Search in sources :

Example 1 with Course

use of org.cpsolver.studentsct.model.Course 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;
}
Also used : FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Element(org.dom4j.Element) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Document(org.dom4j.Document) Student(org.cpsolver.studentsct.model.Student) Section(org.cpsolver.studentsct.model.Section) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course)

Example 2 with Course

use of org.cpsolver.studentsct.model.Course in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadCourse.

/**
     * Load course
     * @param courseEl course element
     * @param offering parent offering
     * @return loaded course
     */
protected Course loadCourse(Element courseEl, Offering offering) {
    Course course = new Course(Long.parseLong(courseEl.attributeValue("id")), courseEl.attributeValue("subjectArea", ""), courseEl.attributeValue("courseNbr", "C" + courseEl.attributeValue("id")), offering, Integer.parseInt(courseEl.attributeValue("limit", "-1")), Integer.parseInt(courseEl.attributeValue("projected", "0")));
    course.setCredit(courseEl.attributeValue("credit"));
    return course;
}
Also used : Course(org.cpsolver.studentsct.model.Course)

Example 3 with Course

use of org.cpsolver.studentsct.model.Course in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadReservation.

/**
     * Load reservation
     * @param reservationEl reservation element
     * @param offering parent offering
     * @param configTable config table (of the offering)
     * @param sectionTable section table (of the offering)
     * @return loaded reservation
     */
protected Reservation loadReservation(Element reservationEl, Offering offering, HashMap<Long, Config> configTable, HashMap<Long, Section> sectionTable) {
    Reservation r = null;
    if ("individual".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new IndividualReservation(Long.valueOf(reservationEl.attributeValue("id")), offering, studentIds);
    } else if ("group".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new GroupReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, studentIds);
    } else if ("curriculum".equals(reservationEl.attributeValue("type"))) {
        List<String> classifications = new ArrayList<String>();
        for (Iterator<?> k = reservationEl.elementIterator("classification"); k.hasNext(); ) {
            Element clasfEl = (Element) k.next();
            classifications.add(clasfEl.attributeValue("code"));
        }
        List<String> majors = new ArrayList<String>();
        for (Iterator<?> k = reservationEl.elementIterator("major"); k.hasNext(); ) {
            Element majorEl = (Element) k.next();
            majors.add(majorEl.attributeValue("code"));
        }
        r = new CurriculumReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, reservationEl.attributeValue("area"), classifications, majors);
    } else if ("course".equals(reservationEl.attributeValue("type"))) {
        long courseId = Long.parseLong(reservationEl.attributeValue("course"));
        for (Course course : offering.getCourses()) {
            if (course.getId() == courseId)
                r = new CourseReservation(Long.valueOf(reservationEl.attributeValue("id")), course);
        }
    } else if ("dummy".equals(reservationEl.attributeValue("type"))) {
        r = new DummyReservation(offering);
    } else if ("override".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new ReservationOverride(Long.valueOf(reservationEl.attributeValue("id")), offering, studentIds);
    }
    if (r == null) {
        sLogger.error("Unknown reservation type " + reservationEl.attributeValue("type"));
        return null;
    }
    r.setExpired("true".equals(reservationEl.attributeValue("expired", "false")));
    for (Iterator<?> k = reservationEl.elementIterator("config"); k.hasNext(); ) {
        Element configEl = (Element) k.next();
        r.addConfig(configTable.get(Long.parseLong(configEl.attributeValue("id"))));
    }
    for (Iterator<?> k = reservationEl.elementIterator("section"); k.hasNext(); ) {
        Element sectionEl = (Element) k.next();
        r.addSection(sectionTable.get(Long.parseLong(sectionEl.attributeValue("id"))));
    }
    r.setPriority(Integer.parseInt(reservationEl.attributeValue("priority", String.valueOf(r.getPriority()))));
    r.setMustBeUsed("true".equals(reservationEl.attributeValue("mustBeUsed", r.mustBeUsed() ? "true" : "false")));
    r.setAllowOverlap("true".equals(reservationEl.attributeValue("allowOverlap", r.isAllowOverlap() ? "true" : "false")));
    r.setCanAssignOverLimit("true".equals(reservationEl.attributeValue("canAssignOverLimit", r.canAssignOverLimit() ? "true" : "false")));
    return r;
}
Also used : GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) HashSet(java.util.HashSet) Set(java.util.Set) BitSet(java.util.BitSet) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) Reservation(org.cpsolver.studentsct.reservation.Reservation) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) ReservationOverride(org.cpsolver.studentsct.reservation.ReservationOverride) Iterator(java.util.Iterator) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet)

Example 4 with Course

use of org.cpsolver.studentsct.model.Course in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method load.

