def prepareGrid( self, page ): showLapTimes = (not Model.race) or getattr( Model.race, 'includeLapTimesInPrintout', True ) with UnstartedRaceWrapper(): if self.pageInfo[page][0] == 'Primes': exportGrid = ExportGrid( **Primes.GetGrid() ) else: exportGrid = ExportGrid() exportGrid.setResultsOneList( self.pageInfo[page][0], True, showLapTimes=showLapTimes ) return exportGrid
def prepareGrid( self, page ): exportGrid = ExportGrid() try: with UnstartedRaceWrapper(): if self.pageInfo[page][0] == 'Primes': exportGrid = ExportGrid( **Primes.GetGrid() ) else: exportGrid.setResultsOneList( self.pageInfo[page][0], True, showLapTimes=False ) except KeyError: return ExportGrid() exportGrid.title = u'\n'.join( [_('Podium Results'), u'', exportGrid.title] ) return exportGrid
def prepareGrid(self, page): exportGrid = ExportGrid() try: with UnstartedRaceWrapper(): if self.pageInfo[page][0] == 'Primes': exportGrid = ExportGrid(**Primes.GetGrid()) else: exportGrid.setResultsOneList(self.pageInfo[page][0], True, showLapTimes=False) except KeyError: return ExportGrid() exportGrid.title = u'\n'.join( [_('Podium Results'), u'', exportGrid.title]) return exportGrid
def prepareGrid(self, page): showLapTimes = (not Model.race) or getattr( Model.race, 'includeLapTimesInPrintout', True) try: with UnstartedRaceWrapper(): if self.pageInfo[page][0] == 'Primes': exportGrid = ExportGrid(**Primes.GetGrid()) else: exportGrid = ExportGrid() exportGrid.setResultsOneList(self.pageInfo[page][0], True, showLapTimes=showLapTimes) except KeyError: return ExportGrid() return exportGrid
def refresh( self ): self.category = None self.isEmpty = True self.iLastLap = 0 self.rcInterp = set() # Set of row/col coordinates of interpolated numbers. self.rcNumTime = set() self.search.SelectAll() CloseFinishTime = 0.07 self.closeFinishBibs = defaultdict( list ) race = Model.race if not race: self.clearGrid() return category = FixCategories( self.categoryChoice, getattr(race, 'resultsCategory', 0) ) self.hbs.RecalcSizes() self.hbs.Layout() for si in self.hbs.GetChildren(): if si.IsWindow(): si.GetWindow().Refresh() self.category = category sortLap = getattr( race, 'sortLap', None ) sortLabel = getattr( race, 'sortLabel', None ) if race.isTimeTrial: def getSortTime( rr ): try: return rr.firstTime + rr._lastTimeOrig except: return 0 else: def getSortTime( rr ): try: return rr._lastTimeOrig except: return 0 results = sorted( (rr for rr in GetResults(category) if rr.status==Model.Rider.Finisher and rr.lapTimes and getSortTime(rr) > 0), key = getSortTime ) for i in xrange(1, len(results)): if results[i]._lastTimeOrig - results[i-1]._lastTimeOrig <= CloseFinishTime: self.closeFinishBibs[results[i-1].num].append( results[i].num ) self.closeFinishBibs[results[i].num].append( results[i-1].num ) labelLastX, labelLastY = self.labelGrid.GetViewStart() lapLastX, lapLastY = self.lapGrid.GetViewStart() exportGrid = ExportGrid() exportGrid.setResultsOneList( category, self.showRiderData, showLapsFrequency = 1 ) if not exportGrid.colnames: self.clearGrid() return # Fix the speed column. speedUnit = None iSpeedCol = None try: iSpeedCol = (i for i, c in enumerate(exportGrid.colnames) if c == _('Speed')).next() except StopIteration: pass if iSpeedCol is not None: for r, d in enumerate(exportGrid.data[iSpeedCol]): d = d.strip() if not d: continue dSplit = d.split() if not speedUnit and len(dSplit) > 1: exportGrid.colnames[iSpeedCol] = speedUnit = dSplit[1] exportGrid.data[iSpeedCol][r] = dSplit[0] if exportGrid.data[iSpeedCol][r] == '"': exportGrid.data[iSpeedCol][r] += ' ' colnames = exportGrid.colnames data = exportGrid.data sortCol = None if sortLap: race.sortLabel = sortLabel = None for i, name in enumerate(colnames): if name.startswith(_('Lap')) and int(name.split()[1]) == sortLap: sortCol = i break elif sortLabel: race.sortLap = sortLap = None if sortLabel not in {_('Pos'), _('Gap'), _('Time'), _('mph'), _('km/h')}: for i, name in enumerate(colnames): if name == sortLabel: sortCol = i break if sortCol is None: race.sortLabel = race.sortLap = sortLabel = sortLap = None results = GetResults( category ) hasSpeeds = False for result in results: if getattr(result, 'lapSpeeds', None) or getattr(result, 'raceSpeeds', None): hasSpeeds = True break if not hasSpeeds: self.showLapSpeedsRadio.Enable( False ) self.showRaceSpeedsRadio.Enable( False ) if self.selectDisplay > Results.DisplayRaceTimes: self.selectDisplay = Results.DisplayRaceTimes self.showRaceTimesRadio.SetValue( True ) else: self.showLapSpeedsRadio.Enable( True ) self.showRaceSpeedsRadio.Enable( True ) for r in [self.showLapTimesRadio, self.showRaceTimesRadio, self.showLapSpeedsRadio, self.showRaceSpeedsRadio]: if r.GetValue(): r.SetFont( self.boldFont ) else: r.SetFont( wx.NullFont ) self.hbs.RecalcSizes() self.hbs.Layout() # Find the fastest lap time. self.fastestLapRC, fastestLapSpeed, fastestLapTime = None, 0.0, sys.float_info.max for r, result in enumerate(results): if getattr(result, 'lapSpeeds', None): # Use speeds if available. for c, s in enumerate(result.lapSpeeds): if s > fastestLapSpeed: fastestLapSpeed = s self.fastestLapRC = (r, c) elif result.lapTimes: # Else, use times. for c, t in enumerate(result.lapTimes): if t < fastestLapTime: fastestLapTime = t self.fastestLapRC = (r, c) highPrecision = Model.highPrecisionTimes() try: firstLapCol = (i for i, name in enumerate(colnames) if name.startswith(_('Lap'))).next() except StopIteration: firstLapCol = len(colnames) # Convert to race times, lap speeds or race speeds as required. ''' DisplayLapTimes = 0 DisplayRaceTimes = 1 DisplayLapSpeeds = 2 DisplayRaceSpeeds = 3 ''' if self.selectDisplay == Results.DisplayRaceTimes: for r, result in enumerate(results): for i, t in enumerate(result.raceTimes[1:]): try: data[i+firstLapCol][r] = Utils.formatTimeCompressed(t, highPrecision) except IndexError: pass elif self.selectDisplay == Results.DisplayLapSpeeds: for r, result in enumerate(results): if getattr(result, 'lapSpeeds', None): for i, s in enumerate(result.lapSpeeds): try: data[i+firstLapCol][r] = u'{:.2f}'.format(s) except IndexError: pass elif self.selectDisplay == Results.DisplayRaceSpeeds: for r, result in enumerate(results): if getattr(result, 'raceSpeeds', None): for i, s in enumerate(result.raceSpeeds): try: data[i+firstLapCol][r] = u'{:.2f}'.format(s) except IndexError: pass # Sort by the given lap, if there is one. # Also, add a position for the lap itself. if sortCol is not None: maxVal = 1000.0*24.0*60.0*60.0 if sortLap: if self.selectDisplay in [Results.DisplayLapTimes, Results.DisplayRaceTimes]: getFunc = Utils.StrToSeconds else: getFunc = lambda x: -float(x) else: if colnames[sortCol] in [_('Start'), _('Finish'), _('Time')]: getFunc = Utils.StrToSeconds elif colnames[sortCol] in [_('mph'), _('km')]: getFunc = lambda x: -float(x) if x else 0.0 elif colnames[sortCol] == _('Factor'): getFunc = lambda x: float(x) if x else maxVal elif colnames[sortCol] in [_('Pos'), _('Bib')]: getFunc = lambda x: int(x) if x and unicode(x).isdigit() else maxVal else: getFunc = lambda x: u'{}'.format(x) maxVal = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' sortPairs = [] for r, result in enumerate(results): try: k = (getFunc(data[sortCol][r]), r) except Exception as e: k = (maxVal, r) sortPairs.append( (k, r) ) sortPairs.sort() for c in xrange(len(data)): col = data[c] data[c] = [col[i] if i < len(col) else u'' for k, i in sortPairs] if colnames[sortCol] != _('Bib'): for r in xrange(len(data[sortCol])): if data[sortCol][r]: data[sortCol][r] = u'{} [{}: {}]'.format(data[sortCol][r], r+1, data[1][r]) # Highlight the sorted column. if sortLap: colnames = [] for name in exportGrid.colnames: try: if int(name.split()[1]) == sortLap: name = u'<{}>\n{}'.format(name, [_('by Lap Time'), _('by Race Time'), _('by Lap Speed'), _('by Race Speed')][self.selectDisplay]) except: pass colnames.append( name ) elif sortLabel: colnames = [] for name in exportGrid.colnames: if name == sortLabel: name = u'<{}>'.format(name) colnames.append( name ) else: colnames = exportGrid.colnames try: iLabelMax = (i for i, name in enumerate(colnames) if name.startswith(_('Lap')) or name.startswith('<' + _('Lap'))).next() except StopIteration: iLabelMax = len(colnames) colnamesLabels = colnames[:iLabelMax] dataLabels = data[:iLabelMax] colnameLaps = colnames[iLabelMax:] dataLaps = data[iLabelMax:] self.labelGrid.Set( data = dataLabels, colnames = colnamesLabels ) self.labelGrid.SetLeftAlignCols( exportGrid.leftJustifyCols ) self.labelGrid.AutoSizeColumns( True ) self.labelGrid.Reset() try: iUCICodeCol = colnamesLabels.index( _('UCICode') ) self.labelGrid.SetColRenderer( iUCICodeCol, IOCCodeRenderer() ) except ValueError: pass try: iNatCodeCol = colnamesLabels.index( _('NatCode') ) self.labelGrid.SetColRenderer( iNatCodeCol, IOCCodeRenderer() ) except ValueError: pass self.lapGrid.Set( data = dataLaps, colnames = colnameLaps ) self.lapGrid.Reset() self.lapGrid.AutoSizeColumns( self.lapGrid.GetNumberCols() < 100 ) self.isEmpty = False # Find interpolated entries. with Model.LockRace() as race: numTimeInfo = race.numTimeInfo riders = race.riders for r in xrange(self.lapGrid.GetNumberRows()): try: rider = riders[int(self.labelGrid.GetCellValue(r, 1))] except: continue try: entries = rider.interpolate() except (ValueError, IndexError): continue if not entries: continue for c in xrange(self.lapGrid.GetNumberCols()): if not self.lapGrid.GetCellValue(r, c): break try: if entries[c+1].interp: self.rcInterp.add( (r, c) ) elif numTimeInfo.getInfo(entries[c+1].num, entries[c+1].t) is not None: self.rcNumTime.add( (r, c) ) elif c > self.iLastLap: self.iLastLap = c except IndexError: pass self.labelGrid.Scroll( labelLastX, labelLastY ) self.lapGrid.Scroll( lapLastX, lapLastY ) self.showNumSelect() if self.firstDraw: self.firstDraw = False self.splitter.SetSashPosition( 400 ) # Fix the grids' scrollbars. self.labelGrid.FitInside() self.lapGrid.FitInside()
def prepareGrid( self, page ): exportGrid = ExportGrid() with UnstartedRaceWrapper(): exportGrid.setResultsOneList( self.pageInfo[page][0], True, showLapTimes=False ) exportGrid.title = u'\n'.join( [_('Podium Results'), u'', exportGrid.title] ) return exportGrid
def refresh(self): self.category = None self.isEmpty = True self.iLastLap = 0 self.rcInterp = set( ) # Set of row/col coordinates of interpolated numbers. self.rcNumTime = set() self.search.SelectAll() CloseFinishTime = 0.07 self.closeFinishBibs = defaultdict(list) race = Model.race if not race: self.clearGrid() return category = FixCategories(self.categoryChoice, getattr(race, 'resultsCategory', 0)) self.hbs.RecalcSizes() self.hbs.Layout() for si in self.hbs.GetChildren(): if si.IsWindow(): si.GetWindow().Refresh() self.category = category sortLap = getattr(race, 'sortLap', None) sortLabel = getattr(race, 'sortLabel', None) if race.isTimeTrial: def getSortTime(rr): try: return rr.firstTime + rr._lastTimeOrig except: return 0 else: def getSortTime(rr): try: return rr._lastTimeOrig except: return 0 results = sorted((rr for rr in GetResults(category) if rr.status == Model.Rider.Finisher and rr.lapTimes and getSortTime(rr) > 0), key=getSortTime) for i in range(1, len(results)): if results[i]._lastTimeOrig - results[ i - 1]._lastTimeOrig <= CloseFinishTime: self.closeFinishBibs[results[i - 1].num].append(results[i].num) self.closeFinishBibs[results[i].num].append(results[i - 1].num) labelLastX, labelLastY = self.labelGrid.GetViewStart() lapLastX, lapLastY = self.lapGrid.GetViewStart() exportGrid = ExportGrid() exportGrid.setResultsOneList(category, self.showRiderData, showLapsFrequency=1) if not exportGrid.colnames: self.clearGrid() return # Fix the speed column. speedUnit = None iSpeedCol = None try: iSpeedCol = next(i for i, c in enumerate(exportGrid.colnames) if c == _('Speed')) except StopIteration: pass if iSpeedCol is not None: for r, d in enumerate(exportGrid.data[iSpeedCol]): d = d.strip() if not d: continue dSplit = d.split() if not speedUnit and len(dSplit) > 1: exportGrid.colnames[iSpeedCol] = speedUnit = dSplit[1] exportGrid.data[iSpeedCol][r] = dSplit[0] if exportGrid.data[iSpeedCol][r] == '"': exportGrid.data[iSpeedCol][r] += ' ' colnames = exportGrid.colnames data = exportGrid.data sortCol = None if sortLap: race.sortLabel = sortLabel = None for i, name in enumerate(colnames): if name.startswith(_('Lap')) and int( name.split()[1]) == sortLap: sortCol = i break elif sortLabel: race.sortLap = sortLap = None if sortLabel not in { _('Pos'), _('Gap'), _('Time'), _('mph'), _('km/h') }: for i, name in enumerate(colnames): if name == sortLabel: sortCol = i break if sortCol is None: race.sortLabel = race.sortLap = sortLabel = sortLap = None results = GetResults(category) hasSpeeds = False for result in results: if getattr(result, 'lapSpeeds', None) or getattr( result, 'raceSpeeds', None): hasSpeeds = True break if not hasSpeeds: self.showLapSpeedsRadio.Enable(False) self.showRaceSpeedsRadio.Enable(False) if self.selectDisplay > Results.DisplayRaceTimes: self.selectDisplay = Results.DisplayRaceTimes self.showRaceTimesRadio.SetValue(True) else: self.showLapSpeedsRadio.Enable(True) self.showRaceSpeedsRadio.Enable(True) for r in [ self.showLapTimesRadio, self.showRaceTimesRadio, self.showLapSpeedsRadio, self.showRaceSpeedsRadio ]: if r.GetValue(): r.SetFont(self.boldFont) else: r.SetFont(wx.NullFont) self.hbs.RecalcSizes() self.hbs.Layout() # Find the fastest lap time. self.fastestLapRC, fastestLapSpeed, fastestLapTime = None, 0.0, sys.float_info.max for r, result in enumerate(results): if getattr(result, 'lapSpeeds', None): # Use speeds if available. for c, s in enumerate(result.lapSpeeds): if s > fastestLapSpeed: fastestLapSpeed = s self.fastestLapRC = (r, c) elif result.lapTimes: # Else, use times. for c, t in enumerate(result.lapTimes): if t < fastestLapTime: fastestLapTime = t self.fastestLapRC = (r, c) highPrecision = Model.highPrecisionTimes() try: firstLapCol = next(i for i, name in enumerate(colnames) if name.startswith(_('Lap'))) except StopIteration: firstLapCol = len(colnames) # Convert to race times, lap speeds or race speeds as required. ''' DisplayLapTimes = 0 DisplayRaceTimes = 1 DisplayLapSpeeds = 2 DisplayRaceSpeeds = 3 ''' if self.selectDisplay == Results.DisplayRaceTimes: for r, result in enumerate(results): for i, t in enumerate(result.raceTimes[1:]): try: data[i + firstLapCol][r] = Utils.formatTimeCompressed( t, highPrecision) except IndexError: pass elif self.selectDisplay == Results.DisplayLapSpeeds: for r, result in enumerate(results): if getattr(result, 'lapSpeeds', None): for i, s in enumerate(result.lapSpeeds): try: data[i + firstLapCol][r] = u'{:.2f}'.format(s) except IndexError: pass elif self.selectDisplay == Results.DisplayRaceSpeeds: for r, result in enumerate(results): if getattr(result, 'raceSpeeds', None): for i, s in enumerate(result.raceSpeeds): try: data[i + firstLapCol][r] = u'{:.2f}'.format(s) except IndexError: pass # Sort by the given lap, if there is one. # Also, add a position for the lap itself. if sortCol is not None: maxVal = 1000.0 * 24.0 * 60.0 * 60.0 if sortLap: if self.selectDisplay in [ Results.DisplayLapTimes, Results.DisplayRaceTimes ]: getFunc = Utils.StrToSeconds else: getFunc = lambda x: -float(x) else: if colnames[sortCol] in [_('Start'), _('Finish'), _('Time')]: getFunc = Utils.StrToSeconds elif colnames[sortCol] in [_('mph'), _('km')]: getFunc = lambda x: -float(x) if x else 0.0 elif colnames[sortCol] == _('Factor'): getFunc = lambda x: float(x) if x else maxVal elif colnames[sortCol] in [_('Pos'), _('Bib')]: getFunc = lambda x: int(x) if x and six.text_type( x).isdigit() else maxVal else: getFunc = lambda x: u'{}'.format(x) maxVal = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' sortPairs = [] for r, result in enumerate(results): try: k = (getFunc(data[sortCol][r]), r) except Exception as e: k = (maxVal, r) sortPairs.append((k, r)) sortPairs.sort() for c in range(len(data)): col = data[c] data[c] = [ col[i] if i < len(col) else u'' for k, i in sortPairs ] if colnames[sortCol] != _('Bib'): for r in range(len(data[sortCol])): if data[sortCol][r]: data[sortCol][r] = u'{} [{}: {}]'.format( data[sortCol][r], r + 1, data[1][r]) # Highlight the sorted column. if sortLap: colnames = [] for name in exportGrid.colnames: try: if int(name.split()[1]) == sortLap: name = u'<{}>\n{}'.format(name, [ _('by Lap Time'), _('by Race Time'), _('by Lap Speed'), _('by Race Speed') ][self.selectDisplay]) except: pass colnames.append(name) elif sortLabel: colnames = [] for name in exportGrid.colnames: if name == sortLabel: name = u'<{}>'.format(name) colnames.append(name) else: colnames = exportGrid.colnames try: iLabelMax = next( i for i, name in enumerate(colnames) if name.startswith(_('Lap')) or name.startswith('<' + _('Lap'))) except StopIteration: iLabelMax = len(colnames) colnamesLabels = colnames[:iLabelMax] dataLabels = data[:iLabelMax] colnameLaps = colnames[iLabelMax:] dataLaps = data[iLabelMax:] self.labelGrid.Set(data=dataLabels, colnames=colnamesLabels) self.labelGrid.SetLeftAlignCols(exportGrid.leftJustifyCols) self.labelGrid.AutoSizeColumns(True) self.labelGrid.Reset() try: iUCICodeCol = colnamesLabels.index(_('UCICode')) self.labelGrid.SetColRenderer(iUCICodeCol, IOCCodeRenderer()) except ValueError: pass try: iNatCodeCol = colnamesLabels.index(_('NatCode')) self.labelGrid.SetColRenderer(iNatCodeCol, IOCCodeRenderer()) except ValueError: pass self.lapGrid.Set(data=dataLaps, colnames=colnameLaps) self.lapGrid.Reset() self.lapGrid.AutoSizeColumns(self.lapGrid.GetNumberCols() < 100) self.isEmpty = False # Find interpolated entries. with Model.LockRace() as race: numTimeInfo = race.numTimeInfo riders = race.riders for r in range(self.lapGrid.GetNumberRows()): try: rider = riders[int(self.labelGrid.GetCellValue(r, 1))] except: continue try: entries = rider.interpolate() except (ValueError, IndexError): continue if not entries: continue for c in range(self.lapGrid.GetNumberCols()): if not self.lapGrid.GetCellValue(r, c): break try: if entries[c + 1].interp: self.rcInterp.add((r, c)) elif numTimeInfo.getInfo(entries[c + 1].num, entries[c + 1].t) is not None: self.rcNumTime.add((r, c)) elif c > self.iLastLap: self.iLastLap = c except IndexError: pass self.labelGrid.Scroll(labelLastX, labelLastY) self.lapGrid.Scroll(lapLastX, lapLastY) self.showNumSelect() if self.firstDraw: self.firstDraw = False self.splitter.SetSashPosition(400) # Fix the grids' scrollbars. self.labelGrid.FitInside() self.lapGrid.FitInside()
def prepareGrid( self, page ): exportGrid = ExportGrid() showLapTimes = (not Model.race) or getattr( Model.race, 'includeLapTimesInPrintout', True ) exportGrid.setResultsOneList( self.pageInfo[page][0], True, showLapTimes = showLapTimes ) return exportGrid