// add all of the course durations together on given days, call it idealdur, and then find the diff between the earliest // start and latest end, call it actualdur, and for every hour the actualdur is greater than the idealdur, subtract 1 from 10 public void calcSmGapWeight(double mult) { double avg = 0; string daysWithSections = ""; // create an array that represents the days of the week, and fill those spots with dayinfo class objects dayinfo[] weekdays = new dayinfo[7]; for (int i = 0; i < 7; i++) weekdays[i] = new dayinfo(); foreach (Section sect in this.courses) { if (sect.days != "NULL") { foreach (char day in sect.days) { // keep track of which days need to be considered daysWithSections = new string((daysWithSections + day.ToString()).Distinct().ToArray()); dayinfo info = weekdays[daysToIndices[day]]; if (sect.startTime < info.minstart) info.minstart = sect.startTime; if (sect.endTime > info.maxend) info.maxend = sect.endTime; info.idealspan += (sect.endTime - sect.startTime).TotalHours; weekdays[daysToIndices[day]] = info; } } } // now calculate the actualspan and find the difference for each day needed foreach (char day in daysWithSections) { dayinfo info = weekdays[daysToIndices[day]]; info.actualspan = (info.maxend - info.minstart).TotalHours; info.diff = info.actualspan - info.idealspan; avg += info.diff; } // take the average across all of the days with sections avg = avg / daysWithSections.Length; total_weight += (10 - avg) * mult; }
// 17 hour span between 6am and 11pm. Idealspan = 17, actual span is still the span between the earliest start and // latest end times on that specific day. just one class during a day? should give 10. public void calcLgGapWeight(double mult) { double avg = 0; string daysWithSections = ""; // create an array that represents the days of the week, and fill those spots with dayinfo class objects dayinfo[] weekdays = new dayinfo[7]; for (int i = 0; i < 7; i++) weekdays[i] = new dayinfo(); foreach (Section sect in this.courses) { if (sect.days != "NULL") { foreach (char day in sect.days) { // keep track of which days need to be considered daysWithSections = new string((daysWithSections + day.ToString()).Distinct().ToArray()); dayinfo info = weekdays[daysToIndices[day]]; info.numClasses++; if (sect.startTime < info.minstart) info.minstart = sect.startTime; if (sect.endTime > info.maxend) info.maxend = sect.endTime; info.idealspan += (sect.endTime - sect.startTime).TotalHours; weekdays[daysToIndices[day]] = info; } } } // now calculate the actualspan and find the difference for each day needed foreach (char day in daysWithSections) { dayinfo info = weekdays[daysToIndices[day]]; // if there is only one day, the gap is infinite, so give it a perfect weight if (info.numClasses == 1) avg += 10; else { info.actualspan = (info.maxend - info.minstart).TotalHours; // actual span is always >= idealspan. ideal must be at least 2, actual best case is 17. // 17-2 = 15-5 = 10 which is the perfect scenario. info.diff = (info.actualspan - info.idealspan) - 5; avg += info.diff; } } // take the average across all of the days with sections avg = avg / daysWithSections.Length; total_weight += avg * mult; }