use of org.cpsolver.studentsct.model.AcademicAreaCode in project cpsolver by UniTime.
the class StudentSectioningXMLSaver method saveStudent.
/**
* Save student
* @param studentEl student element to be populated
* @param student student to be saved
*/
protected void saveStudent(Element studentEl, Student student) {
studentEl.addAttribute("id", getId("student", student.getId()));
if (iShowNames) {
if (student.getExternalId() != null && !student.getExternalId().isEmpty())
studentEl.addAttribute("externalId", student.getExternalId());
if (student.getName() != null && !student.getName().isEmpty())
studentEl.addAttribute("name", student.getName());
if (student.getStatus() != null && !student.getStatus().isEmpty())
studentEl.addAttribute("status", student.getStatus());
}
if (student.isDummy())
studentEl.addAttribute("dummy", "true");
if (iSaveStudentInfo) {
for (AcademicAreaCode aac : student.getAcademicAreaClasiffications()) {
Element aacEl = studentEl.addElement("classification");
if (aac.getArea() != null)
aacEl.addAttribute("area", aac.getArea());
if (aac.getCode() != null)
aacEl.addAttribute("code", aac.getCode());
}
for (AcademicAreaCode aac : student.getMajors()) {
Element aacEl = studentEl.addElement("major");
if (aac.getArea() != null)
aacEl.addAttribute("area", aac.getArea());
if (aac.getCode() != null)
aacEl.addAttribute("code", aac.getCode());
}
for (AcademicAreaCode aac : student.getMinors()) {
Element aacEl = studentEl.addElement("minor");
if (aac.getArea() != null)
aacEl.addAttribute("area", aac.getArea());
if (aac.getCode() != null)
aacEl.addAttribute("code", aac.getCode());
}
for (AreaClassificationMajor acm : student.getAreaClassificationMajors()) {
Element acmEl = studentEl.addElement("acm");
if (acm.getArea() != null)
acmEl.addAttribute("area", acm.getArea());
if (acm.getArea() != null)
acmEl.addAttribute("classification", acm.getClassification());
if (acm.getArea() != null)
acmEl.addAttribute("major", acm.getMajor());
}
}
for (Unavailability unavailability : student.getUnavailabilities()) {
Element unavEl = studentEl.addElement("unavailability");
unavEl.addAttribute("offering", getId("offering", unavailability.getSection().getSubpart().getConfig().getOffering().getId()));
unavEl.addAttribute("section", getId("section", unavailability.getSection().getId()));
if (unavailability.isAllowOverlap())
unavEl.addAttribute("allowOverlap", "true");
}
}
use of org.cpsolver.studentsct.model.AcademicAreaCode in project cpsolver by UniTime.
the class Test method loadStudentInfoXml.
/** Load student infos from a given XML file.
* @param model problem model
* @param xml an XML file
**/
public static void loadStudentInfoXml(StudentSectioningModel model, File xml) {
try {
sLog.info("Loading student infos from " + xml);
Document document = (new SAXReader()).read(xml);
Element root = document.getRootElement();
HashMap<Long, Student> studentTable = new HashMap<Long, Student>();
for (Student student : model.getStudents()) {
studentTable.put(new Long(student.getId()), student);
}
for (Iterator<?> i = root.elementIterator("student"); i.hasNext(); ) {
Element studentEl = (Element) i.next();
Student student = studentTable.get(Long.valueOf(studentEl.attributeValue("externalId")));
if (student == null) {
sLog.debug(" -- student " + studentEl.attributeValue("externalId") + " not found");
continue;
}
sLog.debug(" -- loading info for student " + student);
student.getAcademicAreaClasiffications().clear();
if (studentEl.element("studentAcadAreaClass") != null)
for (Iterator<?> j = studentEl.element("studentAcadAreaClass").elementIterator("acadAreaClass"); j.hasNext(); ) {
Element studentAcadAreaClassElement = (Element) j.next();
student.getAcademicAreaClasiffications().add(new AcademicAreaCode(studentAcadAreaClassElement.attributeValue("academicArea"), studentAcadAreaClassElement.attributeValue("academicClass")));
}
sLog.debug(" -- acad areas classifs " + student.getAcademicAreaClasiffications());
student.getMajors().clear();
if (studentEl.element("studentMajors") != null)
for (Iterator<?> j = studentEl.element("studentMajors").elementIterator("major"); j.hasNext(); ) {
Element studentMajorElement = (Element) j.next();
student.getMajors().add(new AcademicAreaCode(studentMajorElement.attributeValue("academicArea"), studentMajorElement.attributeValue("code")));
}
sLog.debug(" -- majors " + student.getMajors());
student.getMinors().clear();
if (studentEl.element("studentMinors") != null)
for (Iterator<?> j = studentEl.element("studentMinors").elementIterator("minor"); j.hasNext(); ) {
Element studentMinorElement = (Element) j.next();
student.getMinors().add(new AcademicAreaCode(studentMinorElement.attributeValue("academicArea", ""), studentMinorElement.attributeValue("code", "")));
}
sLog.debug(" -- minors " + student.getMinors());
}
} catch (Exception e) {
sLog.error(e.getMessage(), e);
}
}
use of org.cpsolver.studentsct.model.AcademicAreaCode in project cpsolver by UniTime.
the class Test method loadCrsReqFiles.
/**
* Load course request from the given files (in the format being used by the
* old MSF system)
*
* @param model
* student sectioning model (with offerings loaded)
* @param files
* semi-colon separated list of files to be loaded
*/
public static void loadCrsReqFiles(StudentSectioningModel model, String files) {
try {
boolean lastLike = model.getProperties().getPropertyBoolean("Test.CrsReqIsLastLike", true);
boolean shuffleIds = model.getProperties().getPropertyBoolean("Test.CrsReqShuffleStudentIds", true);
boolean tryWithoutSuffix = model.getProperties().getPropertyBoolean("Test.CrsReqTryWithoutSuffix", false);
HashMap<Long, Student> students = new HashMap<Long, Student>();
long reqId = 0;
for (StringTokenizer stk = new StringTokenizer(files, ";"); stk.hasMoreTokens(); ) {
String file = stk.nextToken();
sLog.debug("Loading " + file + " ...");
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
int lineIndex = 0;
while ((line = in.readLine()) != null) {
lineIndex++;
if (line.length() <= 150)
continue;
char code = line.charAt(13);
if (code == 'H' || code == 'T')
// skip header and tail
continue;
long studentId = Long.parseLong(line.substring(14, 23));
Student student = students.get(new Long(studentId));
if (student == null) {
student = new Student(studentId);
if (lastLike)
student.setDummy(true);
students.put(new Long(studentId), student);
sLog.debug(" -- loading student " + studentId + " ...");
} else
sLog.debug(" -- updating student " + studentId + " ...");
line = line.substring(150);
while (line.length() >= 20) {
String subjectArea = line.substring(0, 4).trim();
String courseNbr = line.substring(4, 8).trim();
if (subjectArea.length() == 0 || courseNbr.length() == 0) {
line = line.substring(20);
continue;
}
/*
* // UNUSED String instrSel = line.substring(8,10);
* //ZZ - Remove previous instructor selection char
* reqPDiv = line.charAt(10); //P - Personal preference;
* C - Conflict resolution; //0 - (Zero) used by program
* only, for change requests to reschedule division //
* (used to reschedule canceled division) String reqDiv
* = line.substring(11,13); //00 - Reschedule division
* String reqSect = line.substring(13,15); //Contains
* designator for designator-required courses String
* credit = line.substring(15,19); char nameRaise =
* line.charAt(19); //N - Name raise
*/
// A - Add; D - Drop; C -
char action = line.charAt(19);
// Change
sLog.debug(" -- requesting " + subjectArea + " " + courseNbr + " (action:" + action + ") ...");
Course course = null;
offerings: for (Offering offering : model.getOfferings()) {
for (Course c : offering.getCourses()) {
if (c.getSubjectArea().equals(subjectArea) && c.getCourseNumber().equals(courseNbr)) {
course = c;
break offerings;
}
}
}
if (course == null && tryWithoutSuffix && courseNbr.charAt(courseNbr.length() - 1) >= 'A' && courseNbr.charAt(courseNbr.length() - 1) <= 'Z') {
String courseNbrNoSfx = courseNbr.substring(0, courseNbr.length() - 1);
offerings: for (Offering offering : model.getOfferings()) {
for (Course c : offering.getCourses()) {
if (c.getSubjectArea().equals(subjectArea) && c.getCourseNumber().equals(courseNbrNoSfx)) {
course = c;
break offerings;
}
}
}
}
if (course == null) {
if (courseNbr.charAt(courseNbr.length() - 1) >= 'A' && courseNbr.charAt(courseNbr.length() - 1) <= 'Z') {
} else {
sLog.warn(" -- course " + subjectArea + " " + courseNbr + " not found (file " + file + ", line " + lineIndex + ")");
}
} else {
CourseRequest courseRequest = null;
for (Request request : student.getRequests()) {
if (request instanceof CourseRequest && ((CourseRequest) request).getCourses().contains(course)) {
courseRequest = (CourseRequest) request;
break;
}
}
if (action == 'A') {
if (courseRequest == null) {
List<Course> courses = new ArrayList<Course>(1);
courses.add(course);
courseRequest = new CourseRequest(reqId++, student.getRequests().size(), false, student, courses, false, null);
} else {
sLog.warn(" -- request for course " + course + " is already present");
}
} else if (action == 'D') {
if (courseRequest == null) {
sLog.warn(" -- request for course " + course + " is not present -- cannot be dropped");
} else {
student.getRequests().remove(courseRequest);
}
} else if (action == 'C') {
if (courseRequest == null) {
sLog.warn(" -- request for course " + course + " is not present -- cannot be changed");
} else {
// ?
}
} else {
sLog.warn(" -- unknown action " + action);
}
}
line = line.substring(20);
}
}
in.close();
}
HashMap<Course, List<Request>> requests = new HashMap<Course, List<Request>>();
Set<Long> studentIds = new HashSet<Long>();
for (Student student : students.values()) {
if (!student.getRequests().isEmpty())
model.addStudent(student);
if (shuffleIds) {
long newId = -1;
while (true) {
newId = 1 + (long) (999999999L * Math.random());
if (studentIds.add(new Long(newId)))
break;
}
student.setId(newId);
}
if (student.isDummy()) {
for (Request request : student.getRequests()) {
if (request instanceof CourseRequest) {
Course course = ((CourseRequest) request).getCourses().get(0);
List<Request> requestsThisCourse = requests.get(course);
if (requestsThisCourse == null) {
requestsThisCourse = new ArrayList<Request>();
requests.put(course, requestsThisCourse);
}
requestsThisCourse.add(request);
}
}
}
}
Collections.sort(model.getStudents(), new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
return Double.compare(o1.getId(), o2.getId());
}
});
for (Map.Entry<Course, List<Request>> entry : requests.entrySet()) {
Course course = entry.getKey();
List<Request> requestsThisCourse = entry.getValue();
double weight = getLastLikeStudentWeight(course, 0, requestsThisCourse.size());
for (Request request : requestsThisCourse) {
request.setWeight(weight);
}
}
if (model.getProperties().getProperty("Test.EtrChk") != null) {
for (StringTokenizer stk = new StringTokenizer(model.getProperties().getProperty("Test.EtrChk"), ";"); stk.hasMoreTokens(); ) {
String file = stk.nextToken();
sLog.debug("Loading " + file + " ...");
BufferedReader in = new BufferedReader(new FileReader(file));
try {
String line;
while ((line = in.readLine()) != null) {
if (line.length() < 55)
continue;
char code = line.charAt(12);
if (code == 'H' || code == 'T')
// skip header and tail
continue;
if (code == 'D' || code == 'K')
// skip delete nad cancel
continue;
long studentId = Long.parseLong(line.substring(2, 11));
Student student = students.get(new Long(studentId));
if (student == null) {
sLog.info(" -- student " + studentId + " not found");
continue;
}
sLog.info(" -- reading student " + studentId);
String area = line.substring(15, 18).trim();
if (area.length() == 0)
continue;
String clasf = line.substring(18, 20).trim();
String major = line.substring(21, 24).trim();
String minor = line.substring(24, 27).trim();
student.getAcademicAreaClasiffications().clear();
student.getMajors().clear();
student.getMinors().clear();
student.getAcademicAreaClasiffications().add(new AcademicAreaCode(area, clasf));
if (major.length() > 0)
student.getMajors().add(new AcademicAreaCode(area, major));
if (minor.length() > 0)
student.getMinors().add(new AcademicAreaCode(area, minor));
}
} finally {
in.close();
}
}
}
int without = 0;
for (Student student : students.values()) {
if (student.getAcademicAreaClasiffications().isEmpty())
without++;
}
fixPriorities(model);
sLog.info("Students without academic area: " + without);
} catch (Exception e) {
sLog.error(e.getMessage(), e);
}
}
use of org.cpsolver.studentsct.model.AcademicAreaCode in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadStudent.
/**
* Load student
* @param studentEl student element
* @param offeringTable offering table
* @return loaded student
*/
protected Student loadStudent(Element studentEl, Map<Long, Offering> offeringTable) {
Student student = new Student(Long.parseLong(studentEl.attributeValue("id")), "true".equals(studentEl.attributeValue("dummy")));
student.setExternalId(studentEl.attributeValue("externalId"));
student.setName(studentEl.attributeValue("name"));
student.setStatus(studentEl.attributeValue("status"));
for (Iterator<?> j = studentEl.elementIterator(); j.hasNext(); ) {
Element requestEl = (Element) j.next();
if ("classification".equals(requestEl.getName())) {
student.getAcademicAreaClasiffications().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
} else if ("major".equals(requestEl.getName())) {
student.getMajors().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
} else if ("minor".equals(requestEl.getName())) {
student.getMinors().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
} else if ("unavailability".equals(requestEl.getName())) {
Offering offering = offeringTable.get(Long.parseLong(requestEl.attributeValue("offering")));
Section section = (offering == null ? null : offering.getSection(Long.parseLong(requestEl.attributeValue("section"))));
if (section != null)
new Unavailability(student, section, "true".equals(requestEl.attributeValue("allowOverlap")));
} else if ("acm".equals(requestEl.getName())) {
student.getAreaClassificationMajors().add(new AreaClassificationMajor(requestEl.attributeValue("area"), requestEl.attributeValue("classification"), requestEl.attributeValue("major")));
}
}
return student;
}
Aggregations