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