Search in sources :

Example 11 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class CriticalCoursesTable method create.

@Override
public CSVFile create(Assignment<Request, Enrollment> assignment, DataProperties properties) {
    RequestPriority rp = RequestPriority.valueOf(properties.getProperty("priority", RequestPriority.Critical.name()));
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("__Student"), new CSVFile.CSVField("Student"), new CSVFile.CSVField("Priority"), new CSVFile.CSVField("Course"), new CSVFile.CSVField("1st Alt"), new CSVFile.CSVField("2nd Alt"), new CSVFile.CSVField("Enrolled"), new CSVFile.CSVField("Choice") });
    for (Student student : getModel().getStudents()) {
        if (student.isDummy())
            continue;
        int priority = 0;
        for (Request r : student.getRequests()) {
            if (r instanceof CourseRequest) {
                CourseRequest cr = (CourseRequest) r;
                priority++;
                if (rp != cr.getRequestPriority() || cr.isAlternative())
                    continue;
                Enrollment e = cr.getAssignment(assignment);
                Course course = cr.getCourses().get(0);
                Course alt1 = (cr.getCourses().size() < 2 ? null : cr.getCourses().get(1));
                Course alt2 = (cr.getCourses().size() < 3 ? null : cr.getCourses().get(2));
                Course enrolled = (e == null ? null : e.getCourse());
                csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(student.getId()), new CSVFile.CSVField(student.getExternalId()), new CSVFile.CSVField(priority), new CSVFile.CSVField(course.getName()), new CSVFile.CSVField(alt1 == null ? "" : alt1.getName()), new CSVFile.CSVField(alt2 == null ? "" : alt2.getName()), new CSVFile.CSVField(enrolled == null ? "" : enrolled.getName()), new CSVFile.CSVField(enrolled == null ? "" : String.valueOf(cr.getCourses().indexOf(enrolled) + 1)) });
            }
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student) Course(org.cpsolver.studentsct.model.Course) RequestPriority(org.cpsolver.studentsct.model.Request.RequestPriority)

Example 12 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class DistanceConflictTable method createTable.

/**
 * Create report
 *
 * @param assignment current assignment
 * @param includeLastLikeStudents
 *            true, if last-like students should be included (i.e.,
 *            {@link Student#isDummy()} is true)
 * @param includeRealStudents
 *            true, if real students should be included (i.e.,
 *            {@link Student#isDummy()} is false)
 * @param useAmPm use 12-hour format
 * @return report as comma separated text file
 */
