    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 all the requested courses and their properties.<br>
    015 * <br>
    016 * Namely:<ul>
    017 * <li><b>Alternative</b> is 1 when the course was requested as an alternative (<b>Primary</b> is 0 or <b>Alternativity</b> is above 0)</li>
    018 * <li><b>Enrolled</b> is 1 when the student is enrolled in the course</li>
    019 * <li><b>Primary</b> is 1 when the request is from the Course Requests table, 0 when it is from the Alternate Course Requests table</li>
    020 * <li><b>Priority</b> is the request's priority</li>
    021 * <li><b>Alternativity</b> is the request's alternativity (0 for the primary course, 1 for the first alternative, 2 for the second alternative, etc.)</li>
    022 * </ul>
    023 * <br>
    024 *
    025 * @author  Tomáš Müller
    026 * @version StudentSct 1.3 (Student Sectioning)<br>
    027 *          Copyright (C) 2015 Tomáš Müller<br>
    028 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    029 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    030 * <br>
    031 *          This library is free software; you can redistribute it and/or modify
    032 *          it under the terms of the GNU Lesser General Public License as
    033 *          published by the Free Software Foundation; either version 3 of the
    034 *          License, or (at your option) any later version. <br>
    035 * <br>
    036 *          This library is distributed in the hope that it will be useful, but
    037 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    038 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    039 *          Lesser General Public License for more details. <br>
    040 * <br>
    041 *          You should have received a copy of the GNU Lesser General Public
    042 *          License along with this library; if not see
    043 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    044 */
    045public class RequestPriorityTable extends AbstractStudentSectioningReport {
    046    /**
    047     * Constructor
    048     *
    049     * @param model
    050     *            student sectioning model
    051     */
    052    public RequestPriorityTable(StudentSectioningModel model) {
    053        super(model);
    054    }
    055
    056    @Override
    057    public CSVFile createTable(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("Course"),
    063                new CSVFile.CSVField("Alternative"),
    064                new CSVFile.CSVField("Enrolled"),
    065                new CSVFile.CSVField("Primary"),
    066                new CSVFile.CSVField("Priority"),
    067                new CSVFile.CSVField("Alternativity")
    068                });
    069        for (Student student: getModel().getStudents()) {
    070            if (student.isDummy()) continue;
    071            int regPriority = 1, altPriority = 1;
    072            for (Request r: student.getRequests()) {
    073                if (r instanceof CourseRequest) {
    074                    CourseRequest cr = (CourseRequest)r;
    075                    Enrollment e = cr.getAssignment(assignment);
    076                    if (!matches(cr, e)) continue;
    077                    int primary = (cr.isAlternative() ? 0 : 1);
    078                    int priority = 0;
    079                    if (cr.isAlternative())
    080                        priority = altPriority++;
    081                    else
    082                        priority = regPriority++;
    083                    int alternativity = 0;
    084                    for (Course course: cr.getCourses()) {
    085                        int alternative = (primary == 0 || alternativity > 0 ? 1 : 0);
    086                        int enrolled = (e != null && e.getCourse().equals(course) ? 1 : 0);
    087                        csv.addLine(new CSVFile.CSVField[] {
    088                                new CSVFile.CSVField(student.getId()),
    089                                new CSVFile.CSVField(student.getExternalId()),
    090                                new CSVFile.CSVField(cr.getCourses().get(alternativity).getName()),
    091                                new CSVFile.CSVField(alternative),
    092                                new CSVFile.CSVField(enrolled),
    093                                new CSVFile.CSVField(primary),
    094                                new CSVFile.CSVField(priority),
    095                                new CSVFile.CSVField(alternativity)
    096                        });
    097                        alternativity++;
    098                    }
    099                }
    100            }
    101        }
    102        return csv;
    103    }
    104}