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