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 extends AbstractStudentSectioningReport {
045    /**
046     * Constructor
047     * 
048     * @param model
049     *            student sectioning model
050     */
051    public RequestPriorityTable(StudentSectioningModel model) {
052        super(model);
053    }
054    
055    @Override
056    public CSVFile createTable(Assignment<Request, Enrollment> assignment, DataProperties properties) {
057        CSVFile csv = new CSVFile();
058        csv.setHeader(new CSVFile.CSVField[] {
059                new CSVFile.CSVField("__Student"),
060                new CSVFile.CSVField("Student"),
061                new CSVFile.CSVField("Course"),
062                new CSVFile.CSVField("Alternative"),
063                new CSVFile.CSVField("Enrolled"),
064                new CSVFile.CSVField("Primary"),
065                new CSVFile.CSVField("Priority"),
066                new CSVFile.CSVField("Alternativity")
067                });
068        for (Student student: getModel().getStudents()) {
069            if (student.isDummy()) continue;
070            int regPriority = 1, altPriority = 1;
071            for (Request r: student.getRequests()) {
072                if (r instanceof CourseRequest) {
073                    CourseRequest cr = (CourseRequest)r;
074                    Enrollment e = cr.getAssignment(assignment);
075                    if (!matches(cr, e)) continue;
076                    int primary = (cr.isAlternative() ? 0 : 1);
077                    int priority = 0;
078                    if (cr.isAlternative())
079                        priority = altPriority++;
080                    else
081                        priority = regPriority++;
082                    int alternativity = 0;
083                    for (Course course: cr.getCourses()) {
084                        int alternative = (primary == 0 || alternativity > 0 ? 1 : 0);
085                        int enrolled = (e != null && e.getCourse().equals(course) ? 1 : 0);
086                        csv.addLine(new CSVFile.CSVField[] {
087                                new CSVFile.CSVField(student.getId()),
088                                new CSVFile.CSVField(student.getExternalId()),
089                                new CSVFile.CSVField(cr.getCourses().get(alternativity).getName()),
090                                new CSVFile.CSVField(alternative),
091                                new CSVFile.CSVField(enrolled),
092                                new CSVFile.CSVField(primary),
093                                new CSVFile.CSVField(priority),
094                                new CSVFile.CSVField(alternativity)
095                        });
096                        alternativity++;
097                    }
098                }
099            }
100        }
101        return csv;
102    }
103}