Search in sources :

Example 11 with ExamPeriod

use of org.cpsolver.exam.model.ExamPeriod in project cpsolver by UniTime.

the class ExamStudentConflictsBySectionCourse method report.

/**
     * generate report
     * @param assignment current assignment
     * @return resultant report
     */
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVField[] { new CSVField("Section/Course"), new CSVField("Period"), new CSVField("Day"), new CSVField("Time"), new CSVField("Room"), new CSVField("Student"), new CSVField("Type"), new CSVField("Section/Course"), new CSVField("Period"), new CSVField("Time"), new CSVField("Room"), new CSVField("Distance") });
    boolean isDayBreakBackToBack = ((StudentBackToBackConflicts) iModel.getCriterion(StudentBackToBackConflicts.class)).isDayBreakBackToBack();
    double backToBackDistance = ((StudentDistanceBackToBackConflicts) iModel.getCriterion(StudentDistanceBackToBackConflicts.class)).getBackToBackDistance();
    TreeSet<ExamOwner> courseSections = new TreeSet<ExamOwner>();
    for (Exam exam : iModel.variables()) {
        courseSections.addAll(getOwners(exam));
    }
    for (ExamOwner cs : courseSections) {
        Exam exam = cs.getExam();
        ExamPlacement placement = assignment.getValue(exam);
        if (placement == null)
            continue;
        String roomsThisExam = "";
        for (ExamRoomPlacement room : placement.getRoomPlacements()) {
            if (roomsThisExam.length() > 0)
                roomsThisExam += ", ";
            roomsThisExam += room.getName();
        }
        ExamPeriod period = placement.getPeriod();
        boolean csPrinted = false;
        List<ExamStudent> students = new ArrayList<ExamStudent>(cs.getStudents());
        Collections.sort(students, new Comparator<ExamStudent>() {

            @Override
            public int compare(ExamStudent s1, ExamStudent s2) {
                int cmp = s1.getName().compareTo(s2.getName());
                if (cmp != 0)
                    return cmp;
                return Double.compare(s1.getId(), s2.getId());
            }
        });
        for (ExamStudent student : students) {
            boolean stdPrinted = false;
            int nrExams = student.getExams(assignment, period).size();
            if (nrExams > 1) {
                boolean typePrinted = false;
                for (Exam otherExam : student.getExams(assignment, period)) {
                    if (otherExam.equals(exam))
                        continue;
                    ExamPlacement otherPlacement = assignment.getValue(otherExam);
                    ExamPeriod otherPeriod = otherPlacement.getPeriod();
                    String roomsOtherExam = "";
                    for (ExamRoomPlacement room : otherPlacement.getRoomPlacements()) {
                        if (roomsOtherExam.length() > 0)
                            roomsOtherExam += ", ";
                        roomsOtherExam += room.getName();
                    }
                    boolean otherPrinted = false;
                    for (ExamOwner ocs : getOwners(otherExam, student)) {
                        csv.addLine(new CSVField[] { new CSVField(csPrinted ? "" : cs.getName()), new CSVField(csPrinted ? "" : String.valueOf(1 + period.getIndex())), new CSVField(csPrinted ? "" : period.getDayStr()), new CSVField(csPrinted ? "" : period.getTimeStr()), new CSVField(csPrinted ? "" : roomsThisExam), new CSVField(stdPrinted ? "" : student.getName()), new CSVField(typePrinted ? "" : "direct"), new CSVField(ocs.getName()), new CSVField(otherPrinted ? "" : String.valueOf(1 + otherPeriod.getIndex())), new CSVField(otherPrinted ? "" : otherPeriod.getTimeStr()), new CSVField(otherPrinted ? "" : roomsOtherExam) });
                        csPrinted = true;
                        stdPrinted = true;
                        typePrinted = true;
                        otherPrinted = true;
                    }
                }
            }
            if (nrExams > 0) {
                boolean typePrinted = false;
                List<ExamPeriod> periods = new ArrayList<ExamPeriod>(2);
                if (period.prev() != null && !student.getExams(assignment, period.prev()).isEmpty() && (!isDayBreakBackToBack || period.prev().getDay() == period.getDay()))
                    periods.add(period.prev());
                if (period.next() != null && !student.getExams(assignment, period.next()).isEmpty() && (!isDayBreakBackToBack || period.next().getDay() == period.getDay()))
                    periods.add(period.next());
                for (ExamPeriod otherPeriod : periods) {
                    for (Exam otherExam : student.getExams(assignment, otherPeriod)) {
                        ExamPlacement otherPlacement = assignment.getValue(otherExam);
                        String roomsOtherExam = "";
                        for (ExamRoomPlacement room : otherPlacement.getRoomPlacements()) {
                            if (roomsOtherExam.length() > 0)
                                roomsOtherExam += ", ";
                            roomsOtherExam += room.getName();
                        }
                        String distStr = "";
                        if (backToBackDistance >= 0) {
                            double dist = placement.getDistanceInMeters(otherPlacement);
                            if (dist > 0)
                                distStr = String.valueOf(dist);
                        }
                        boolean otherPrinted = false;
                        for (ExamOwner ocs : getOwners(otherExam, student)) {
                            csv.addLine(new CSVField[] { new CSVField(csPrinted ? "" : cs.getName()), new CSVField(csPrinted ? "" : String.valueOf(1 + period.getIndex())), new CSVField(csPrinted ? "" : period.getDayStr()), new CSVField(csPrinted ? "" : period.getTimeStr()), new CSVField(csPrinted ? "" : roomsThisExam), new CSVField(stdPrinted ? "" : student.getName()), new CSVField(typePrinted ? "" : "back-to-back"), new CSVField(ocs.getName()), new CSVField(otherPrinted ? "" : String.valueOf(1 + otherPeriod.getIndex())), new CSVField(otherPrinted ? "" : otherPeriod.getTimeStr()), new CSVField(otherPrinted ? "" : roomsOtherExam), new CSVField(otherPrinted ? "" : distStr) });
                            csPrinted = true;
                            stdPrinted = true;
                            typePrinted = true;
                            otherPrinted = true;
                        }
                    }
                }
            }
            int nrExamsADay = student.getExamsADay(assignment, period.getDay()).size();
            if (nrExamsADay > 2) {
                boolean typePrinted = false;
                for (Exam otherExam : student.getExamsADay(assignment, period.getDay())) {
                    if (otherExam.equals(exam))
                        continue;
                    ExamPlacement otherPlacement = assignment.getValue(otherExam);
                    ExamPeriod otherPeriod = otherPlacement.getPeriod();
                    String roomsOtherExam = "";
                    for (ExamRoomPlacement room : otherPlacement.getRoomPlacements()) {
                        if (roomsOtherExam.length() > 0)
                            roomsOtherExam += ", ";
                        roomsOtherExam += room.getName();
                    }
                    boolean otherPrinted = false;
                    for (ExamOwner ocs : getOwners(otherExam, student)) {
                        csv.addLine(new CSVField[] { new CSVField(csPrinted ? "" : cs.getName()), new CSVField(csPrinted ? "" : String.valueOf(1 + period.getIndex())), new CSVField(csPrinted ? "" : period.getDayStr()), new CSVField(csPrinted ? "" : period.getTimeStr()), new CSVField(csPrinted ? "" : roomsThisExam), new CSVField(stdPrinted ? "" : student.getName()), new CSVField(typePrinted ? "" : "more-2-day"), new CSVField(ocs.getName()), new CSVField(otherPrinted ? "" : String.valueOf(1 + otherPeriod.getIndex())), new CSVField(otherPrinted ? "" : otherPeriod.getTimeStr()), new CSVField(otherPrinted ? "" : roomsOtherExam) });
                        csPrinted = true;
                        stdPrinted = true;
                        typePrinted = true;
                        otherPrinted = true;
                    }
                }
            }
        }
    }
    return csv;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) CSVFile(org.cpsolver.ifs.util.CSVFile) ArrayList(java.util.ArrayList) ExamStudent(org.cpsolver.exam.model.ExamStudent) ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) StudentBackToBackConflicts(org.cpsolver.exam.criteria.StudentBackToBackConflicts) TreeSet(java.util.TreeSet) ExamOwner(org.cpsolver.exam.model.ExamOwner) StudentDistanceBackToBackConflicts(org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts) Exam(org.cpsolver.exam.model.Exam)

