Skip to content

Commit

Permalink
Student Scheduling: Universal Override
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tomas-muller committed Jan 23, 2024
1 parent 8a27733 commit 94d6ae0
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 29 deletions.
26 changes: 25 additions & 1 deletion src/org/cpsolver/studentsct/model/AreaClassificationMajor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* License along with this library; if not see
* <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
*/
public class AreaClassificationMajor {
public class AreaClassificationMajor implements Comparable<AreaClassificationMajor>{
private String iArea, iClassification, iMajor, iConcentration;
private String iAreaName, iClassificationName, iMajorName, iConcentrationName;
private Double iWeight;
Expand Down Expand Up @@ -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());
}
}
11 changes: 10 additions & 1 deletion src/org/cpsolver/studentsct/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.cpsolver.studentsct.model.Request.RequestPriority;



/**
* Representation of a student. Each student contains id, and a list of
* requests. <br>
Expand Down Expand Up @@ -299,6 +298,16 @@ public List<AreaClassificationMajor> 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
Expand Down
93 changes: 66 additions & 27 deletions src/org/cpsolver/studentsct/reservation/UniversalOverride.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

0 comments on commit 94d6ae0

Please sign in to comment.