public CSVFile createTable(Assignment<Request, Enrollment> assignment, boolean includeLastLikeStudents, boolean includeRealStudents, boolean useAmPm) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("Course"), new CSVFile.CSVField("Total\nConflicts"), new CSVFile.CSVField("Class"), new CSVFile.CSVField("Meeting Time"), new CSVFile.CSVField("Room"), new CSVFile.CSVField("Distance\nConflicts"), new CSVFile.CSVField("% of Total\nConflicts"), new CSVFile.CSVField("Conflicting\nClass"), new CSVFile.CSVField("Conflicting\nMeeting Time"), new CSVFile.CSVField("Conflicting\nRoom"), new CSVFile.CSVField("Distance [m]"), new CSVFile.CSVField("Distance [min]"), new CSVFile.CSVField("Joined\nConflicts"), new CSVFile.CSVField("% of Total\nConflicts") });
    Set<Conflict> confs = new HashSet<Conflict>();
    for (Request r1 : getModel().variables()) {
        Enrollment e1 = assignment.getValue(r1);
        if (e1 == null || !(r1 instanceof CourseRequest))
            continue;
        confs.addAll(iDC.conflicts(e1));
        for (Request r2 : r1.getStudent().getRequests()) {
            Enrollment e2 = assignment.getValue(r2);
            if (e2 == null || r1.getId() >= r2.getId() || !(r2 instanceof CourseRequest))
                continue;
            confs.addAll(iDC.conflicts(e1, e2));
        }
    }
    HashMap<Course, Set<Long>> totals = new HashMap<Course, Set<Long>>();
    HashMap<CourseSection, Map<CourseSection, Double>> conflictingPairs = new HashMap<CourseSection, Map<CourseSection, Double>>();
    HashMap<CourseSection, Set<Long>> sectionOverlaps = new HashMap<CourseSection, Set<Long>>();
    for (Conflict conflict : confs) {
        if (conflict.getStudent().isDummy() && !includeLastLikeStudents)
            continue;
        if (!conflict.getStudent().isDummy() && !includeRealStudents)
            continue;
        Section s1 = conflict.getS1(), s2 = conflict.getS2();
        Course c1 = null, c2 = null;
        Request r1 = null, r2 = null;
        for (Request request : conflict.getStudent().getRequests()) {
            Enrollment enrollment = assignment.getValue(request);
            if (enrollment == null || !enrollment.isCourseRequest())
                continue;
            if (c1 == null && enrollment.getAssignments().contains(s1)) {
                c1 = enrollment.getCourse();
                r1 = request;
                Set<Long> total = totals.get(enrollment.getCourse());
                if (total == null) {
                    total = new HashSet<Long>();
                    totals.put(enrollment.getCourse(), total);
                }
                total.add(enrollment.getStudent().getId());
            }
            if (c2 == null && enrollment.getAssignments().contains(s2)) {
                c2 = enrollment.getCourse();
                r2 = request;
                Set<Long> total = totals.get(enrollment.getCourse());
                if (total == null) {
                    total = new HashSet<Long>();
                    totals.put(enrollment.getCourse(), total);
                }
                total.add(enrollment.getStudent().getId());
            }
        }
        if (c1 == null) {
            sLog.error("Unable to find a course for " + s1);
            continue;
        }
        if (c2 == null) {
            sLog.error("Unable to find a course for " + s2);
            continue;
        }
        CourseSection a = new CourseSection(c1, s1);
        CourseSection b = new CourseSection(c2, s2);
        Set<Long> total = sectionOverlaps.get(a);
        if (total == null) {
            total = new HashSet<Long>();
            sectionOverlaps.put(a, total);
        }
        total.add(r1.getStudent().getId());
        Map<CourseSection, Double> pair = conflictingPairs.get(a);
        if (pair == null) {
            pair = new HashMap<CourseSection, Double>();
            conflictingPairs.put(a, pair);
        }
        Double prev = pair.get(b);
        pair.put(b, r2.getWeight() + (prev == null ? 0.0 : prev.doubleValue()));
        total = sectionOverlaps.get(b);
        if (total == null) {
            total = new HashSet<Long>();
            sectionOverlaps.put(b, total);
        }
        total.add(r2.getStudent().getId());
        pair = conflictingPairs.get(b);
        if (pair == null) {
            pair = new HashMap<CourseSection, Double>();
            conflictingPairs.put(b, pair);
        }
        prev = pair.get(a);
        pair.put(a, r1.getWeight() + (prev == null ? 0.0 : prev.doubleValue()));
    }
    Comparator<Course> courseComparator = new Comparator<Course>() {

        @Override
        public int compare(Course a, Course b) {
            int cmp = a.getName().compareTo(b.getName());
            if (cmp != 0)
                return cmp;
            return a.getId() < b.getId() ? -1 : a.getId() == b.getId() ? 0 : 1;
        }
    };
    Comparator<Section> sectionComparator = new Comparator<Section>() {

        @Override
        public int compare(Section a, Section b) {
            int cmp = a.getSubpart().getConfig().getOffering().getName().compareTo(b.getSubpart().getConfig().getOffering().getName());
            if (cmp != 0)
                return cmp;
            cmp = a.getSubpart().getInstructionalType().compareTo(b.getSubpart().getInstructionalType());
            // cmp = a.getName().compareTo(b.getName());
            if (cmp != 0)
                return cmp;
            return a.getId() < b.getId() ? -1 : a.getId() == b.getId() ? 0 : 1;
        }
    };
    TreeSet<Course> courses = new TreeSet<Course>(courseComparator);
    courses.addAll(totals.keySet());
    for (Course course : courses) {
        Set<Long> total = totals.get(course);
        TreeSet<Section> sections = new TreeSet<Section>(sectionComparator);
        for (Map.Entry<CourseSection, Set<Long>> entry : sectionOverlaps.entrySet()) if (course.equals(entry.getKey().getCourse()))
            sections.add(entry.getKey().getSection());
        boolean firstCourse = true;
        for (Section section : sections) {
            Set<Long> sectionOverlap = sectionOverlaps.get(new CourseSection(course, section));
            Map<CourseSection, Double> pair = conflictingPairs.get(new CourseSection(course, section));
            boolean firstClass = true;
            String rooms = "";
            if (section.getRooms() != null)
                for (RoomLocation r : section.getRooms()) {
                    if (!rooms.isEmpty())
                        rooms += "\n";
                    rooms += r.getName();
                }
            for (CourseSection other : new TreeSet<CourseSection>(pair.keySet())) {
                List<CSVFile.CSVField> line = new ArrayList<CSVFile.CSVField>();
                line.add(new CSVFile.CSVField(firstCourse && firstClass ? course.getName() : ""));
                line.add(new CSVFile.CSVField(firstCourse && firstClass ? total.size() : ""));
                line.add(new CSVFile.CSVField(firstClass ? section.getSubpart().getName() + " " + section.getName(course.getId()) : ""));
                line.add(new CSVFile.CSVField(firstClass ? section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(useAmPm) + " - " + section.getTime().getEndTimeHeader(useAmPm) : ""));
                line.add(new CSVFile.CSVField(firstClass ? rooms : ""));
                line.add(new CSVFile.CSVField(firstClass && sectionOverlap != null ? String.valueOf(sectionOverlap.size()) : ""));
                line.add(new CSVFile.CSVField(firstClass && sectionOverlap != null ? sDF2.format(((double) sectionOverlap.size()) / total.size()) : ""));
                line.add(new CSVFile.CSVField(other.getCourse().getName() + " " + other.getSection().getSubpart().getName() + " " + other.getSection().getName(other.getCourse().getId())));
                line.add(new CSVFile.CSVField(other.getSection().getTime().getDayHeader() + " " + other.getSection().getTime().getStartTimeHeader(useAmPm) + " - " + other.getSection().getTime().getEndTimeHeader(useAmPm)));
                String or = "";
                if (other.getSection().getRooms() != null)
                    for (RoomLocation r : other.getSection().getRooms()) {
                        if (!or.isEmpty())
                            or += "\n";
                        or += r.getName();
                    }
                line.add(new CSVFile.CSVField(or));
                line.add(new CSVFile.CSVField(sDF2.format(Placement.getDistanceInMeters(iDM, section.getPlacement(), other.getSection().getPlacement()))));
                line.add(new CSVFile.CSVField(String.valueOf(Placement.getDistanceInMinutes(iDM, section.getPlacement(), other.getSection().getPlacement()))));
                line.add(new CSVFile.CSVField(sDF1.format(pair.get(other))));
                line.add(new CSVFile.CSVField(sDF2.format(pair.get(other) / total.size())));
                csv.addLine(line);
                firstClass = false;
            }
            firstCourse = false;
        }
        csv.addLine();
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) TreeSet(java.util.TreeSet) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet) RoomLocation(org.cpsolver.coursett.model.RoomLocation) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Section(org.cpsolver.studentsct.model.Section) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Conflict(org.cpsolver.studentsct.extension.DistanceConflict.Conflict) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class RequestGroupTable method create.

