001 package net.sf.cpsolver.exam.reports; 002 003 import java.util.Enumeration; 004 import java.util.Iterator; 005 import java.util.Vector; 006 007 import net.sf.cpsolver.exam.model.Exam; 008 import net.sf.cpsolver.exam.model.ExamModel; 009 import net.sf.cpsolver.exam.model.ExamOwner; 010 import net.sf.cpsolver.exam.model.ExamPlacement; 011 import net.sf.cpsolver.exam.model.ExamRoomPlacement; 012 import net.sf.cpsolver.ifs.util.CSVFile; 013 import net.sf.cpsolver.ifs.util.CSVFile.CSVField; 014 015 /** 016 * Export exam time and room assignments into a CSV file. Similar to {@link ExamAssignments}, 017 * however, a line is created for each course/section. 018 * <br><br> 019 * Usage:<br> 020 * <code> 021 * new ExamCourseSectionAssignments(model).report().save(file); 022 * </code> 023 * <br><br> 024 * 025 * @version 026 * ExamTT 1.1 (Examination Timetabling)<br> 027 * Copyright (C) 2008 Tomáš Müller<br> 028 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 029 * Lazenska 391, 76314 Zlin, Czech Republic<br> 030 * <br> 031 * This library is free software; you can redistribute it and/or 032 * modify it under the terms of the GNU Lesser General Public 033 * License as published by the Free Software Foundation; either 034 * version 2.1 of the License, or (at your option) any later version. 035 * <br><br> 036 * This library is distributed in the hope that it will be useful, 037 * but WITHOUT ANY WARRANTY; without even the implied warranty of 038 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 039 * Lesser General Public License for more details. 040 * <br><br> 041 * You should have received a copy of the GNU Lesser General Public 042 * License along with this library; if not, write to the Free Software 043 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 044 */ 045 public class ExamCourseSectionAssignments { 046 private ExamModel iModel = null; 047 048 /** 049 * Constructor 050 * @param model examination timetabling model 051 */ 052 public ExamCourseSectionAssignments(ExamModel model) { 053 iModel = model; 054 } 055 056 /** 057 * generate report 058 */ 059 public CSVFile report() { 060 CSVFile csv = new CSVFile(); 061 csv.setHeader(new CSVField[] { 062 new CSVField("Section/Course"), 063 new CSVField("Enrl"), 064 new CSVField("Alt"), 065 new CSVField("Period"), 066 new CSVField("Date"), 067 new CSVField("Time"), 068 new CSVField("Room"), 069 new CSVField("Cap") 070 }); 071 for (Enumeration e=iModel.variables().elements();e.hasMoreElements();) { 072 Exam exam = (Exam)e.nextElement(); 073 ExamPlacement placement = (ExamPlacement)exam.getAssignment(); 074 for (Enumeration f=exam.getOwners().elements();f.hasMoreElements();) { 075 ExamOwner owner = (ExamOwner)f.nextElement(); 076 Vector fields = new Vector(); 077 fields.addElement(new CSVField(owner.getName())); 078 fields.addElement(new CSVField(owner.getStudents().size())); 079 fields.addElement(new CSVField(exam.hasAltSeating()?"Yes":"No")); 080 if (placement==null) { 081 fields.addElement(new CSVField("")); 082 fields.addElement(new CSVField("")); 083 fields.addElement(new CSVField("")); 084 fields.addElement(new CSVField("")); 085 fields.addElement(new CSVField("")); 086 } else { 087 fields.addElement(new CSVField(placement.getPeriod().getIndex()+1)); 088 fields.addElement(new CSVField(placement.getPeriod().getDayStr())); 089 fields.addElement(new CSVField(placement.getPeriod().getTimeStr())); 090 String rooms = ""; 091 String roomSizes = ""; 092 for (Iterator i=placement.getRoomPlacements().iterator();i.hasNext();) { 093 ExamRoomPlacement room = (ExamRoomPlacement)i.next(); 094 rooms += room.getName(); 095 roomSizes += room.getSize(exam.hasAltSeating()); 096 if (i.hasNext()) { 097 rooms+=", "; 098 roomSizes+=", "; 099 } 100 } 101 fields.addElement(new CSVField(rooms)); 102 fields.addElement(new CSVField(roomSizes)); 103 } 104 csv.addLine(fields); 105 } 106 } 107 return csv; 108 } 109 }