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