PyScore

001: # -*- python -*-
002: #### populate.py #### python package PyScore.tabulate module populate ####
003: 
004: # PyScore
005: # a race scoring programme
006: # written by Matt Draisey
007: # 2004 April 6
008: 
009: reloadables=[]
010: 
011: #### populate.py #### python package PyScore.tabulate module populate ####
012: 
013: from tabulate import racesheet,scoresheet,printsheet,database
014: from utility.verbose import vv,vvv,vvvv,debug
015: 
016: ######## ######## the overall database ######## ########
017: 
018: class Population(database.DataBase):
019: 
020:     def tabulate_all(self):
021:         super(Population,self).tabulate_all()
022: 
023:         print>>vv,"TABULATION COMPLETE"
024:         print>>vv
025: 
026:     def xtabulate_all_races(self):
027:         super(Population,self).tabulate_all_races()
028: 
029:     def tabulate_all_series(self):
030:         super(Population,self).tabulate_all_series()
031: 
032:         print_last_race_only=True
033:         #print_last_race_only=False
034:         races=database.sheetbase.racesheet.values()
035: 
036:         if not len(races):
037:             print>>vv
038:             print>>vv,"NO RACES SAILED"
039:             print>>vv
040: 
041:         elif print_last_race_only:
042:             racename=max(races).racename
043:             print>>vv
044:             print>>vv,"NUMBER OF RACES SAILED: ",len(races)
045:             print>>vv,"LAST RACE SAILED: ",racename
046:             print>>vv
047: 
048:             racesheet.apply_to_race_named(
049:                print_stuff_in_race,
050:                racename,database.sheetbase.handicapsheet,
051:             )
052:             racesheet.apply_to_race_named(
053:                print_rc_in_race,
054:                racename,database.sheetbase.rcsheet,
055:             )
056:         else:
057:             print>>vv
058:             print>>vv,"NUMBER OF RACES SAILED: ",len(races)
059:             print>>vv,"ALL RACES:"
060:             print>>vv
061: 
062:             racesheet.apply_to_all_races(
063:                print_stuff_in_race,
064:                database.sheetbase.handicapsheet,
065:             )
066:             racesheet.apply_to_all_races(
067:                print_rc_in_race,
068:                database.sheetbase.rcsheet,
069:             )
070: 
071:         print_last_series_only=True
072:         #print_last_series_only=False
073:         series=database.seriesbase.seriestab.values()
074: 
075:         if not len(series):
076:             print>>vv
077:             print>>vv,"NO SERIES STARTED"
078:             print>>vv
079: 
080:         elif print_last_series_only:
081:             seriesname=max(series).seriesname
082:             print>>vv
083:             print>>vv,"CURRENT SERIES: ",seriesname
084:             print>>vv
085: 
086:             scoresheet.apply_to_series_named(
087:                print_stuff_in_series,
088:                seriesname,database.seriesbase.seriesscoretab,
089:             )
090:         else:
091:             print>>vv
092:             print>>vv,"ALL SERIES:"
093:             print>>vv
094: 
095:             scoresheet.apply_to_all_series(
096:                print_stuff_in_series,
097:                database.seriesbase.seriesscoretab,
098:             )
099: 
100:     def xtabulate_all_championship(self):
101:         super(Population,self).tabulate_all_championship()
102: 
103:         printsheet.print_championship_scoresheet_in_fleet(
104:             self.championshipbase.championship,
105:             self.championshipbase.championshipscoretab,
106:         )
107: 
108:     def xtabulate_all_casual(self):
109:         super(Population,self).tabulate_all_casual()
110:         
111:         printsheet.print_midfleet_scoresheet(
112:             self.casualbase.casual,
113:             self.casualbase.midfleetscoretab,
114:         )
115: 
116: ######## ######## populate the overall database ######## ########
117: 
118: class OutWriter:
119:     def __init__(self,stream=None):
120:         if stream:
121:             def write(self,p): print>>stream,p,
122:             self.write=write
123:         else:
124:             self.write=lambda p: None
125: 
126: def print_stuff_in_race(race,handicapsheet,*p,**pp):
127:     """Printing per race."""
128:     #printsheet.print_scratches(race,handicapsheet,*p,**pp)
129:     #printsheet.print_handicapsheet(race,handicapsheet,*p,**pp)
130:     printsheet.print_casual_handicapsheet(race,handicapsheet,*p,**pp)
131:     printsheet.print_handicapsheet_weirdness(race,handicapsheet,*p,**pp)
132: 
133: def print_rc_in_race(race,rcsheet,*p,**pp):
134:     """RC stuff per race."""
135:     printsheet.print_rc(race,rcsheet,*p,**pp)
136: 
137: def print_stuff_in_series(series,scoretab,*p,**pp):
138:     """Printing per series."""
139:     printsheet.print_series_scoresheet_in_fleet(series,scoretab,*p,**pp)
140: 
141: database=Population()
142: 
143: def populate(sheetdir):
144:     database.import_all_timesheets(sheetdir)
145: 
146:     database.tabulate_all()
147: 
148: #### populate.py #### python package PyScore.tabulate module populate ####