Example 12 with ExamPeriod

use of org.cpsolver.exam.model.ExamPeriod in project cpsolver by UniTime.

the class ExamNbrMeetingsPerDay method report.

/**
     * generate report
     * @param assignment current assignment
     * @return resultant report
     */
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
    CSVFile csv = new CSVFile();
    List<CSVField> header = new ArrayList<CSVField>();
    header.add(new CSVField("Date"));
    header.add(new CSVField("None"));
    boolean isDayBreakBackToBack = ((StudentBackToBackConflicts) iModel.getCriterion(StudentBackToBackConflicts.class)).isDayBreakBackToBack();
    for (int i = 1; i <= 5; i++) header.add(new CSVField(i == 5 ? "5+" : String.valueOf(i)));
    header.add(new CSVField("Back-To-Back"));
    csv.setHeader(header);
    int[] nrExamsTotal = new int[6];
    for (int i = 0; i <= 5; i++) nrExamsTotal[i] = 0;
    int btbTotal = 0;
    for (int d = 0; d < iModel.getNrDays(); d++) {
        ExamPeriod period = null;
        for (ExamPeriod p : iModel.getPeriods()) {
            if (p.getDay() == d) {
                period = p;
                break;
            }
        }
        int[] nrExams = new int[6];
        for (int i = 0; i <= 5; i++) nrExams[i] = 0;
        int btb = 0;
        for (ExamStudent student : iModel.getStudents()) {
            int ex = student.getExamsADay(assignment, d).size();
            nrExams[ex <= 5 ? ex : 5]++;
            ExamPeriod p = period;
            while (p.next() != null && (isDayBreakBackToBack ? p : p.next()).getDay() == d) {
                btb += student.getExams(assignment, p).size() * student.getExams(assignment, p.next()).size();
                p = p.next();
            }
        }
        List<CSVField> line = new ArrayList<CSVField>();
        line.add(new CSVField(period.getDayStr()));
        for (int i = 0; i <= 5; i++) {
            line.add(new CSVField(nrExams[i]));
            nrExamsTotal[i] += nrExams[i];
        }
        line.add(new CSVField(btb));
        btbTotal += btb;
        csv.addLine(line);
    }
    List<CSVField> line = new ArrayList<CSVField>();
    line.add(new CSVField("Total"));
    for (int i = 0; i <= 5; i++) line.add(new CSVField(nrExamsTotal[i]));
    line.add(new CSVField(btbTotal));
    csv.addLine(line);
    return csv;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) CSVFile(org.cpsolver.ifs.util.CSVFile) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) StudentBackToBackConflicts(org.cpsolver.exam.criteria.StudentBackToBackConflicts) ArrayList(java.util.ArrayList) ExamStudent(org.cpsolver.exam.model.ExamStudent)

