001 package net.sf.cpsolver.exam.reports; 002 003 004 import java.util.ArrayList; 005 import java.util.List; 006 007 import net.sf.cpsolver.exam.model.ExamModel; 008 import net.sf.cpsolver.exam.model.ExamPeriod; 009 import net.sf.cpsolver.exam.model.ExamStudent; 010 import net.sf.cpsolver.ifs.util.CSVFile; 011 import net.sf.cpsolver.ifs.util.CSVFile.CSVField; 012 013 /** 014 * Export distribution of number of students by number of meetings per day into 015 * a CSV file. <br> 016 * <br> 017 * Usage:<br> 018 * <code> 019 * new ExamNbrMeetingsPerDay(model).report().save(file); 020 * </code> <br> 021 * <br> 022 * 023 * @version ExamTT 1.2 (Examination Timetabling)<br> 024 * Copyright (C) 2008 - 2010 Tomas Muller<br> 025 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 026 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 027 * <br> 028 * This library is free software; you can redistribute it and/or modify 029 * it under the terms of the GNU Lesser General Public License as 030 * published by the Free Software Foundation; either version 3 of the 031 * License, or (at your option) any later version. <br> 032 * <br> 033 * This library is distributed in the hope that it will be useful, but 034 * WITHOUT ANY WARRANTY; without even the implied warranty of 035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 036 * Lesser General Public License for more details. <br> 037 * <br> 038 * You should have received a copy of the GNU Lesser General Public 039 * License along with this library; if not see 040 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 041 */ 042 public class ExamNbrMeetingsPerDay { 043 private ExamModel iModel = null; 044 045 /** 046 * Constructor 047 * 048 * @param model 049 * examination timetabling model 050 */ 051 public ExamNbrMeetingsPerDay(ExamModel model) { 052 iModel = model; 053 } 054 055 /** 056 * generate report 057 */ 058 public CSVFile report() { 059 CSVFile csv = new CSVFile(); 060 List<CSVField> header = new ArrayList<CSVField>(); 061 header.add(new CSVField("Date")); 062 header.add(new CSVField("None")); 063 for (int i = 1; i <= 5; i++) 064 header.add(new CSVField(i == 5 ? "5+" : String.valueOf(i))); 065 header.add(new CSVField("Back-To-Back")); 066 csv.setHeader(header); 067 int[] nrExamsTotal = new int[6]; 068 for (int i = 0; i <= 5; i++) 069 nrExamsTotal[i] = 0; 070 int btbTotal = 0; 071 for (int d = 0; d < iModel.getNrDays(); d++) { 072 ExamPeriod period = null; 073 for (ExamPeriod p : iModel.getPeriods()) { 074 if (p.getDay() == d) { 075 period = p; 076 break; 077 } 078 } 079 int[] nrExams = new int[6]; 080 for (int i = 0; i <= 5; i++) 081 nrExams[i] = 0; 082 int btb = 0; 083 for (ExamStudent student : iModel.getStudents()) { 084 int ex = student.getExamsADay(d).size(); 085 nrExams[ex <= 5 ? ex : 5]++; 086 ExamPeriod p = period; 087 while (p.next() != null && (iModel.isDayBreakBackToBack() ? p : p.next()).getDay() == d) { 088 btb += student.getExams(p).size() * student.getExams(p.next()).size(); 089 p = p.next(); 090 } 091 } 092 List<CSVField> line = new ArrayList<CSVField>(); 093 line.add(new CSVField(period.getDayStr())); 094 for (int i = 0; i <= 5; i++) { 095 line.add(new CSVField(nrExams[i])); 096 nrExamsTotal[i] += nrExams[i]; 097 } 098 line.add(new CSVField(btb)); 099 btbTotal += btb; 100 csv.addLine(line); 101 } 102 List<CSVField> line = new ArrayList<CSVField>(); 103 line.add(new CSVField("Total")); 104 for (int i = 0; i <= 5; i++) 105 line.add(new CSVField(nrExamsTotal[i])); 106 line.add(new CSVField(btbTotal)); 107 csv.addLine(line); 108 return csv; 109 } 110 }