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