Example 13 with ExamPeriod

use of org.cpsolver.exam.model.ExamPeriod in project cpsolver by UniTime.

the class ExamPeriodUsage method report.

/**
     * generate report
     * @param assignment current assignment
     * @return resultant report
     */
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
    CSVFile csv = new CSVFile();
    List<CSVField> header = new ArrayList<CSVField>();
    header.add(new CSVField("Period"));
    header.add(new CSVField("Date"));
    header.add(new CSVField("Time"));
    header.add(new CSVField("Weight"));
    header.add(new CSVField("NrExams"));
    header.add(new CSVField("Students"));
    for (int i = 0; i < sLimits.length; i++) {
        header.add(new CSVField("NrExams>=" + sLimits[i]));
    }
    header.add(new CSVField("AvgPeriod"));
    header.add(new CSVField("WgAvgPeriod"));
    csv.setHeader(header);
    for (ExamPeriod period : iModel.getPeriods()) {
        int nrExams = 0;
        int nrStudents = 0;
        int[] nrExamsLim = new int[sLimits.length];
        int totAvgPer = 0, nrAvgPer = 0, totWgAvgPer = 0;
        for (int i = 0; i < sLimits.length; i++) nrExamsLim[i] = 0;
        for (Exam exam : iModel.variables()) {
            ExamPlacement placement = assignment.getValue(exam);
            if (placement == null || !(placement.getPeriod().equals(period)))
                continue;
            nrExams++;
            nrStudents += exam.getStudents().size();
            if (exam.getAveragePeriod() >= 0) {
                totAvgPer += exam.getAveragePeriod();
                nrAvgPer++;
                totWgAvgPer += exam.getAveragePeriod() * exam.getStudents().size();
            }
            for (int i = 0; i < sLimits.length; i++) if (exam.getStudents().size() >= sLimits[i])
                nrExamsLim[i]++;
        }
        List<CSVField> line = new ArrayList<CSVField>();
        line.add(new CSVField(period.getIndex() + 1));
        line.add(new CSVField(period.getDayStr()));
        line.add(new CSVField(period.getTimeStr()));
        line.add(new CSVField(period.getPenalty()));
        line.add(new CSVField(nrExams));
        line.add(new CSVField(nrStudents));
        for (int i = 0; i < sLimits.length; i++) line.add(new CSVField(nrExamsLim[i]));
        if (nrAvgPer > 0) {
            line.add(new CSVField(sDF.format(((double) totAvgPer) / nrAvgPer)));
            line.add(new CSVField(sDF.format(((double) totWgAvgPer) / nrAvgPer)));
        }
        csv.addLine(line);
    }
    return csv;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) CSVFile(org.cpsolver.ifs.util.CSVFile) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ArrayList(java.util.ArrayList) Exam(org.cpsolver.exam.model.Exam)

Aggregations

ExamPeriod (org.cpsolver.exam.model.ExamPeriod)13 Exam (org.cpsolver.exam.model.Exam)12 ExamStudent (org.cpsolver.exam.model.ExamStudent)7 Set (java.util.Set)6 ExamModel (org.cpsolver.exam.model.ExamModel)6 CSVFile (org.cpsolver.ifs.util.CSVFile)6 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)6 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)5 ArrayList (java.util.ArrayList)4 StudentBackToBackConflicts (org.cpsolver.exam.criteria.StudentBackToBackConflicts)3 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)3 ExamOwner (org.cpsolver.exam.model.ExamOwner)3 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)3 StudentDistanceBackToBackConflicts (org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts)2 TreeSet (java.util.TreeSet)1 InstructorBackToBackConflicts (org.cpsolver.exam.criteria.InstructorBackToBackConflicts)1 InstructorDistanceBackToBackConflicts (org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts)1 ExamRoom (org.cpsolver.exam.model.ExamRoom)1