@Override
public CSVFile create(Assignment<Request, Enrollment> assignment, DataProperties properties) {
    boolean useAmPm = properties.getPropertyBoolean("useAmPm", true);
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("Group"), new CSVFile.CSVField("Course"), new CSVFile.CSVField("Total\nSpread"), new CSVFile.CSVField("Group\nEnrollment"), new CSVFile.CSVField("Class"), new CSVFile.CSVField("Meeting Time"), new CSVFile.CSVField("Class\nSpread"), new CSVFile.CSVField("Class\nEnrollment"), new CSVFile.CSVField("Class\nLimit") });
    TreeSet<RequestGroup> groups = new TreeSet<RequestGroup>(new Comparator<RequestGroup>() {

        @Override
        public int compare(RequestGroup g1, RequestGroup g2) {
            int cmp = g1.getName().compareTo(g2.getName());
            if (cmp != 0)
                return cmp;
            cmp = g1.getCourse().getName().compareTo(g2.getCourse().getName());
            if (cmp != 0)
                return cmp;
            if (g1.getId() < g2.getId())
                return -1;
            if (g1.getId() > g2.getId())
                return 1;
            return (g1.getCourse().getId() < g2.getCourse().getId() ? -1 : g1.getCourse().getId() > g2.getCourse().getId() ? 1 : 0);
        }
    });
    for (Offering offering : iModel.getOfferings()) for (Course course : offering.getCourses()) groups.addAll(course.getRequestGroups());
    for (RequestGroup group : groups) {
        double groupEnrollment = group.getEnrollmentWeight(assignment, null);
        double groupSpread = group.getAverageSpread(assignment);
        for (Config config : group.getCourse().getOffering().getConfigs()) for (Subpart subpart : config.getSubparts()) for (Section section : subpart.getSections()) {
            double s = group.getSectionWeight(assignment, section, null);
            if (s > 0.00001) {
                csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(group.getName()), new CSVFile.CSVField(group.getCourse().getName()), new CSVFile.CSVField(sDF.format(100.0 * groupSpread)), new CSVFile.CSVField(Math.round(groupEnrollment)), new CSVFile.CSVField(section.getSubpart().getName() + " " + section.getName(group.getCourse().getId())), new CSVFile.CSVField(section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(useAmPm) + " - " + section.getTime().getEndTimeHeader(useAmPm)), new CSVFile.CSVField(sDF.format(100.0 * group.getSectionSpread(assignment, section))), new CSVFile.CSVField(Math.round(group.getSectionWeight(assignment, section, null))), new CSVFile.CSVField(section.getLimit()) });
            }
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) Config(org.cpsolver.studentsct.model.Config) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section) RequestGroup(org.cpsolver.studentsct.model.RequestGroup) TreeSet(java.util.TreeSet) Subpart(org.cpsolver.studentsct.model.Subpart) Course(org.cpsolver.studentsct.model.Course)

