    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("Course"),
    070                new CSVFile.CSVField("Alternative"),
    071                new CSVFile.CSVField("Enrolled"),
    072                new CSVFile.CSVField("Primary"),
    073                new CSVFile.CSVField("Priority"),
    074                new CSVFile.CSVField("Alternativity")
    075                });
    076        for (Student student: getModel().getStudents()) {
    077            if (student.isDummy()) continue;
    078            int regPriority = 1, altPriority = 1;
    079            for (Request r: student.getRequests()) {
    080                if (r instanceof CourseRequest) {
    081                    CourseRequest cr = (CourseRequest)r;
    082                    Enrollment e = cr.getAssignment(assignment);
    083                    int primary = (cr.isAlternative() ? 0 : 1);
    084                    int priority = 0;
    085                    if (cr.isAlternative())
    086                        priority = altPriority++;
    087                    else
    088                        priority = regPriority++;
    089                    int alternativity = 0;
    090                    for (Course course: cr.getCourses()) {
    091                        int alternative = (primary == 0 || alternativity > 0 ? 1 : 0);
    092                        int enrolled = (e != null && e.getCourse().equals(course) ? 1 : 0);
    093                        csv.addLine(new CSVFile.CSVField[] {
    094                                new CSVFile.CSVField(student.getExternalId()),
    095                                new CSVFile.CSVField(cr.getCourses().get(alternativity).getName()),
    096                                new CSVFile.CSVField(alternative),
    097                                new CSVFile.CSVField(enrolled),
    098                                new CSVFile.CSVField(primary),
    099                                new CSVFile.CSVField(priority),
    100                                new CSVFile.CSVField(alternativity)
    101                        });
    102                        alternativity++;
    103                    }
    104                }
    105            }
    106        }
    107        return csv;
    108    }
    109}