public void load(Document document) {
    Element root = document.getRootElement();
    if (getModel().getDistanceConflict() != null && root.element("travel-times") != null)
        loadTravelTimes(root.element("travel-times"), getModel().getDistanceConflict().getDistanceMetric());
    Progress.getInstance(getModel()).load(root, true);
    Progress.getInstance(getModel()).message(Progress.MSGLEVEL_STAGE, "Restoring from backup ...");
    Map<Long, Offering> offeringTable = new HashMap<Long, Offering>();
    Map<Long, Course> courseTable = new HashMap<Long, Course>();
    if (root.element("offerings") != null) {
        loadOfferings(root.element("offerings"), offeringTable, courseTable, null);
    }
    if (root.element("students") != null) {
        loadStudents(root.element("students"), offeringTable, courseTable);
    }
    if (root.element("constraints") != null)
        loadLinkedSections(root.element("constraints"), offeringTable);
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) Course(org.cpsolver.studentsct.model.Course) Offering(org.cpsolver.studentsct.model.Offering)

Example 5 with Course

use of org.cpsolver.studentsct.model.Course in project cpsolver by UniTime.

the class StudentSectioningXMLSaver method saveCourseRequest.

/**
     * Save course request 
     * @param requestEl request element to be populated
     * @param request course request to be saved
     */
protected void saveCourseRequest(Element requestEl, CourseRequest request) {
    requestEl.addAttribute("id", getId("request", request.getId()));
    requestEl.addAttribute("priority", String.valueOf(request.getPriority()));
    if (request.isAlternative())
        requestEl.addAttribute("alternative", "true");
    if (request.getWeight() != 1.0)
        requestEl.addAttribute("weight", sStudentWeightFormat.format(request.getWeight()));
    requestEl.addAttribute("waitlist", request.isWaitlist() ? "true" : "false");
    if (request.getTimeStamp() != null)
        requestEl.addAttribute("timeStamp", request.getTimeStamp().toString());
    boolean first = true;
    for (Course course : request.getCourses()) {
        if (first)
            requestEl.addAttribute("course", getId("course", course.getId()));
        else
            requestEl.addElement("alternative").addAttribute("course", getId("course", course.getId()));
        first = false;
    }
    for (Choice choice : request.getWaitlistedChoices()) {
        Element choiceEl = requestEl.addElement("waitlisted");
        choiceEl.addAttribute("offering", getId("offering", choice.getOffering().getId()));
        choiceEl.setText(choice.getId());
    }
    for (Choice choice : request.getSelectedChoices()) {
        Element choiceEl = requestEl.addElement("selected");
        choiceEl.addAttribute("offering", getId("offering", choice.getOffering().getId()));
        choiceEl.setText(choice.getId());
    }
    if (iSaveInitial && request.getInitialAssignment() != null) {
        saveEnrollment(requestEl.addElement("initial"), request.getInitialAssignment());
    }
    if (iSaveCurrent && getAssignment().getValue(request) != null) {
        saveEnrollment(requestEl.addElement("current"), getAssignment().getValue(request));
    }
    if (iSaveBest && request.getBestAssignment() != null) {
        saveEnrollment(requestEl.addElement("best"), request.getBestAssignment());
    }
    for (RequestGroup g : request.getRequestGroups()) {
        Element groupEl = requestEl.addElement("group").addAttribute("id", getId("group", g.getId())).addAttribute("course", getId("course", g.getCourse().getId()));
        if (iShowNames)
            groupEl.addAttribute("name", g.getName());
    }
}
Also used : Choice(org.cpsolver.studentsct.model.Choice) RequestGroup(org.cpsolver.studentsct.model.RequestGroup) Element(org.dom4j.Element) Course(org.cpsolver.studentsct.model.Course)

Aggregations

Course (org.cpsolver.studentsct.model.Course)37 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)22 Request (org.cpsolver.studentsct.model.Request)20 Section (org.cpsolver.studentsct.model.Section)19 HashSet (java.util.HashSet)16 Offering (org.cpsolver.studentsct.model.Offering)15 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 Enrollment (org.cpsolver.studentsct.model.Enrollment)14 Config (org.cpsolver.studentsct.model.Config)13 Subpart (org.cpsolver.studentsct.model.Subpart)12 Element (org.dom4j.Element)10 Map (java.util.Map)9 Student (org.cpsolver.studentsct.model.Student)9 TreeSet (java.util.TreeSet)7 CSVFile (org.cpsolver.ifs.util.CSVFile)7 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)7 Set (java.util.Set)6 Comparator (java.util.Comparator)5 DataProperties (org.cpsolver.ifs.util.DataProperties)5