001package org.cpsolver.studentsct.report;
002
003import java.text.DecimalFormat;
004import java.util.ArrayList;
005import java.util.Comparator;
006import java.util.HashMap;
007import java.util.HashSet;
008import java.util.List;
009import java.util.Map;
010import java.util.Set;
011import java.util.TreeSet;
012
013import org.cpsolver.ifs.assignment.Assignment;
014import org.cpsolver.ifs.model.GlobalConstraint;
015import org.cpsolver.ifs.util.CSVFile;
016import org.cpsolver.ifs.util.DataProperties;
017import org.cpsolver.studentsct.StudentSectioningModel;
018import org.cpsolver.studentsct.constraint.SectionLimit;
019import org.cpsolver.studentsct.model.Course;
020import org.cpsolver.studentsct.model.CourseRequest;
021import org.cpsolver.studentsct.model.Enrollment;
022import org.cpsolver.studentsct.model.FreeTimeRequest;
023import org.cpsolver.studentsct.model.Request;
024import org.cpsolver.studentsct.model.Section;
025
026
027/**
028 * This class computes time and availability conflicts on classes in a {@link CSVFile} comma separated
029 * text file. <br>
030 * <br>
031 * The first report (type OVERLAPS) shows time conflicts between pairs of classes. Each such enrollment
032 * is given a weight of 1/n, where n is the number of available enrollments of the student into the course.
033 * This 1/n is added to each class that is present in a conflict. These numbers are aggregated on
034 * individual classes and on pairs of classes (that are in a time conflict).
035 * <br>
036 * The second report (type UNAVAILABILITIES) shows for each course how many students could not get into
037 * the course because of the limit constraints. It considers all the not-conflicting, but unavailable enrollments
038 * of a student into the course. For each such an enrollment 1/n is added to each class. So, in a way, the
039 * Availability Conflicts column shows how much space is missing in each class. The Class Potential column
040 * can be handy as well. If the class would be unlimited, this is the number of students (out of all the 
041 * conflicting students) that can get into the class.
042 * <br>
043 * The last report (type OVERLAPS_AND_UNAVAILABILITIES) show the two reports together. It is possible that
044 * there is a course where some students cannot get in because of availabilities (all not-conflicting enrollments
045 * have no available space) as well as time conflicts (all available enrollments are conflicting with some other
046 * classes the student has). 
047 * <br>
048 * <br>
049 * 
050 * Usage: new SectionConflictTable(model, type),createTable(true, true).save(aFile);
051 * 
052 * <br>
053 * <br>
054 * 
055 * @author  Tomáš Müller
056 * @version StudentSct 1.3 (Student Sectioning)<br>
057 *          Copyright (C) 2013 - 2014 Tomáš Müller<br>
058 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
059 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
060 * <br>
061 *          This library is free software; you can redistribute it and/or modify
062 *          it under the terms of the GNU Lesser General Public License as
063 *          published by the Free Software Foundation; either version 3 of the
064 *          License, or (at your option) any later version. <br>
065 * <br>
066 *          This library is distributed in the hope that it will be useful, but
067 *          WITHOUT ANY WARRANTY; without even the implied warranty of
068 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
069 *          Lesser General Public License for more details. <br>
070 * <br>
071 *          You should have received a copy of the GNU Lesser General Public
072 *          License along with this library; if not see
073 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
074 */
075public class SectionConflictTable extends AbstractStudentSectioningReport {
076    private static DecimalFormat sDF1 = new DecimalFormat("0.####");
077    private static DecimalFormat sDF2 = new DecimalFormat("0.0000");
078
079    private Type iType;
080    private boolean iOverlapsAllEnrollments = true;
081    private boolean iHigherPriorityConflictsOnly = false;
082    private Set<String> iPriorities;
083    
084    /**
085     * Report type
086     */
087    public static enum Type {
088        /** Time conflicts */
089        OVERLAPS(true, false),
090        /** Availability conflicts */
091        UNAVAILABILITIES(false, true),
092        /** Both time and availability conflicts */
093        OVERLAPS_AND_UNAVAILABILITIES(true, true),
094        ;
095        
096        boolean iOveralps, iUnavailabilities;
097        Type(boolean overlaps, boolean unavailabilities) {
098            iOveralps = overlaps;
099            iUnavailabilities = unavailabilities;
100        }
101        
102        /** Has time conflicts 
103         * @return include time conflicts
104         **/
105        public boolean hasOverlaps() { return iOveralps; }
106        
107        /** Has availability conflicts 
108         * @return include unavailabilities
109         **/
110        public boolean hasUnavailabilities() { return iUnavailabilities; }
111    }
112
113    /**
114     * Constructor
115     * 
116     * @param model
117     *            student sectioning model
118     * @param type report type
119     */
120    public SectionConflictTable(StudentSectioningModel model, Type type) {
121        super(model);
122        iType = type;
123    }
124    
125    public SectionConflictTable(StudentSectioningModel model) {
126        this(model, Type.OVERLAPS_AND_UNAVAILABILITIES);
127    }
128
129    private boolean canIgnore(Assignment<Request, Enrollment> assignment, Enrollment enrollment, Section section, List<Enrollment> other) {
130        e: for (Enrollment e: other) {
131            Section a = null;
132            for (Section s: e.getSections()) {
133                if (s.getSubpart().equals(section.getSubpart())) {
134                    if (s.equals(section)) continue e;
135                    a = s;
136                } else if (!enrollment.getSections().contains(s))
137                    continue e;
138            }
139            if (a == null) continue e;
140            for (Request r: enrollment.getStudent().getRequests()) {
141                Enrollment curr = assignment.getValue(r);
142                if (!enrollment.getRequest().equals(r) && curr != null && r instanceof CourseRequest && !curr.isAllowOverlap())
143                    for (Section b: curr.getSections())
144                        if (!b.isAllowOverlap() && !b.isToIgnoreStudentConflictsWith(section.getId()) && b.getTime() != null && a.getTime() != null && !a.isAllowOverlap() && b.getTime().hasIntersection(a.getTime()))
145                            continue e;
146            }
147            return true;
148        }
149        return false;
150    }
151
152    /**
153     * Create report
154     * 
155     * @param assignment current assignment
156     * @return report as comma separated text file
157     */
158    @Override
159    public CSVFile createTable(Assignment<Request, Enrollment> assignment, DataProperties properties) {
160        iType = Type.valueOf(properties.getProperty("type", iType.name()));
161        iOverlapsAllEnrollments = properties.getPropertyBoolean("overlapsIncludeAll", true);
162        iPriorities = new HashSet<String>();
163        for (String type: properties.getProperty("priority", "").split("\\,"))
164                if (!type.isEmpty())
165                    iPriorities.add(type);
166        iHigherPriorityConflictsOnly = !iPriorities.isEmpty();
167        
168        HashMap<Course, Map<Section, Double[]>> unavailabilities = new HashMap<Course, Map<Section,Double[]>>();
169        HashMap<Course, Set<Long>> totals = new HashMap<Course, Set<Long>>();
170        HashMap<CourseSection, Map<CourseSection, Double>> conflictingPairs = new HashMap<CourseSection, Map<CourseSection,Double>>();
171        HashMap<CourseSection, Double> sectionOverlaps = new HashMap<CourseSection, Double>();        
172        
173        for (Request request : new ArrayList<Request>(getModel().unassignedVariables(assignment))) {
174            if (!matches(request)) continue;
175            if (iPriorities != null && !iPriorities.isEmpty() && (request.getRequestPriority() == null || !iPriorities.contains(request.getRequestPriority().name()))) continue;
176            if (request instanceof CourseRequest) {
177                CourseRequest courseRequest = (CourseRequest) request;
178                if (courseRequest.getStudent().isComplete(assignment)) continue;
179                
180                List<Enrollment> values = courseRequest.values(assignment);
181
182                SectionLimit limitConstraint = null;
183                for (GlobalConstraint<Request, Enrollment> c: getModel().globalConstraints()) {
184                    if (c instanceof SectionLimit) {
185                        limitConstraint = (SectionLimit)c;
186                        break;
187                    }
188                }
189                if (limitConstraint == null) {
190                    limitConstraint = new SectionLimit(new DataProperties());
191                    limitConstraint.setModel(getModel());
192                }
193                List<Enrollment> notAvailableValues = new ArrayList<Enrollment>(values.size());
194                List<Enrollment> availableValues = new ArrayList<Enrollment>(values.size());
195                for (Enrollment enrollment : values) {
196                    if (limitConstraint.inConflict(assignment, enrollment))
197                        notAvailableValues.add(enrollment);
198                    else
199                        availableValues.add(enrollment); 
200                }
201                
202                if (!notAvailableValues.isEmpty() && iType.hasUnavailabilities()) {
203                    List<Enrollment> notOverlappingEnrollments = new ArrayList<Enrollment>(values.size());
204                    enrollments: for (Enrollment enrollment: notAvailableValues) {
205                        for (Request other : request.getStudent().getRequests()) {
206                            if (other.equals(request) || assignment.getValue(other) == null || other instanceof FreeTimeRequest) continue;
207                            if (iHigherPriorityConflictsOnly) {
208                                if (iPriorities != null && !iPriorities.isEmpty() && (other.getRequestPriority() == null || other.getRequestPriority().ordinal() > request.getRequestPriority().ordinal())) continue;
209                            } else {
210                                if (iPriorities != null && !iPriorities.isEmpty() && (other.getRequestPriority() == null || !iPriorities.contains(other.getRequestPriority().name()))) continue;
211                            }
212                            if (assignment.getValue(other).isOverlapping(enrollment)) continue enrollments;
213                        }
214                        // not overlapping
215                        notOverlappingEnrollments.add(enrollment);
216                    }
217                    
218                    if (notOverlappingEnrollments.isEmpty()  && availableValues.isEmpty() && iOverlapsAllEnrollments) {
219                        double fraction = request.getWeight() / notAvailableValues.size();
220                        Set<CourseSection> ones = new HashSet<CourseSection>();
221                        for (Enrollment enrollment: notAvailableValues) {
222                            boolean hasConflict = false;
223                            for (Section s: enrollment.getSections()) {
224                                if (s.getLimit() >= 0 && s.getEnrollmentWeight(assignment, request) + request.getWeight() > s.getLimit()) {
225                                    hasConflict = true;
226                                    break;
227                                }
228                            }
229                            
230                            Map<Section, Double[]> sections = unavailabilities.get(enrollment.getCourse());
231                            if (sections == null) {
232                                sections = new HashMap<Section, Double[]>();
233                                unavailabilities.put(enrollment.getCourse(), sections);
234                            }
235                            for (Section s: enrollment.getSections()) {
236                                if (hasConflict && s.getLimit() < 0 || s.getEnrollmentWeight(assignment, request) + request.getWeight() <= s.getLimit()) continue;
237                                Double[] total = sections.get(s);
238                                sections.put(s, new Double[] {
239                                            fraction + (total == null ? 0.0 : total[0].doubleValue()),
240                                            (total == null ? 0.0 : total[1].doubleValue())
241                                        });
242                                ones.add(new CourseSection(enrollment.getCourse(), s));
243                            }
244                            Set<Long> total = totals.get(enrollment.getCourse());
245                            if (total == null) {
246                                total = new HashSet<Long>();
247                                totals.put(enrollment.getCourse(), total);
248                            }
249                            total.add(enrollment.getStudent().getId());
250                        }
251                    } else if (!notOverlappingEnrollments.isEmpty()) {
252                        double fraction = request.getWeight() / notOverlappingEnrollments.size();
253                        Set<CourseSection> ones = new HashSet<CourseSection>();
254                        for (Enrollment enrollment: notOverlappingEnrollments) {
255                            boolean hasConflict = false;
256                            for (Section s: enrollment.getSections()) {
257                                if (s.getLimit() >= 0 && s.getEnrollmentWeight(assignment, request) + request.getWeight() > s.getLimit()) {
258                                    hasConflict = true;
259                                    break;
260                                }
261                            }
262                            
263                            Map<Section, Double[]> sections = unavailabilities.get(enrollment.getCourse());
264                            if (sections == null) {
265                                sections = new HashMap<Section, Double[]>();
266                                unavailabilities.put(enrollment.getCourse(), sections);
267                            }
268                            for (Section s: enrollment.getSections()) {
269                                if (hasConflict && s.getLimit() < 0 || s.getEnrollmentWeight(assignment, request) + request.getWeight() <= s.getLimit()) continue;
270                                Double[] total = sections.get(s);
271                                sections.put(s, new Double[] {
272                                            fraction + (total == null ? 0.0 : total[0].doubleValue()),
273                                            (total == null ? 0.0 : total[1].doubleValue())
274                                        });
275                                ones.add(new CourseSection(enrollment.getCourse(), s));
276                            }
277                            Set<Long> total = totals.get(enrollment.getCourse());
278                            if (total == null) {
279                                total = new HashSet<Long>();
280                                totals.put(enrollment.getCourse(), total);
281                            }
282                            total.add(enrollment.getStudent().getId());
283                        }
284                        for (CourseSection section: ones) {
285                            Map<Section, Double[]> sections = unavailabilities.get(section.getCourse());
286                            Double[] total = sections.get(section.getSection());
287                            sections.put(section.getSection(), new Double[] {
288                                    (total == null ? 0.0 : total[0].doubleValue()),
289                                    request.getWeight() + (total == null ? 0.0 : total[1].doubleValue())
290                                });
291                        }                        
292                    }
293                }
294                
295                if (iOverlapsAllEnrollments)
296                    availableValues = values;
297                if (!availableValues.isEmpty() && iType.hasOverlaps()) {
298                    List<Map<CourseSection, List<CourseSection>>> conflicts = new ArrayList<Map<CourseSection, List<CourseSection>>>();
299                    for (Enrollment enrollment: availableValues) {
300                        Map<CourseSection, List<CourseSection>> overlaps = new HashMap<CourseSection, List<CourseSection>>();
301                        for (Request other : request.getStudent().getRequests()) {
302                            Enrollment otherEnrollment = assignment.getValue(other);
303                            if (other.equals(request) || otherEnrollment == null || other instanceof FreeTimeRequest) continue;
304                            if (iHigherPriorityConflictsOnly) {
305                                if (iPriorities != null && !iPriorities.isEmpty() && (other.getRequestPriority() == null || other.getRequestPriority().ordinal() > request.getRequestPriority().ordinal())) continue;
306                            } else {
307                                if (iPriorities != null && !iPriorities.isEmpty() && (other.getRequestPriority() == null || !iPriorities.contains(other.getRequestPriority().name()))) continue;
308                            }
309                            if (enrollment.isOverlapping(otherEnrollment))
310                                for (Section a: enrollment.getSections())
311                                    for (Section b: otherEnrollment.getSections())
312                                        if (a.getTime() != null && b.getTime() != null && !a.isAllowOverlap() && !b.isAllowOverlap() && !a.isToIgnoreStudentConflictsWith(b.getId()) && a.getTime().hasIntersection(b.getTime()) && !canIgnore(assignment, enrollment, a, availableValues)) {
313                                            List<CourseSection> x = overlaps.get(new CourseSection(enrollment.getCourse(), a));
314                                            if (x == null) { x = new ArrayList<CourseSection>(); overlaps.put(new CourseSection(enrollment.getCourse(), a), x); }
315                                            x.add(new CourseSection(otherEnrollment.getCourse(), b));
316                                        }
317                        }
318                        if (!overlaps.isEmpty()) {
319                            conflicts.add(overlaps);
320                            Set<Long> total = totals.get(enrollment.getCourse());
321                            if (total == null) {
322                                total = new HashSet<Long>();
323                                totals.put(enrollment.getCourse(), total);
324                            }
325                            total.add(enrollment.getStudent().getId());
326                        }
327                    }
328                    
329                    double fraction = request.getWeight() / conflicts.size();
330                    for (Map<CourseSection, List<CourseSection>> overlaps: conflicts) {
331                        for (Map.Entry<CourseSection, List<CourseSection>> entry: overlaps.entrySet()) {
332                            CourseSection a = entry.getKey();
333                            Double total = sectionOverlaps.get(a);
334                            sectionOverlaps.put(a, fraction + (total == null ? 0.0 : total.doubleValue()));
335                            Map<CourseSection, Double> pair = conflictingPairs.get(a);
336                            if (pair == null) {
337                                pair = new HashMap<CourseSection, Double>();
338                                conflictingPairs.put(a, pair);
339                            }
340                            for (CourseSection b: entry.getValue()) {
341                                Double prev = pair.get(b);
342                                pair.put(b, fraction + (prev == null ? 0.0 : prev.doubleValue()));
343                            }
344                        }
345                    }
346                }
347            }
348        }
349        Comparator<Course> courseComparator = new Comparator<Course>() {
350            @Override
351            public int compare(Course a, Course b) {
352                int cmp = a.getName().compareTo(b.getName());
353                if (cmp != 0) return cmp;
354                return a.getId() < b.getId() ? -1 : a.getId() == b.getId() ? 0 : 1;
355            }
356        };
357        Comparator<Section> sectionComparator = new Comparator<Section>() {
358            @Override
359            public int compare(Section a, Section b) {
360                int cmp = a.getSubpart().getConfig().getOffering().getName().compareTo(b.getSubpart().getConfig().getOffering().getName());
361                if (cmp != 0) return cmp;
362                cmp = a.getSubpart().getInstructionalType().compareTo(b.getSubpart().getInstructionalType());
363                // if (cmp != 0) return cmp;
364                // cmp = a.getName().compareTo(b.getName());
365                if (cmp != 0) return cmp;
366                return a.getId() < b.getId() ? -1 : a.getId() == b.getId() ? 0 : 1;
367            }
368        };
369        
370        CSVFile csv = new CSVFile();
371        List<CSVFile.CSVField> headers = new ArrayList<CSVFile.CSVField>();
372        headers.add(new CSVFile.CSVField("Course"));
373        headers.add(new CSVFile.CSVField("Total\nConflicts"));
374        if (iType.hasUnavailabilities()) {
375            headers.add(new CSVFile.CSVField("Course\nEnrollment"));
376            headers.add(new CSVFile.CSVField("Course\nLimit"));
377        }
378        headers.add(new CSVFile.CSVField("Class"));
379        headers.add(new CSVFile.CSVField("Meeting Time"));
380        if (iType.hasUnavailabilities()) {
381            headers.add(new CSVFile.CSVField("Availability\nConflicts"));
382            headers.add(new CSVFile.CSVField("% of Total\nConflicts"));
383        }
384        if (iType.hasOverlaps()) {
385            headers.add(new CSVFile.CSVField("Time\nConflicts"));
386            headers.add(new CSVFile.CSVField("% of Total\nConflicts"));
387        }
388        if (iType.hasUnavailabilities()) {
389            headers.add(new CSVFile.CSVField("Class\nEnrollment"));
390            headers.add(new CSVFile.CSVField("Class\nLimit"));
391            if (!iType.hasOverlaps())
392                headers.add(new CSVFile.CSVField("Class\nPotential"));
393        }
394        if (iType.hasOverlaps()) {
395            headers.add(new CSVFile.CSVField("Conflicting\nClass"));
396            headers.add(new CSVFile.CSVField("Conflicting\nMeeting Time"));
397            headers.add(new CSVFile.CSVField("Joined\nConflicts"));
398            headers.add(new CSVFile.CSVField("% of Total\nConflicts"));
399        }
400        csv.setHeader(headers);
401        
402        TreeSet<Course> courses = new TreeSet<Course>(courseComparator);
403        courses.addAll(totals.keySet());
404        
405        for (Course course: courses) {
406            Map<Section, Double[]> sectionUnavailability = unavailabilities.get(course);
407            Set<Long> total = totals.get(course);
408            
409            TreeSet<Section> sections = new TreeSet<Section>(sectionComparator);
410            if (sectionUnavailability != null)
411                sections.addAll(sectionUnavailability.keySet());
412            for (Map.Entry<CourseSection, Double> entry: sectionOverlaps.entrySet())
413                if (course.equals(entry.getKey().getCourse()))
414                    sections.add(entry.getKey().getSection());
415            
416            boolean firstCourse = true;
417            for (Section section: sections) {
418                Double[] sectionUnavailable = (sectionUnavailability == null ? null : sectionUnavailability.get(section));
419                Double sectionOverlap = sectionOverlaps.get(new CourseSection(course, section));
420                Map<CourseSection, Double> pair = conflictingPairs.get(new CourseSection(course, section));
421                
422                if (pair == null) {
423                    List<CSVFile.CSVField> line = new ArrayList<CSVFile.CSVField>();
424                    line.add(new CSVFile.CSVField(firstCourse ? course.getName() : ""));
425                    line.add(new CSVFile.CSVField(firstCourse ? total.size() : ""));
426                    if (iType.hasUnavailabilities()) {
427                        line.add(new CSVFile.CSVField(firstCourse ? sDF1.format(course.getEnrollmentWeight(assignment, null)) : ""));
428                        line.add(new CSVFile.CSVField(firstCourse ? course.getLimit() < 0 ? "" : String.valueOf(course.getLimit()) : ""));
429                    }
430                    
431                    line.add(new CSVFile.CSVField(section.getSubpart().getName() + " " + section.getName(course.getId())));
432                    line.add(new CSVFile.CSVField(section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(isUseAmPm()) + " - " + section.getTime().getEndTimeHeader(isUseAmPm())));
433                    
434                    if (iType.hasUnavailabilities()) {
435                        line.add(new CSVFile.CSVField(sectionUnavailable != null ? sDF2.format(sectionUnavailable[0]) : ""));
436                        line.add(new CSVFile.CSVField(sectionUnavailable != null ? sDF2.format(sectionUnavailable[0] / total.size()) : ""));
437                    }
438                    if (iType.hasOverlaps()) {
439                        line.add(new CSVFile.CSVField(sectionOverlap != null ? sDF2.format(sectionOverlap) : ""));
440                        line.add(new CSVFile.CSVField(sectionOverlap != null ? sDF2.format(sectionOverlap / total.size()) : ""));
441                    }
442                    if (iType.hasUnavailabilities()) {
443                        line.add(new CSVFile.CSVField(sDF1.format(section.getEnrollmentWeight(assignment, null))));
444                        line.add(new CSVFile.CSVField(section.getLimit() < 0 ? "" : String.valueOf(section.getLimit())));
445                        if (!iType.hasOverlaps())
446                            line.add(new CSVFile.CSVField(sectionUnavailable != null ? sDF1.format(sectionUnavailable[1]) : ""));
447                    }
448                    
449                    csv.addLine(line);
450                } else {
451                    boolean firstClass = true;
452                    for (CourseSection other: new TreeSet<CourseSection>(pair.keySet())) {
453                        List<CSVFile.CSVField> line = new ArrayList<CSVFile.CSVField>();
454                        line.add(new CSVFile.CSVField(firstCourse && firstClass ? course.getName() : ""));
455                        line.add(new CSVFile.CSVField(firstCourse && firstClass ? total.size() : ""));
456                        if (iType.hasUnavailabilities()) {
457                            line.add(new CSVFile.CSVField(firstCourse && firstClass ? sDF1.format(course.getEnrollmentWeight(assignment, null)) : ""));
458                            line.add(new CSVFile.CSVField(firstCourse && firstClass ? course.getLimit() < 0 ? "" : String.valueOf(course.getLimit()) : ""));
459                        }
460                        
461                        line.add(new CSVFile.CSVField(firstClass ? section.getSubpart().getName() + " " + section.getName(course.getId()): ""));
462                        line.add(new CSVFile.CSVField(firstClass ? section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(isUseAmPm()) + " - " + section.getTime().getEndTimeHeader(isUseAmPm()): ""));
463                        
464                        if (iType.hasUnavailabilities()) {
465                            line.add(new CSVFile.CSVField(firstClass && sectionUnavailable != null ? sDF2.format(sectionUnavailable[0]): ""));
466                            line.add(new CSVFile.CSVField(sectionUnavailable != null ? sDF2.format(sectionUnavailable[0] / total.size()) : ""));
467                        }
468                        line.add(new CSVFile.CSVField(firstClass && sectionOverlap != null ? sDF2.format(sectionOverlap): ""));
469                        line.add(new CSVFile.CSVField(firstClass && sectionOverlap != null ? sDF2.format(sectionOverlap / total.size()) : ""));
470                        if (iType.hasUnavailabilities()) {
471                            line.add(new CSVFile.CSVField(firstClass ? sDF1.format(section.getEnrollmentWeight(assignment, null)): ""));
472                            line.add(new CSVFile.CSVField(firstClass ? section.getLimit() < 0 ? "" : String.valueOf(section.getLimit()): ""));
473                        }
474                        
475                        line.add(new CSVFile.CSVField(other.getCourse().getName() + " " + other.getSection().getSubpart().getName() + " " + other.getSection().getName(other.getCourse().getId())));
476                        line.add(new CSVFile.CSVField(other.getSection().getTime().getDayHeader() + " " + other.getSection().getTime().getStartTimeHeader(isUseAmPm()) + " - " + other.getSection().getTime().getEndTimeHeader(isUseAmPm())));
477                        line.add(new CSVFile.CSVField(sDF2.format(pair.get(other))));
478                        line.add(new CSVFile.CSVField(sDF2.format(pair.get(other) / total.size())));
479                        
480                        csv.addLine(line);
481                        firstClass = false;
482                    }                    
483                }
484                
485                firstCourse = false;
486            }
487            
488            csv.addLine();
489        }
490        return csv;
491    }
492}