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