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