コード例 #1
0
ファイル: group.py プロジェクト: ucamhal/timetables
 def best_template(self):
     gt = GroupTemplate(None,self.term)
     for e in self.elements:
         gt.add_patterns(e.when,e)
     gt.calculate_reduction()
     gt.restrict_to_term(self.term)
     return gt
コード例 #2
0
ファイル: details.py プロジェクト: ucamhal/timetables
 def from_json(data):
     out = Details(data['id'],data['name'],data['organiser'],data['where'],data['metadata'])
     for g in data['groups']:
         term = Details.termindex[g['term']]
         group = GroupTemplate(g['code'],term)
         Details._add_rows_from_group_json(out,g,group,data['name'])
     return out
コード例 #3
0
ファイル: year.py プロジェクト: ucamhal/timetables
 def to_templated_secular_display(self, fp, group, type='lecture'):
     gt = GroupTemplate(None)
     gt.add_patterns(fp)
     gt.calculate_reduction(True)
     out = []
     for (_, _, (pattern, mult)) in gt.get_patterns_raw(False):
         if pattern is None:
             # just multiplier, should be just "x lectures"
             row = "%d %s, %s" % (mult, util.plural(type), gt.template
                                  )  # XXX proper plurals
         elif mult is None:
             # traditional pattern, expand codes sensibly
             row = "%s %s" % (util.plural(type),
                              self.atoms_to_secular(fp.patterns(), True))
         else:
             # start date and multiplier
             pp = copy.deepcopy(gt.template)
             pp.setAllYear()
             row = "%s %s, starting on %s, %s" % (mult, util.plural(type),
                                                  self.atoms_to_secular(
                                                      [pattern], False), pp)
         out.append(row)
     prefix = ''
     if group is not None:
         prefix = "%s term, " % term_names[group.term]
     return prefix + ", ".join(out)
コード例 #4
0
ファイル: year.py プロジェクト: ieb/timetables
 def to_templated_secular_display(self,fp,group,type= 'lecture'):
     gt = GroupTemplate(None)
     gt.add_patterns(fp)
     gt.calculate_reduction(True)
     out = []
     for (_,_,(pattern,mult)) in gt.get_patterns_raw(False):
         if pattern is None:
             # just multiplier, should be just "x lectures"
             row = "%d %s, %s" % (mult,util.plural(type),gt.template) # XXX proper plurals
         elif mult is None:
             # traditional pattern, expand codes sensibly
             row = "%s %s" % (util.plural(type),self.atoms_to_secular(fp.patterns(),True))
         else:
             # start date and multiplier
             pp = copy.deepcopy(gt.template)
             pp.setAllYear()
             row = "%s %s, starting on %s, %s" % (mult,util.plural(type),self.atoms_to_secular([pattern],False),pp)
         out.append(row)
     prefix = ''
     if group is not None:
         prefix = "%s term, " % term_names[group.term]
     return prefix+", ".join(out)
コード例 #5
0
ファイル: pparser.py プロジェクト: ucamhal/timetables
            out.addAll(p)
        return out
        
    def parse(self):
        (base,mult,implicit) = self._p.parse_full()
        if mult is not None and self._group is not None:
            if implicit:
                base = self._group.last()
            return self._apply(base,mult)        
        else:
            out = fullpattern.FullPattern(base)
            if self._group is not None:
                self._group.track_pattern(out)
            return out

def fullparse(text,template = None):    
    return FullParser(text,group = template).parse()
        
def parseone(text):
    return AtomParser(text).parse_template()
  
# XXX compact patterns generation from pattern list    
if __name__ == '__main__' and False:
    from grouptemplate import GroupTemplate
    
    g = GroupTemplate("TuThSa12")
    p = fullparse("Mi1 Tu12 x4",g)
    g.add_patterns(p)
    print p.format(group = g)
    print g.get_patterns()