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