Example 14 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class TableauReport method create.

@Override
public CSVFile create(Assignment<Request, Enrollment> assignment, DataProperties properties) {
    CSVFile csv = new CSVFile();
    boolean simple = properties.getPropertyBoolean("simple", false);
    if (simple) {
        csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("__Student"), new CSVFile.CSVField("Student"), new CSVFile.CSVField("Course"), new CSVFile.CSVField("Course Limit"), new CSVFile.CSVField("Primary"), new CSVFile.CSVField("Priority"), new CSVFile.CSVField("Alternativity"), new CSVFile.CSVField("Enrolled"), new CSVFile.CSVField("Request Type") });
    } else {
        csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("__Student"), new CSVFile.CSVField("Student"), new CSVFile.CSVField("Course"), new CSVFile.CSVField("Course Limit"), new CSVFile.CSVField("Controlling Course"), new CSVFile.CSVField("Primary"), new CSVFile.CSVField("Priority"), new CSVFile.CSVField("Alternativity"), new CSVFile.CSVField("Enrolled"), new CSVFile.CSVField("Credits"), new CSVFile.CSVField("Sections"), new CSVFile.CSVField("Preferred Sections"), new CSVFile.CSVField("Required Sections"), new CSVFile.CSVField("Instructional Method"), new CSVFile.CSVField("Preferred Instructional Methods"), new CSVFile.CSVField("Required Instructional Methods"), new CSVFile.CSVField("Request Type") });
    }
    for (Student student : getModel().getStudents()) {
        if (student.isDummy())
            continue;
        int regPriority = 1, altPriority = 1;
        for (Request r : student.getRequests()) {
            if (r instanceof CourseRequest) {
                CourseRequest cr = (CourseRequest) r;
                Enrollment e = cr.getAssignment(assignment);
                int primary = (cr.isAlternative() ? 0 : 1);
                int priority = 0;
                if (cr.isAlternative())
                    priority = altPriority++;
                else
                    priority = regPriority++;
                int alternativity = 0;
                for (Course course : cr.getCourses()) {
                    int enrolled = (e != null && e.getCourse().equals(course) ? 1 : 0);
                    String sect = null;
                    if (e != null && e.getCourse().equals(course)) {
                        sect = "";
                        Set<String> added = new HashSet<String>();
                        for (Section s : e.getSections()) {
                            String x = s.getName(e.getCourse().getId());
                            if (x.indexOf('-') > 0)
                                x = x.substring(0, x.indexOf('-'));
                            if (added.add(x))
                                sect += (sect.isEmpty() ? "" : ",") + x;
                        }
                    }
                    String imR = "", sctR = "";
                    Set<String> addedR = new HashSet<String>();
                    for (Choice ch : cr.getRequiredChoices()) {
                        if (course.getOffering().equals(ch.getOffering())) {
                            if (ch.getConfigId() != null) {
                                for (Config cfg : ch.getOffering().getConfigs()) {
                                    if (ch.getConfigId().equals(cfg.getId())) {
                                        String im = cfg.getInstructionalMethodReference();
                                        if (im != null && addedR.add(im))
                                            imR += (imR.isEmpty() ? "" : ",") + im;
                                    }
                                }
                            }
                            if (ch.getSectionId() != null) {
                                String x = ch.getOffering().getSection(ch.getSectionId()).getName(course.getId());
                                if (x.indexOf('-') > 0)
                                    x = x.substring(0, x.indexOf('-'));
                                if (addedR.add(x))
                                    sctR += (sctR.isEmpty() ? "" : ",") + x;
                            }
                        }
                    }
                    for (Reservation rs : cr.getReservations(course)) {
                        if (rs.mustBeUsed()) {
                            for (Map.Entry<Subpart, Set<Section>> ent : rs.getSections().entrySet()) {
                                for (Section s : ent.getValue()) {
                                    String x = s.getName(course.getId());
                                    if (x.indexOf('-') > 0)
                                        x = x.substring(0, x.indexOf('-'));
                                    if (addedR.add(x))
                                        sctR += (sctR.isEmpty() ? "" : ",") + x;
                                }
                            }
                            if (rs.getSections().isEmpty()) {
                                for (Config cfg : rs.getConfigs()) {
                                    String im = cfg.getInstructionalMethodReference();
                                    if (im != null && addedR.add(im))
                                        imR += (imR.isEmpty() ? "" : ",") + im;
                                }
                            }
                        }
                    }
                    String imP = "", sctP = "";
                    for (Choice ch : cr.getSelectedChoices()) {
                        Set<String> added = new HashSet<String>();
                        if (course.getOffering().equals(ch.getOffering())) {
                            if (ch.getConfigId() != null) {
                                for (Config cfg : ch.getOffering().getConfigs()) {
                                    if (ch.getConfigId().equals(cfg.getId())) {
                                        String im = cfg.getInstructionalMethodReference();
                                        if (im != null && added.add(im))
                                            imP += (imP.isEmpty() ? "" : ",") + im;
                                    }
                                }
                            }
                            if (ch.getSectionId() != null) {
                                String x = ch.getOffering().getSection(ch.getSectionId()).getName(course.getId());
                                if (x.indexOf('-') > 0)
                                    x = x.substring(0, x.indexOf('-'));
                                if (added.add(x))
                                    sctP += (sctP.isEmpty() ? "" : ",") + x;
                            }
                        }
                    }
                    if (simple)
                        csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(student.getId()), new CSVFile.CSVField(student.getExternalId()), new CSVFile.CSVField(course.getName()), new CSVFile.CSVField(course.getLimit() < 0 ? null : course.getLimit()), new CSVFile.CSVField(primary == 1 ? "Yes" : "No"), new CSVFile.CSVField(priority), new CSVFile.CSVField(alternativity), new CSVFile.CSVField(enrolled == 1 ? "Yes" : "No"), new CSVFile.CSVField(cr.getRequestPriority() == null ? "" : cr.getRequestPriority().name()) });
                    else
                        csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(student.getId()), new CSVFile.CSVField(student.getExternalId()), new CSVFile.CSVField(course.getName()), new CSVFile.CSVField(course.getLimit() < 0 ? null : course.getLimit()), new CSVFile.CSVField(course.getOffering().getCourses().size() <= 1 ? null : course.getOffering().getName()), new CSVFile.CSVField(primary == 1 ? "Yes" : "No"), new CSVFile.CSVField(priority), new CSVFile.CSVField(alternativity), new CSVFile.CSVField(enrolled == 1 ? "Yes" : "No"), new CSVFile.CSVField(enrolled == 1 ? e.getCredit() : course.getCreditValue() == null ? 0f : course.getCreditValue()), new CSVFile.CSVField(sect), new CSVFile.CSVField(sctP), new CSVFile.CSVField(sctR), new CSVFile.CSVField(e != null ? e.getConfig().getInstructionalMethodReference() : null), new CSVFile.CSVField(imP), new CSVFile.CSVField(imR), new CSVFile.CSVField(cr.getRequestPriority() == null ? "" : cr.getRequestPriority().name()) });
                    alternativity++;
                }
            }
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) Choice(org.cpsolver.studentsct.model.Choice) Set(java.util.Set) HashSet(java.util.HashSet) Config(org.cpsolver.studentsct.model.Config) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Student(org.cpsolver.studentsct.model.Student) Section(org.cpsolver.studentsct.model.Section) Reservation(org.cpsolver.studentsct.reservation.Reservation) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Subpart(org.cpsolver.studentsct.model.Subpart) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) Map(java.util.Map) HashSet(java.util.HashSet)

