Beispiel #1
0
 def build_days(self,days,timestr):
     # merge days by term/week
     inweek = collections.defaultdict(set)
     for (term,week,day) in days:
         inweek[(term,week)].add(day_names[day])
     # flip the map around so index is by day set
     outweek = collections.defaultdict(set)
     for ((term,week),days) in inweek.iteritems():
         daystr = "".join(sorted(list(days),reverse=True))
         outweek[daystr].add((term,week))
     # For each day combination build term/week specs
     twout = collections.defaultdict(str)
     for (daystr,termweeks) in outweek.iteritems():
         for term in range(0,3):
             weeks = set()
             for (term2,week) in termweeks:
                 if term == term2:
                     weeks.add(week)
             if len(weeks):
                 week_str = util.number_range_text(weeks)
                 twout[int(term)*100+int(min(weeks))] += "%s%s %s" % (term_names[term],week_str,daystr)
     out = FullPattern()
     for k in sorted(twout.keys()):
         out.addOne("%s%s" % (twout[k],timestr))
     return out
Beispiel #2
0
 def _format_termweeks(self,reduction):
     if reduction is not None and  self._termweeks == reduction._termweeks:
         return ""
     out = []
     if not self._termweeks.all_weeks_of_year_test():
         for term in self._termweeks.each_term():
             weeks = self._termweeks.weeks_of_term(term)
             if self._termweeks.all_weeks_of_term_test(term):
                 s = ''
             else:
                 s = util.number_range_text(weeks)
             out.append("%s%s" % (self.terms[term],s))
     return " ".join(out)
 def _format_termweeks(self, reduction):
     if reduction is not None and self._termweeks == reduction._termweeks:
         return ""
     out = []
     if not self._termweeks.all_weeks_of_year_test():
         for term in self._termweeks.each_term():
             weeks = self._termweeks.weeks_of_term(term)
             if self._termweeks.all_weeks_of_term_test(term):
                 s = ''
             else:
                 s = util.number_range_text(weeks)
             out.append("%s%s" % (self.terms[term], s))
     return " ".join(out)
Beispiel #4
0
 def _format_daytimes(self,reduction):
     if reduction is not None and set(reduction._daytimes) == set(self._daytimes):
         return ""
     # collate by time
     daysbytime = collections.defaultdict(set)
     for dt in self._daytimes:
         (day,time) = dt.rep2()
         daysbytime[time].add(day)
     # sort by time. For now we only care about stability, should also care about sensibleness XXX
     keys = sorted(daysbytime.keys())
     # emit    
     out = []
     for time in keys:
         days = daysbytime[time]
         out.append(util.hide_commas(util.number_range_text(days,self.dayname)))
         out.append(time)
     return " ".join(out)
 def _format_daytimes(self, reduction):
     if reduction is not None and set(reduction._daytimes) == set(
             self._daytimes):
         return ""
     # collate by time
     daysbytime = collections.defaultdict(set)
     for dt in self._daytimes:
         (day, time) = dt.rep2()
         daysbytime[time].add(day)
     # sort by time. For now we only care about stability, should also care about sensibleness XXX
     keys = sorted(daysbytime.keys())
     # emit
     out = []
     for time in keys:
         days = daysbytime[time]
         out.append(
             util.hide_commas(util.number_range_text(days, self.dayname)))
         out.append(time)
     return " ".join(out)