From 94d6ae0763bd88fb04b6d5d52070914a12d1d08c Mon Sep 17 00:00:00 2001 From: tomas-muller Date: Tue, 23 Jan 2024 16:56:34 +0100 Subject: [PATCH] Student Scheduling: Universal Override - added the ability to match on concentration, degree, or program - added the ability to match on primary area, classification, major, concentration, degree, program, or campus --- .../model/AreaClassificationMajor.java | 26 +++++- .../cpsolver/studentsct/model/Student.java | 11 ++- .../reservation/UniversalOverride.java | 93 +++++++++++++------ 3 files changed, 101 insertions(+), 29 deletions(-) diff --git a/src/org/cpsolver/studentsct/model/AreaClassificationMajor.java b/src/org/cpsolver/studentsct/model/AreaClassificationMajor.java index 4eef6a9f..088bfc0e 100644 --- a/src/org/cpsolver/studentsct/model/AreaClassificationMajor.java +++ b/src/org/cpsolver/studentsct/model/AreaClassificationMajor.java @@ -26,7 +26,7 @@ * License along with this library; if not see * http://www.gnu.org/licenses/. */ -public class AreaClassificationMajor { +public class AreaClassificationMajor implements Comparable{ private String iArea, iClassification, iMajor, iConcentration; private String iAreaName, iClassificationName, iMajorName, iConcentrationName; private Double iWeight; @@ -383,4 +383,28 @@ public boolean equals(Object o) { public String toString() { return getArea() + "/" + getMajor() + (getConcentration() == null || getConcentration().isEmpty()? "" : "-" + getConcentration()) + " " + getClassification(); } + + private String getDegreeNotNull() { return (iDegree == null ? "" : iDegree); } + private String getProgramNotNull() { return (iProgram == null ? "" : iProgram); } + private String getCampusNotNull() { return (iCampus == null ? "" : iCampus); } + private String getConcentrationNotNull() { return (iConcentration == null ? "" : iConcentration); } + + @Override + public int compareTo(AreaClassificationMajor acm) { + if (getWeight() != acm.getWeight()) + return getWeight() > acm.getWeight() ? -1 : 1; + if (!getArea().equals(acm.getArea())) + return getArea().compareTo(acm.getArea()); + if (!getClassification().equals(acm.getClassification())) + return getClassification().compareTo(acm.getClassification()); + if (!getDegreeNotNull().equals(acm.getDegreeNotNull())) + return getDegreeNotNull().compareTo(acm.getDegreeNotNull()); + if (!getProgramNotNull().equals(acm.getProgramNotNull())) + return getProgramNotNull().compareTo(acm.getProgramNotNull()); + if (!getMajor().equals(acm.getMajor())) + return getMajor().compareTo(acm.getMajor()); + if (!getCampusNotNull().equals(acm.getCampusNotNull())) + return getCampusNotNull().compareTo(acm.getCampusNotNull()); + return getConcentrationNotNull().compareTo(acm.getConcentrationNotNull()); + } } diff --git a/src/org/cpsolver/studentsct/model/Student.java b/src/org/cpsolver/studentsct/model/Student.java index 69616f72..1330a558 100644 --- a/src/org/cpsolver/studentsct/model/Student.java +++ b/src/org/cpsolver/studentsct/model/Student.java @@ -11,7 +11,6 @@ import org.cpsolver.studentsct.model.Request.RequestPriority; - /** * Representation of a student. Each student contains id, and a list of * requests.
@@ -299,6 +298,16 @@ public List getAreaClassificationMajors() { return iMajors; } + public AreaClassificationMajor getPrimaryMajor() { + if (iMajors == null) return null; + AreaClassificationMajor major = null; + for (AreaClassificationMajor m: iMajors) { + if (major == null || m.compareTo(major) < 0) + major = m; + } + return major; + } + /** * List of academic area, classification, and minor codes ({@link AreaClassificationMajor}) for the given student * @return list of academic area, classification, and minor codes diff --git a/src/org/cpsolver/studentsct/reservation/UniversalOverride.java b/src/org/cpsolver/studentsct/reservation/UniversalOverride.java index 33528847..0f43fd93 100644 --- a/src/org/cpsolver/studentsct/reservation/UniversalOverride.java +++ b/src/org/cpsolver/studentsct/reservation/UniversalOverride.java @@ -134,50 +134,89 @@ public boolean match(String attr, String term) { if (attr == null && term.isEmpty()) return true; if ("limit".equals(attr)) return true; if ("area".equals(attr)) { - for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) - if (eq(acm.getArea(), term)) return true; + for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) + if (eq(acm.getArea(), term)) return true; } else if ("clasf".equals(attr) || "classification".equals(attr)) { - for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) - if (eq(acm.getClassification(), term)) return true; + for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) + if (eq(acm.getClassification(), term)) return true; } else if ("campus".equals(attr)) { for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) - if (eq(acm.getCampus(), term)) return true; + if (eq(acm.getCampus(), term)) return true; } else if ("major".equals(attr)) { - for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) - if (eq(acm.getMajor(), term)) return true; + for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) + if (eq(acm.getMajor(), term)) return true; } else if ("group".equals(attr)) { - for (StudentGroup aac: student().getGroups()) - if (eq(aac.getReference(), term)) return true; + for (StudentGroup aac: student().getGroups()) + if (eq(aac.getReference(), term)) return true; } else if ("accommodation".equals(attr)) { - for (String aac: student().getAccommodations()) - if (eq(aac, term)) return true; + for (String aac: student().getAccommodations()) + if (eq(aac, term)) return true; } else if ("student".equals(attr)) { - return has(student().getName(), term) || eq(student().getExternalId(), term) || eq(student().getName(), term); + return has(student().getName(), term) || eq(student().getExternalId(), term) || eq(student().getName(), term); } else if ("advisor".equals(attr)) { - for (Instructor a: student().getAdvisors()) - if (eq(a.getExternalId(), term)) return true; - return false; + for (Instructor a: student().getAdvisors()) + if (eq(a.getExternalId(), term)) return true; + return false; } else if ("status".equals(attr)) { - if ("default".equalsIgnoreCase(term) || "Not Set".equalsIgnoreCase(term)) return student().getStatus() == null; - return term.equalsIgnoreCase(student().getStatus()); - } else if (attr != null) { - for (StudentGroup aac: student().getGroups()) - if (eq(aac.getType(), attr.replace('_', ' ')) && eq(aac.getReference(), term)) return true; + if ("default".equalsIgnoreCase(term) || "Not Set".equalsIgnoreCase(term)) return student().getStatus() == null; + return term.equalsIgnoreCase(student().getStatus()); + } else if ("concentration".equals(attr)) { + for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) + if (eq(acm.getConcentration(), term)) return true; + } else if ("degree".equals(attr)) { + for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) + if (eq(acm.getDegree(), term)) return true; + } else if ("program".equals(attr)) { + for (AreaClassificationMajor acm: student().getAreaClassificationMajors()) + if (eq(acm.getProgram(), term)) return true; + } else if ("primary-area".equals(attr)) { + AreaClassificationMajor acm = student().getPrimaryMajor(); + if (acm != null && eq(acm.getArea(), term)) return true; + } else if ("primary-clasf".equals(attr) || "primary-classification".equals(attr)) { + AreaClassificationMajor acm = student().getPrimaryMajor(); + if (acm != null && eq(acm.getClassification(), term)) return true; + } else if ("primary-major".equals(attr)) { + AreaClassificationMajor acm = student().getPrimaryMajor(); + if (acm != null && eq(acm.getMajor(), term)) return true; + } else if ("primary-concentration".equals(attr)) { + AreaClassificationMajor acm = student().getPrimaryMajor(); + if (acm != null && eq(acm.getConcentration(), term)) return true; + } else if ("primary-degree".equals(attr)) { + AreaClassificationMajor acm = student().getPrimaryMajor(); + if (acm != null && eq(acm.getDegree(), term)) return true; + } else if ("primary-program".equals(attr)) { + AreaClassificationMajor acm = student().getPrimaryMajor(); + if (acm != null && like(acm.getProgram(), term)) return true; + } else if ("primary-campus".equals(attr)) { + AreaClassificationMajor acm = student().getPrimaryMajor(); + if (acm != null && like(acm.getCampus(), term)) return true; + } else { + for (StudentGroup aac: student().getGroups()) + if (eq(aac.getType(), attr.replace('_', ' ')) && eq(aac.getReference(), term)) return true; } return false; } private boolean eq(String name, String term) { - if (name == null) return false; - return name.equalsIgnoreCase(term); + if (name == null) return false; + return name.equalsIgnoreCase(term); } private boolean has(String name, String term) { - if (name == null) return false; - if (eq(name, term)) return true; - for (String t: name.split(" |,")) - if (t.equalsIgnoreCase(term)) return true; - return false; + if (name == null) return false; + if (eq(name, term)) return true; + for (String t: name.split(" |,")) + if (t.equalsIgnoreCase(term)) return true; + return false; + } + + private boolean like(String name, String term) { + if (name == null) return false; + if (term.indexOf('%') >= 0) { + return name.matches("(?i)" + term.replaceAll("%", ".*")); + } else { + return name.equalsIgnoreCase(term); + } } } }