Example 15 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class UnbalancedSectionsTable method createTable.

/**
 * Create report
 *
 * @param assignment current assignment
 * @param includeLastLikeStudents
 *            true, if last-like students should be included (i.e.,
 *            {@link Student#isDummy()} is true)
 * @param includeRealStudents
 *            true, if real students should be included (i.e.,
 *            {@link Student#isDummy()} is false)
 * @param useAmPm use 12-hour format
 * @return report as comma separated text file
 */
public CSVFile createTable(Assignment<Request, Enrollment> assignment, boolean includeLastLikeStudents, boolean includeRealStudents, boolean useAmPm) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("Course"), new CSVFile.CSVField("Class"), new CSVFile.CSVField("Meeting Time"), new CSVFile.CSVField("Enrollment"), new CSVFile.CSVField("Target"), new CSVFile.CSVField("Limit"), new CSVFile.CSVField("Disbalance [%]") });
    TreeSet<Offering> offerings = new TreeSet<Offering>(new Comparator<Offering>() {

        @Override
        public int compare(Offering o1, Offering o2) {
            int cmp = o1.getName().compareToIgnoreCase(o2.getName());
            if (cmp != 0)
                return cmp;
            return o1.getId() < o2.getId() ? -1 : o2.getId() == o2.getId() ? 0 : 1;
        }
    });
    offerings.addAll(getModel().getOfferings());
    Offering last = null;
    for (Offering offering : offerings) {
        for (Config config : offering.getConfigs()) {
            double configEnrl = 0;
            for (Enrollment e : config.getEnrollments(assignment)) {
                if (e.getStudent().isDummy() && !includeLastLikeStudents)
                    continue;
                if (!e.getStudent().isDummy() && !includeRealStudents)
                    continue;
                configEnrl += e.getRequest().getWeight();
            }
            for (Subpart subpart : config.getSubparts()) {
                if (subpart.getSections().size() <= 1)
                    continue;
                if (subpart.getLimit() > 0) {
                    // sections have limits -> desired size is section limit x (total enrollment / total limit)
                    double ratio = configEnrl / subpart.getLimit();
                    for (Section section : subpart.getSections()) {
                        double enrl = 0.0;
                        for (Enrollment e : section.getEnrollments(assignment)) {
                            if (e.getStudent().isDummy() && !includeLastLikeStudents)
                                continue;
                            if (!e.getStudent().isDummy() && !includeRealStudents)
                                continue;
                            enrl += e.getRequest().getWeight();
                        }
                        double desired = ratio * section.getLimit();
                        if (Math.abs(desired - enrl) >= Math.max(1.0, 0.1 * section.getLimit())) {
                            if (last != null && !offering.equals(last))
                                csv.addLine();
                            csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(offering.equals(last) ? "" : offering.getName()), new CSVFile.CSVField(section.getSubpart().getName() + " " + section.getName()), new CSVFile.CSVField(section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(useAmPm) + " - " + section.getTime().getEndTimeHeader(useAmPm)), new CSVFile.CSVField(sDF1.format(enrl)), new CSVFile.CSVField(sDF2.format(desired)), new CSVFile.CSVField(sDF1.format(section.getLimit())), new CSVFile.CSVField(sDF2.format(Math.min(1.0, Math.max(-1.0, (enrl - desired) / section.getLimit())))) });
                            last = offering;
                        }
                    }
                } else {
                    // unlimited sections -> desired size is total enrollment / number of sections
                    for (Section section : subpart.getSections()) {
                        double enrl = 0.0;
                        for (Enrollment e : section.getEnrollments(assignment)) {
                            if (e.getStudent().isDummy() && !includeLastLikeStudents)
                                continue;
                            if (!e.getStudent().isDummy() && !includeRealStudents)
                                continue;
                            enrl += e.getRequest().getWeight();
                        }
                        double desired = configEnrl / subpart.getSections().size();
                        if (Math.abs(desired - enrl) >= Math.max(1.0, 0.1 * desired)) {
                            if (last != null && !offering.equals(last))
                                csv.addLine();
                            csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(offering.equals(last) ? "" : offering.getName()), new CSVFile.CSVField(section.getSubpart().getName() + " " + section.getName()), new CSVFile.CSVField(section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(useAmPm) + " - " + section.getTime().getEndTimeHeader(useAmPm)), new CSVFile.CSVField(sDF1.format(enrl)), new CSVFile.CSVField(sDF2.format(desired)), new CSVFile.CSVField(""), new CSVFile.CSVField(sDF2.format(Math.min(1.0, Math.max(-1.0, (enrl - desired) / desired)))) });
                            last = offering;
                        }
                    }
                }
            }
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) TreeSet(java.util.TreeSet) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Enrollment(org.cpsolver.studentsct.model.Enrollment) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section)

Aggregations

CSVFile (org.cpsolver.ifs.util.CSVFile)26 ArrayList (java.util.ArrayList)14 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)13 Exam (org.cpsolver.exam.model.Exam)12 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)12 TreeSet (java.util.TreeSet)9 Enrollment (org.cpsolver.studentsct.model.Enrollment)9 Course (org.cpsolver.studentsct.model.Course)8 Request (org.cpsolver.studentsct.model.Request)8 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)7 Section (org.cpsolver.studentsct.model.Section)7 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)6 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)6 ExamStudent (org.cpsolver.exam.model.ExamStudent)6 HashSet (java.util.HashSet)5 Map (java.util.Map)5 DecimalFormat (java.text.DecimalFormat)4 Comparator (java.util.Comparator)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4