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