def __init__(self,template): self._daytimes = [] self._termweeks = TermWeek() self._template = template # currently unused, but should be useful in reducing confusion in this class re omissions
def __init__(self, template): self._daytimes = [] self._termweeks = TermWeek() self._template = template # currently unused, but should be useful in reducing confusion in this class re omissions
class PatternAtom(object): dayname = ['M','Tu','W','Th','F','Sa','Su'] terms = ['Mi','Le','Ea'] def __init__(self,template): self._daytimes = [] self._termweeks = TermWeek() self._template = template # currently unused, but should be useful in reducing confusion in this class re omissions def addTermWeek(self,term,week): self._termweeks.addTermWeek(term,week) def addDayTimeRange(self,dy,fh,fm,th,tm): self._daytimes.append(DayTimeRange(dy,fh,fm,th,tm)) def addDayTimeRangeDirect(self,c): self._daytimes.append(c) def getDayTimesRaw(self): return self._daytimes def getTermWeeks(self): return self._termweeks def getTerms(self): return self._termweeks.getTerms() def restrictToTerm(self,t): self._termweeks.restrictToTerm(t) def copyRestrictedToTerm(self,term): out = copy(self) out._termweeks = self._termweeks.copyRestrictedToTerm(term) return out def restrictToDayTimeRange(self,dy,fh,fm,th,tm): r = DayTimeRange(dy,fh,fm,th,tm) out = [] for dt in self._daytimes: if dt.intersect_test(r): out.append(dt) self._daytimes = out def removeDayTimeRangeDirect(self,target): hit = target in self._daytimes self._daytimes = filter(lambda x: x != target,self._daytimes) return hit def addTermWeeksFrom(self,src): self._termweeks.merge(src._termweeks) def addDayTimesFrom(self,src): self._daytimes.extend(deepcopy(src._daytimes)) def setAllYear(self): self._termweeks.set_all() def setAllInTerm(self,term): self._termweeks.set_all_in_term(term) def empty(self): if len(self._daytimes) == 0: return True return not len(self._termweeks) def firstDayTime(self): return min(self._daytimes) def firstTermWeek(self): return self._termweeks.first() def lastDayTime(self): return max(self._daytimes) def key(self): (first_term,first_week) = self._termweeks.first() day = set([x.day for x in self._daytimes]) first_day = min([(x+4)%7 for x in day]) m_day = (first_day+3)%7 min_time = set() for d in [x for x in self._daytimes if x.day == m_day]: min_time.add(d.startval()) if len(min_time): min_time = min(min_time) else: min_time = 0 return "%1.1d%2.2d%1.1d%4.4d" % (first_term,first_week,first_day,min_time) def merge(self,other): # If dts are equivalent, can merge tws if set(self._daytimes) == set(other._daytimes): # Merge tws out = deepcopy(self) out._termweeks.merge(other._termweeks) return out # If tws are equivalent, can merge dts if self._termweeks == other._termweeks: out = deepcopy(self) out._daytimes.extend(deepcopy(other._daytimes)) return out return None def _after(self,(term,week),cur): x = util.successor(self._daytimes,cur) if x is None: (term,week) = self._termweeks.successor(term,week) if term is None and week is None: return None return ((term,week),self.firstDayTime()) else: return ((term,week),x)
class PatternAtom(object): dayname = ['M', 'Tu', 'W', 'Th', 'F', 'Sa', 'Su'] terms = ['Mi', 'Le', 'Ea'] def __init__(self, template): self._daytimes = [] self._termweeks = TermWeek() self._template = template # currently unused, but should be useful in reducing confusion in this class re omissions def addTermWeek(self, term, week): self._termweeks.addTermWeek(term, week) def addDayTimeRange(self, dy, fh, fm, th, tm): self._daytimes.append(DayTimeRange(dy, fh, fm, th, tm)) def addDayTimeRangeDirect(self, c): self._daytimes.append(c) def getDayTimesRaw(self): return self._daytimes def getTermWeeks(self): return self._termweeks def getTerms(self): return self._termweeks.getTerms() def restrictToTerm(self, t): self._termweeks.restrictToTerm(t) def copyRestrictedToTerm(self, term): out = copy(self) out._termweeks = self._termweeks.copyRestrictedToTerm(term) return out def restrictToDayTimeRange(self, dy, fh, fm, th, tm): r = DayTimeRange(dy, fh, fm, th, tm) out = [] for dt in self._daytimes: if dt.intersect_test(r): out.append(dt) self._daytimes = out def removeDayTimeRangeDirect(self, target): hit = target in self._daytimes self._daytimes = filter(lambda x: x != target, self._daytimes) return hit def addTermWeeksFrom(self, src): self._termweeks.merge(src._termweeks) def addDayTimesFrom(self, src): self._daytimes.extend(deepcopy(src._daytimes)) def setAllYear(self): self._termweeks.set_all() def setAllInTerm(self, term): self._termweeks.set_all_in_term(term) def empty(self): if len(self._daytimes) == 0: return True return not len(self._termweeks) def firstDayTime(self): return min(self._daytimes) def firstTermWeek(self): return self._termweeks.first() def lastDayTime(self): return max(self._daytimes) def key(self): (first_term, first_week) = self._termweeks.first() day = set([x.day for x in self._daytimes]) first_day = min([(x + 4) % 7 for x in day]) m_day = (first_day + 3) % 7 min_time = set() for d in [x for x in self._daytimes if x.day == m_day]: min_time.add(d.startval()) if len(min_time): min_time = min(min_time) else: min_time = 0 return "%1.1d%2.2d%1.1d%4.4d" % (first_term, first_week, first_day, min_time) def merge(self, other): # If dts are equivalent, can merge tws if set(self._daytimes) == set(other._daytimes): # Merge tws out = deepcopy(self) out._termweeks.merge(other._termweeks) return out # If tws are equivalent, can merge dts if self._termweeks == other._termweeks: out = deepcopy(self) out._daytimes.extend(deepcopy(other._daytimes)) return out return None def _after(self, (term, week), cur): x = util.successor(self._daytimes, cur) if x is None: (term, week) = self._termweeks.successor(term, week) if term is None and week is None: return None return ((term, week), self.firstDayTime()) else: return ((term, week), x)