001package org.cpsolver.studentsct.report;
002
003import org.cpsolver.ifs.assignment.Assignment;
004import org.cpsolver.ifs.util.CSVFile;
005import org.cpsolver.ifs.util.DataProperties;
006import org.cpsolver.studentsct.StudentSectioningModel;
007import org.cpsolver.studentsct.model.Course;
008import org.cpsolver.studentsct.model.CourseRequest;
009import org.cpsolver.studentsct.model.Enrollment;
010import org.cpsolver.studentsct.model.Request;
011import org.cpsolver.studentsct.model.Request.RequestPriority;
012import org.cpsolver.studentsct.model.Student;
013
014/**
015 * This reports lists critical courses and their assignments.<br>
016 * <br>
017 * 
018 * @version StudentSct 1.3 (Student Sectioning)<br>
019 *          Copyright (C) 2015 Tomáš Müller<br>
020 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
021 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
022 * <br>
023 *          This library is free software; you can redistribute it and/or modify
024 *          it under the terms of the GNU Lesser General Public License as
025 *          published by the Free Software Foundation; either version 3 of the
026 *          License, or (at your option) any later version. <br>
027 * <br>
028 *          This library is distributed in the hope that it will be useful, but
029 *          WITHOUT ANY WARRANTY; without even the implied warranty of
030 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
031 *          Lesser General Public License for more details. <br>
032 * <br>
033 *          You should have received a copy of the GNU Lesser General Public
034 *          License along with this library; if not see
035 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
036 */
037public class CriticalCoursesTable extends AbstractStudentSectioningReport {
038    /**
039     * Constructor
040     * 
041     * @param model
042     *            student sectioning model
043     */
044    public CriticalCoursesTable(StudentSectioningModel model) {
045        super(model);
046    }
047
048    @Override
049    public CSVFile createTable(Assignment<Request, Enrollment> assignment, DataProperties properties) {
050        RequestPriority rp = RequestPriority.valueOf(properties.getProperty("priority", RequestPriority.Critical.name()));
051        CSVFile csv = new CSVFile();
052        csv.setHeader(new CSVFile.CSVField[] {
053                new CSVFile.CSVField("__Student"),
054                new CSVFile.CSVField("Student"),
055                new CSVFile.CSVField("Priority"),
056                new CSVFile.CSVField("Course"),
057                new CSVFile.CSVField("1st Alt"),
058                new CSVFile.CSVField("2nd Alt"),
059                new CSVFile.CSVField("Enrolled"),
060                new CSVFile.CSVField("Choice")
061                });
062        for (Student student: getModel().getStudents()) {
063            if (student.isDummy()) continue;
064            int priority = 0;
065            for (Request r: student.getRequests()) {
066                if (r instanceof CourseRequest) {
067                    CourseRequest cr = (CourseRequest)r;
068                    priority ++;
069                    if (rp != cr.getRequestPriority() || cr.isAlternative()) continue;
070                    Enrollment e = cr.getAssignment(assignment);
071                    if (!matches(cr, e)) continue;
072                    Course course = cr.getCourses().get(0);
073                    Course alt1 = (cr.getCourses().size() < 2 ? null : cr.getCourses().get(1));
074                    Course alt2 = (cr.getCourses().size() < 3 ? null : cr.getCourses().get(2));
075                    Course enrolled = (e == null ? null : e.getCourse());
076                    csv.addLine(new CSVFile.CSVField[] {
077                            new CSVFile.CSVField(student.getId()),
078                            new CSVFile.CSVField(student.getExternalId()),
079                            new CSVFile.CSVField(priority),
080                            new CSVFile.CSVField(course.getName()),
081                            new CSVFile.CSVField(alt1 == null ? "" : alt1.getName()),
082                            new CSVFile.CSVField(alt2 == null ? "" : alt2.getName()),
083                            new CSVFile.CSVField(enrolled == null ? "" : enrolled.getName()),
084                            new CSVFile.CSVField(enrolled == null ? "" : String.valueOf(cr.getCourses().indexOf(enrolled) + 1))
085                    });
086                }
087            }
088        }
089        return csv;
090    }
091}