use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class StudentRequestXml method exportModel.
public static Document exportModel(Assignment<Request, Enrollment> assignment, StudentSectioningModel model) {
Document document = DocumentHelper.createDocument();
Element requestElement = document.addElement("request");
requestElement.addAttribute("campus", model.getProperties().getProperty("Data.Initiative"));
requestElement.addAttribute("year", model.getProperties().getProperty("Data.Year"));
requestElement.addAttribute("term", model.getProperties().getProperty("Data.Term"));
for (Student student : model.getStudents()) {
Element studentElement = requestElement.addElement("student");
studentElement.addAttribute("key", String.valueOf(student.getId()));
Element courseRequestsElement = studentElement.addElement("updateCourseRequests");
courseRequestsElement.addAttribute("commit", "true");
Collections.sort(student.getRequests(), new Comparator<Request>() {
@Override
public int compare(Request r1, Request r2) {
if (r1.isAlternative() != r2.isAlternative()) {
return (r1.isAlternative() ? 1 : -1);
}
return Double.compare(r1.getPriority(), r2.getPriority());
}
});
boolean hasSchedule = false;
for (Request request : student.getRequests()) {
if (assignment.getValue(request) != null)
hasSchedule = true;
if (request instanceof FreeTimeRequest) {
FreeTimeRequest ftReq = (FreeTimeRequest) request;
Element ftReqElement = courseRequestsElement.addElement("freeTime");
requestElement.addAttribute("days", ftReq.getTime().getDayHeader());
int startSlot = ftReq.getTime().getStartSlot();
int startTime = startSlot * Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN;
ftReqElement.addAttribute("startTime", s2zDF.format(startTime / 60) + s2zDF.format(startTime % 60));
int endTime = startTime + ftReq.getTime().getLength() * Constants.SLOT_LENGTH_MIN - ftReq.getTime().getBreakTime();
ftReqElement.addAttribute("endTime", s2zDF.format(endTime / 60) + s2zDF.format(endTime % 60));
ftReqElement.addAttribute("length", String.valueOf(ftReq.getTime().getLength() * Constants.SLOT_LENGTH_MIN));
} else {
CourseRequest crReq = (CourseRequest) request;
Element crReqElement = courseRequestsElement.addElement("courseOffering");
Course course = crReq.getCourses().get(0);
crReqElement.addAttribute("subjectArea", course.getSubjectArea());
crReqElement.addAttribute("courseNumber", course.getCourseNumber());
crReqElement.addAttribute("waitlist", crReq.isWaitlist() ? "true" : "false");
crReqElement.addAttribute("alternative", crReq.isAlternative() ? "true" : "false");
for (int i = 1; i < crReq.getCourses().size(); i++) {
Course altCourse = crReq.getCourses().get(i);
Element altCourseElement = crReqElement.addElement("alternative");
altCourseElement.addAttribute("subjectArea", altCourse.getSubjectArea());
altCourseElement.addAttribute("courseNumber", altCourse.getCourseNumber());
}
}
}
if (hasSchedule) {
Element requestScheduleElement = studentElement.addElement("requestSchedule");
requestScheduleElement.addAttribute("type", "commit");
for (Request request : student.getRequests()) {
if (request instanceof CourseRequest) {
CourseRequest crReq = (CourseRequest) request;
Enrollment enrollment = assignment.getValue(crReq);
if (enrollment == null)
continue;
Element crReqElement = requestScheduleElement.addElement("courseOffering");
Course course = enrollment.getCourse();
crReqElement.addAttribute("subjectArea", course.getSubjectArea());
crReqElement.addAttribute("courseNumber", course.getCourseNumber());
for (Section section : enrollment.getSections()) {
Element classEl = crReqElement.addElement("class");
classEl.addAttribute("id", section.getSubpart().getInstructionalType());
classEl.addAttribute("assignmentId", String.valueOf(section.getId()));
}
}
}
}
}
return document;
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadSubpart.
/**
* Load subpart
* @param subpartEl supart element
* @param config parent config
* @param subpartTable subpart table (of the offering)
* @param sectionTable section table (of the offering)
* @param timetable provided timetable
* @return loaded subpart
*/
protected Subpart loadSubpart(Element subpartEl, Config config, Map<Long, Subpart> subpartTable, Map<Long, Section> sectionTable, Map<Long, Placement> timetable) {
Subpart parentSubpart = null;
if (subpartEl.attributeValue("parent") != null)
parentSubpart = subpartTable.get(Long.valueOf(subpartEl.attributeValue("parent")));
Subpart subpart = new Subpart(Long.parseLong(subpartEl.attributeValue("id")), subpartEl.attributeValue("itype"), subpartEl.attributeValue("name", "P" + subpartEl.attributeValue("id")), config, parentSubpart);
subpart.setAllowOverlap("true".equals(subpartEl.attributeValue("allowOverlap", "false")));
subpart.setCredit(subpartEl.attributeValue("credit"));
for (Iterator<?> l = subpartEl.elementIterator("section"); l.hasNext(); ) {
Element sectionEl = (Element) l.next();
Section section = loadSection(sectionEl, subpart, sectionTable, timetable);
sectionTable.put(new Long(section.getId()), section);
}
return subpart;
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class StudentSectioningXMLSaver method saveReservation.
/**
* Save reservation
* @param reservationEl reservation element to be populated
* @param reservation reservation to be saved
*/
protected void saveReservation(Element reservationEl, Reservation reservation) {
reservationEl.addAttribute("id", getId("reservation", reservation.getId()));
reservationEl.addAttribute("expired", reservation.isExpired() ? "true" : "false");
if (reservation instanceof GroupReservation) {
GroupReservation gr = (GroupReservation) reservation;
reservationEl.addAttribute("type", "group");
for (Long studentId : gr.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
if (gr.getReservationLimit() >= 0.0)
reservationEl.addAttribute("limit", String.valueOf(gr.getReservationLimit()));
} else if (reservation instanceof ReservationOverride) {
reservationEl.addAttribute("type", "override");
ReservationOverride o = (ReservationOverride) reservation;
for (Long studentId : o.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
} else if (reservation instanceof IndividualReservation) {
reservationEl.addAttribute("type", "individual");
for (Long studentId : ((IndividualReservation) reservation).getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
} else if (reservation instanceof CurriculumReservation) {
reservationEl.addAttribute("type", "curriculum");
CurriculumReservation cr = (CurriculumReservation) reservation;
if (cr.getReservationLimit() >= 0.0)
reservationEl.addAttribute("limit", String.valueOf(cr.getReservationLimit()));
reservationEl.addAttribute("area", cr.getAcademicArea());
for (String clasf : cr.getClassifications()) reservationEl.addElement("classification").addAttribute("code", clasf);
for (String major : cr.getMajors()) reservationEl.addElement("major").addAttribute("code", major);
} else if (reservation instanceof CourseReservation) {
reservationEl.addAttribute("type", "course");
CourseReservation cr = (CourseReservation) reservation;
reservationEl.addAttribute("course", getId("course", cr.getCourse().getId()));
} else if (reservation instanceof DummyReservation) {
reservationEl.addAttribute("type", "dummy");
}
reservationEl.addAttribute("priority", String.valueOf(reservation.getPriority()));
reservationEl.addAttribute("mustBeUsed", reservation.mustBeUsed() ? "true" : "false");
reservationEl.addAttribute("allowOverlap", reservation.isAllowOverlap() ? "true" : "false");
reservationEl.addAttribute("canAssignOverLimit", reservation.canAssignOverLimit() ? "true" : "false");
for (Config config : reservation.getConfigs()) reservationEl.addElement("config").addAttribute("id", getId("config", config.getId()));
for (Map.Entry<Subpart, Set<Section>> entry : reservation.getSections().entrySet()) {
for (Section section : entry.getValue()) {
reservationEl.addElement("section").addAttribute("id", getId("section", section.getId()));
}
}
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class StudentSectioningXMLSaver method saveLinkedSections.
/**
* Save linked sections
* @param root document root
*/
protected void saveLinkedSections(Element root) {
Element constrainstEl = root.addElement("constraints");
for (LinkedSections linkedSections : getModel().getLinkedSections()) {
Element linkEl = constrainstEl.addElement("linked-sections");
linkEl.addAttribute("mustBeUsed", linkedSections.isMustBeUsed() ? "true" : "false");
for (Offering offering : linkedSections.getOfferings()) for (Subpart subpart : linkedSections.getSubparts(offering)) for (Section section : linkedSections.getSections(subpart)) linkEl.addElement("section").addAttribute("offering", getId("offering", offering.getId())).addAttribute("id", getId("section", section.getId()));
}
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class StudentSectioningModel method clearOnlineSectioningInfos.
/**
* Empty online student sectioning infos for all sections (see
* {@link Section#getSpaceExpected()} and {@link Section#getSpaceHeld()}).
*/
public void clearOnlineSectioningInfos() {
for (Offering offering : iOfferings) {
for (Config config : offering.getConfigs()) {
for (Subpart subpart : config.getSubparts()) {
for (Section section : subpart.getSections()) {
section.setSpaceExpected(0);
section.setSpaceHeld(0);
}
}
}
}
}
Aggregations