001package org.cpsolver.exam.reports; 002 003import java.text.DecimalFormat; 004 005import org.cpsolver.exam.criteria.StudentBackToBackConflicts; 006import org.cpsolver.exam.criteria.StudentDirectConflicts; 007import org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts; 008import org.cpsolver.exam.criteria.StudentMoreThan2ADayConflicts; 009import org.cpsolver.exam.criteria.StudentNotAvailableConflicts; 010import org.cpsolver.exam.model.Exam; 011import org.cpsolver.exam.model.ExamModel; 012import org.cpsolver.exam.model.ExamPlacement; 013import org.cpsolver.ifs.assignment.Assignment; 014import org.cpsolver.ifs.util.CSVFile; 015import org.cpsolver.ifs.util.CSVFile.CSVField; 016 017 018/** 019 * Export student direct, back-to-back, and more than two exams a day conflicts 020 * summarized for each exam into a CSV file. <br> 021 * <br> 022 * Usage: 023 * <pre><code> 024 * new ExamStudentConflictsPerExam(model).report().save(file); 025 * </code></pre> 026 * <br> 027 * 028 * @author Tomáš Müller 029 * @version ExamTT 1.3 (Examination Timetabling)<br> 030 * Copyright (C) 2008 - 2014 Tomáš Müller<br> 031 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 032 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 033 * <br> 034 * This library is free software; you can redistribute it and/or modify 035 * it under the terms of the GNU Lesser General Public License as 036 * published by the Free Software Foundation; either version 3 of the 037 * License, or (at your option) any later version. <br> 038 * <br> 039 * This library is distributed in the hope that it will be useful, but 040 * WITHOUT ANY WARRANTY; without even the implied warranty of 041 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 042 * Lesser General Public License for more details. <br> 043 * <br> 044 * You should have received a copy of the GNU Lesser General Public 045 * License along with this library; if not see 046 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 047 */ 048public class ExamStudentConflictsPerExam { 049 private ExamModel iModel = null; 050 051 /** 052 * Constructor 053 * 054 * @param model 055 * examination timetabling model 056 */ 057 public ExamStudentConflictsPerExam(ExamModel model) { 058 iModel = model; 059 } 060 061 /** 062 * generate report 063 * @param assignment current assignment 064 * @return resultant report 065 */ 066 public CSVFile report(Assignment<Exam, ExamPlacement> assignment) { 067 CSVFile csv = new CSVFile(); 068 csv.setHeader(new CSVField[] { new CSVField("Exam"), new CSVField("Enrl"), new CSVField("Direct"), 069 new CSVField("Direct [%]"), new CSVField("More-2-Day"), new CSVField("More-2-Day [%]"), 070 new CSVField("Back-To-Back"), new CSVField("Back-To-Back [%]"), new CSVField("Dist Back-To-Back"), 071 new CSVField("Dist Back-To-Back [%]") }); 072 DecimalFormat df = new DecimalFormat("0.0"); 073 for (Exam exam : iModel.variables()) { 074 ExamPlacement placement = assignment.getValue(exam); 075 if (placement == null) 076 continue; 077 int dc = (int)iModel.getCriterion(StudentDirectConflicts.class).getValue(assignment, placement, null) + 078 (int)iModel.getCriterion(StudentNotAvailableConflicts.class).getValue(assignment, placement, null); 079 int btb = (int)iModel.getCriterion(StudentBackToBackConflicts.class).getValue(assignment, placement, null); 080 int dbtb = (int)iModel.getCriterion(StudentDistanceBackToBackConflicts.class).getValue(assignment, placement, null); 081 int m2d = (int)iModel.getCriterion(StudentMoreThan2ADayConflicts.class).getValue(assignment, placement, null); 082 if (dc == 0 && m2d == 0 && btb == 0 && dbtb == 0) 083 continue; 084 /* 085 * String section = ""; for (Enumeration 086 * f=exam.getCourseSections().elements();f.hasMoreElements();) { 087 * ExamCourseSection cs = (ExamCourseSection)f.nextElement(); if 088 * (section.length()>0) section+="\n"; section += cs.getName(); } 089 */ 090 csv.addLine(new CSVField[] { 091 new CSVField(exam.getName()), 092 new CSVField(exam.getStudents().size()), 093 new CSVField(dc), 094 new CSVField(df.format(100.0 * dc / exam.getStudents().size())), 095 new CSVField(m2d), 096 new CSVField(df.format(100.0 * m2d / exam.getStudents().size())), 097 new CSVField(btb), 098 new CSVField(df.format(100.0 * btb / exam.getStudents().size())), 099 new CSVField(dbtb), 100 new CSVField(df.format(100.0 * dbtb / exam.getStudents().size())) }); 101 } 102 return csv; 103 } 104}