Skip to content

Commit

Permalink
Added UCI ID.
Browse files Browse the repository at this point in the history
Fixed Excel import.
  • Loading branch information
esitarski committed Aug 31, 2017
1 parent cc44c2c commit 0bf6f5f
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 92 deletions.
13 changes: 8 additions & 5 deletions MainWin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import wx
import wx.adv
import wx.lib.masked.numctrl as NC
import wx.lib.intctrl as IC
from wx.lib.wordwrap import wordwrap
Expand Down Expand Up @@ -84,7 +85,7 @@ def __init__( self, parent, id = wx.ID_ANY, title='', size=(200,200) ):
self.tutorialButton = wx.Button( self, label=_('Help/Tutorial...') )
self.tutorialButton.Bind( wx.EVT_BUTTON, self.onTutorial )
vs.Add( self.tutorialButton, flag=wx.ALL, border=4 )
branding = wx.HyperlinkCtrl( self, id=wx.ID_ANY, label=u"Powered by CrossMgr", url=u"http://www.sites.google.com/site/crossmgrsoftware/" )
branding = wx.adv.HyperlinkCtrl( self, id=wx.ID_ANY, label=u"Powered by CrossMgr", url=u"http://www.sites.google.com/site/crossmgrsoftware/" )
vs.Add( branding, flag=wx.ALL, border=4 )
horizontalControlSizer.Add( vs )

Expand Down Expand Up @@ -133,6 +134,7 @@ def onTutorial( self, event ):
try:
fname_excel = MakeExampleExcel()
except Exception as e:
traceback.print_exc()
Utils.MessageOK( self, u'{}\n\n{}\n\n{}'.format(
u'Problem creating Excel sheet.',
e,
Expand Down Expand Up @@ -170,12 +172,12 @@ def updateStageList( self, registration=None, stages=None ):
stages = (stages or (Model.model and Model.model.stages) or [])

def insert_stage_info( stage ):
idx = self.stageList.InsertStringItem( sys.maxint, stage.sheet_name )
self.stageList.SetStringItem( idx, 1, unicode(len(stage)) )
idx = self.stageList.InsertItem( sys.maxint, stage.sheet_name )
self.stageList.SetItem( idx, 1, unicode(len(stage)) )
if stage.errors:
self.stageList.SetStringItem( idx, 2, u'{}: {}'.format(len(stage.errors), u' '.join(u'[{}]'.format(e) for e in stage.errors)) )
self.stageList.SetItem( idx, 2, u'{}: {}'.format(len(stage.errors), u' '.join(u'[{}]'.format(e) for e in stage.errors)) )
else:
self.stageList.SetStringItem( idx, 2, u' ' )
self.stageList.SetItem( idx, 2, u' ' )

insert_stage_info( registration )
for stage in stages:
Expand Down Expand Up @@ -207,6 +209,7 @@ def doUpdate( self, event=None, fnameNew=None ):
with open(self.fname, 'rb') as f:
pass
except Exception as e:
traceback.print_exc()
Utils.MessageOK( self, u'{}:\n\n {}\n\n{}'.format( _('Cannot Open Excel file'), self.fname, e), _('Cannot Open Excel File') )
self.setUpdated( False )
return
Expand Down
25 changes: 13 additions & 12 deletions MakeExampleExcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
def get_license():
return u''.join( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[random.randint(0,25)] for i in xrange(6) )

def get_uci_code():
def get_uci_id():
dob = datetime.date.today() - datetime.timedelta( days=random.normalvariate(25,3)*365.25 )
return u'FRA{}'.format( dob.strftime( '%Y%m%d' ) )

def make_title( s ):
words = [(w.upper() if w == u'uci' else w) for w in s.split(u'_')]
return u' '.join( (w[0].upper() + w[1:]) for w in words if w not in (u'of', u'in', u'or') )


def get_uci_id():
uci_id = ''.join(random.choice('123456789') for i in xrange(9))
uci_id += '{:02d}'.format(int(uci_id)%97)
return uci_id

stage_points = '''
50 30 20 18 16 14 12 10 8 7 6 5 4 3 2
30 25 22 19 17 15 13 11 9 7 6 5 4 3 2
Expand Down Expand Up @@ -64,21 +65,21 @@ def MakeExampleExcel():
ws = wb.add_worksheet('Registration')
fit_sheet = FitSheetWrapper( ws )

fields = ['bib', 'first_name', 'last_name', 'uci_code', 'license', 'team']
fields = ['bib', 'first_name', 'last_name', 'uci_id', 'license', 'team']
row = 0
for c, field in enumerate(fields):
fit_sheet.write( row, c, make_title(field), bold_format )
fit_sheet.write( row, c, Utils.fieldToHeader(field), bold_format )

riders = 20
team_size = 4
riders = 25
team_size = riders // len(teams)
bibs = []
for i in xrange(riders):
row += 1
bibs.append((i//team_size+1)*10 + (i%team_size))
fit_sheet.write( row, 0, bibs[i] )
fit_sheet.write( row, 1, common_first_names[i%len(common_first_names)] )
fit_sheet.write( row, 2, common_last_names[i%len(common_last_names)] )
fit_sheet.write( row, 3, get_uci_code() )
fit_sheet.write( row, 3, get_uci_id() )
fit_sheet.write( row, 4, get_license() )
fit_sheet.write( row, 5, teams[i//team_size] )

Expand All @@ -101,7 +102,7 @@ def MakeExampleExcel():

row = 0
for c, field in enumerate(fields):
fit_sheet.write( row, c, make_title(field), bold_format )
fit_sheet.write( row, c, Utils.fieldToHeader(field), bold_format )

bibAB = []
for i, (bib, t) in enumerate(sorted( ((bib, random.normalvariate(race_time-bib/4.0, 5*60)) for bib in bibs), key=operator.itemgetter(1) )):
Expand Down
40 changes: 29 additions & 11 deletions Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Rider( object ):
'bib',
'first_name', 'last_name',
'team',
'uci_code',
'uci_id',
'license',
'row'
)
Expand Down Expand Up @@ -75,32 +75,43 @@ def __init__( self, **kwargs ):
if self.license is not None:
self.license = unicode(self.license).strip()

if self.row:
if self.row is not None:
try:
self.row = int(self.row)
except ValueError:
self.row = None

if self.last_name:
self.last_name = unicode(self.last_name).replace(u'*',u'').strip()
self.last_name = self.last_name or u''

if self.first_name:
self.first_name = unicode(self.first_name).replace(u'*',u'').replace(u'(JR)',u'').strip()
self.first_name = self.first_name or u''

if self.uci_code:
self.uci_code = unicode(self.uci_code).strip()
if len(self.uci_code) != 11:
raise ValueError( u'Row {}: invalid uci_code: {}'.format(self.row, self.uci_code) )

assert self.bib is not None, 'Missing Bib'
self.bib = int(self.bib)

if self.uci_id:
try:
self.uci_id = int(self.uci_id)
except:
pass
self.uci_id = unicode(self.uci_id).strip()
if len(self.uci_id) != 11:
raise ValueError( u'Row {}: invalid uci_id: {} incorrect length'.format(self.row, self.uci_id) )
if not self.uci_id.isdigit():
raise ValueError( u'Row {}: invalid uci_id: {} must be all digits'.format(self.row, self.uci_id) )
if int(self.uci_id[:-2]) % 97 != int(self.uci_id[-2:]):
raise ValueError( u'Row {}: invalid uci_id: {} checkdigit error'.format(self.row, self.uci_id) )

@property
def full_name( self ):
return u'{} {}'.format( self.first_name, self.last_name )

@property
def results_name( self ):
return u','.join( name for name in [self.last_name.upper(), self.first_name] if name )
return u','.join( name for name in [(self.last_name or u'').upper(), self.first_name] if name )

def __repr__( self ):
return u'Rider({})'.format(u','.join( u'{}'.format(getattr(self, a)) for a in self.Fields ))
Expand Down Expand Up @@ -204,9 +215,16 @@ def __repr__( self ):
u'RANK': u'PLACE',
u'POS': u'PLACE',
u'BIBNUM': u'BIB',
u'NUM': u'BIB',
u'NUMBER': u'BIB',
u'FNAME': u'FIRST',
u'LNAME': u'LAST',
}
def scrub_header( h ):
h = reNonAlphaNum.sub( '', Utils.removeDiacritic(unicode(h)).upper() )
h = unicode(h).upper()
if h.endswith('_NAME') or h.endswith(' NAME'):
h = h[:-5]
h = reNonAlphaNum.sub( '', Utils.removeDiacritic(h) )
return header_sub.get(h, h)

def readSheet( reader, sheet_name, header_fields ):
Expand Down Expand Up @@ -241,7 +259,7 @@ def readSheet( reader, sheet_name, header_fields ):
hv = scrub_header( h )
if rv == hv:
header_map[h] = c
break
break
continue

# Create a Result from the row.
Expand Down Expand Up @@ -277,7 +295,7 @@ def read( self, reader ):
except Exception as e:
self.errors.append( e )
continue

self.riders.append( rider )
self.bibToRider[rider.bib] = rider
return self.errors
Expand Down
16 changes: 8 additions & 8 deletions StageRaceGCToExcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def writeIC( ws, stage ):
riderFields = set( model.registration.getFieldsInUse() )
headers = (
['Place', 'Bib', 'Last Name', 'First Name', 'Team'] +
(['UCI Code'] if 'uci_code' in riderFields else []) +
(['UCI ID'] if 'uci_id' in riderFields else []) +
(['License'] if 'license' in riderFields else []) +
[Utils.fieldToHeader(h) for h in ic_fields]
)
Expand All @@ -76,7 +76,7 @@ def writeIC( ws, stage ):
fit_sheet.write( rowNum, col, rider.first_name ); col += 1
fit_sheet.write( rowNum, col, rider.team ); col += 1

if 'uci_code' in riderFields:
if 'uci_id' in riderFields:
fit_sheet.write( rowNum, col, rider.team ); col += 1
if 'license' in riderFields:
fit_sheet.write( rowNum, col, rider.license ); col += 1
Expand Down Expand Up @@ -167,7 +167,7 @@ def writeSprintGC( ws ):
riderFields = set( model.registration.getFieldsInUse() )
headers = (
['place', 'bib', 'last_name', 'first_name', 'team'] +
(['uci_code'] if 'uci_code' in riderFields else []) +
(['uci_id'] if 'uci_id' in riderFields else []) +
(['license'] if 'license' in riderFields else []) +
['points', 'stage_wins', 'sprint_wins', 'GC']
)
Expand All @@ -190,8 +190,8 @@ def writeSprintGC( ws ):
fit_sheet.write( rowNum, col, unicode(rider.first_name) ); col += 1
fit_sheet.write( rowNum, col, unicode(rider.team) ); col += 1

if 'uci_code' in riderFields:
fit_sheet.write( rowNum, col, unicode(rider.uci_code) ); col += 1
if 'uci_id' in riderFields:
fit_sheet.write( rowNum, col, unicode(rider.uci_id) ); col += 1
if 'license' in riderFields:
fit_sheet.write( rowNum, col, unicode(rider.license) ); col += 1

Expand All @@ -209,7 +209,7 @@ def writeKOMGC( ws ):
riderFields = set( model.registration.getFieldsInUse() )
headers = (
['place', 'bib', 'last_name', 'first_name', 'team'] +
(['uci_code'] if 'uci_code' in riderFields else []) +
(['uci_id'] if 'uci_id' in riderFields else []) +
(['license'] if 'license' in riderFields else []) +
['KOM Total', 'HC Wins', 'C1 Wins', 'C2 Wins', 'C3 Wins', 'C4 Wins', 'GC']
)
Expand All @@ -232,8 +232,8 @@ def writeKOMGC( ws ):
fit_sheet.write( rowNum, col, unicode(rider.first_name) ); col += 1
fit_sheet.write( rowNum, col, unicode(rider.team) ); col += 1

if 'uci_code' in riderFields:
fit_sheet.write( rowNum, col, unicode(rider.uci_code) ); col += 1
if 'uci_id' in riderFields:
fit_sheet.write( rowNum, col, unicode(rider.uci_id) ); col += 1
if 'license' in riderFields:
fit_sheet.write( rowNum, col, unicode(rider.license) ); col += 1

Expand Down
24 changes: 12 additions & 12 deletions StageRaceGCToGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def callback( event ):
key = (page, coords[0], coords[1])
if key != model.lastKey:
try:
event.GetEventObject().SetToolTipString(model.comments[key])
event.GetEventObject().SetToolTip(model.comments[key])
except:
event.GetEventObject().SetToolTipString(u'')
event.GetEventObject().SetToolTip(u'')
model.lastKey = key
event.Skip()
return callback
Expand All @@ -63,7 +63,7 @@ def writeIC( stage ):
riderFields = set( model.registration.getFieldsInUse() )
headers = (
['place', 'bib', 'last_name', 'first_name', 'team'] +
(['uci_code'] if 'uci_code' in riderFields else []) +
(['uci_id'] if 'uci_id' in riderFields else []) +
(['license'] if 'license' in riderFields else []) +
list(ic_fields)
)
Expand All @@ -79,7 +79,7 @@ def writeIC( stage ):
attr.SetAlignment( wx.ALIGN_RIGHT, wx.ALIGN_CENTRE )
grid.SetColAttr( col, attr )
grid.SetColLabelValue( col, Utils.fieldToHeader(h, True) )

rowNum = 0
for place, r in enumerate(stage.individual_gc, 1):
try:
Expand All @@ -98,8 +98,8 @@ def writeIC( stage ):
grid.SetCellValue( rowNum, col, unicode(rider.first_name) ); col += 1
grid.SetCellValue( rowNum, col, unicode(rider.team) ); col += 1

if 'uci_code' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.uci_code) ); col += 1
if 'uci_id' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.uci_id) ); col += 1
if 'license' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.license) ); col += 1

Expand Down Expand Up @@ -214,7 +214,7 @@ def writeSprintGC():
riderFields = set( model.registration.getFieldsInUse() )
headers = (
['place', 'bib', 'last_name', 'first_name', 'team'] +
(['uci_code'] if 'uci_code' in riderFields else []) +
(['uci_id'] if 'uci_id' in riderFields else []) +
(['license'] if 'license' in riderFields else []) +
['points', 'stage_wins', 'sprint_wins', 'GC']
)
Expand Down Expand Up @@ -245,8 +245,8 @@ def writeSprintGC():
grid.SetCellValue( rowNum, col, unicode(rider.first_name) ); col += 1
grid.SetCellValue( rowNum, col, unicode(rider.team) ); col += 1

if 'uci_code' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.uci_code) ); col += 1
if 'uci_id' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.uci_id) ); col += 1
if 'license' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.license) ); col += 1

Expand All @@ -266,7 +266,7 @@ def writeKOMGC():
riderFields = set( model.registration.getFieldsInUse() )
headers = (
['place', 'bib', 'last_name', 'first_name', 'team'] +
(['uci_code'] if 'uci_code' in riderFields else []) +
(['uci_id'] if 'uci_id' in riderFields else []) +
(['license'] if 'license' in riderFields else []) +
['KOM Total', 'HC Wins', 'C1 Wins', 'C2 Wins', 'C3 Wins', 'C4 Wins', 'GC']
)
Expand Down Expand Up @@ -297,8 +297,8 @@ def writeKOMGC():
grid.SetCellValue( rowNum, col, unicode(rider.first_name) ); col += 1
grid.SetCellValue( rowNum, col, unicode(rider.team) ); col += 1

if 'uci_code' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.uci_code) ); col += 1
if 'uci_id' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.uci_id) ); col += 1
if 'license' in riderFields:
grid.SetCellValue( rowNum, col, unicode(rider.license) ); col += 1

Expand Down
31 changes: 10 additions & 21 deletions Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@ def initTranslation():

initTranslation()

#-----------------------------------------------------------------------
# Monkey-patch font so we always fetch a default font face.
#
if 'WXMAC' not in wx.Platform:
FontFace = 'Arial'
FontFromPixelSize = wx.FontFromPixelSize
def FontFromPixelSizeFontFace( *args, **kwargs ):
if 'face' not in kwargs:
kwargs['face'] = FontFace
return FontFromPixelSize( *args, **kwargs )
wx.FontFromPixelSize = FontFromPixelSizeFontFace

Font = wx.Font
def FontFontFace( *args, **kwargs ):
if 'face' not in kwargs:
kwargs['face'] = FontFace
return Font( *args, **kwargs )
wx.Font = FontFontFace

try:
from win32com.shell import shell, shellcon
except ImportError:
Expand Down Expand Up @@ -123,11 +104,17 @@ def writeLog( message ):
try:
dt = datetime.datetime.now()
dt = dt.replace( microsecond = 0 )
sys.stdout.write( '{} ({}) {}{}'.format(dt.isoformat(), PlatformName, message, '\n' if not message or message[-1] != '\n' else '' ) )
msg = u'{} ({}) {}{}'.format(
dt.isoformat(),
PlatformName,
message,
'\n' if not message or message[-1] != '\n' else ''
)
sys.stdout.write( removeDiacritic(msg) )
sys.stdout.flush()
except IOError:
pass

def disable_stdout_buffering():
fileno = sys.stdout.fileno()
temp_fd = os.dup(fileno)
Expand Down Expand Up @@ -156,6 +143,8 @@ def logException( e, exc_info ):
writeLog( '**** End Exception ****' )

def fieldToHeader( f, multi_line=False ):
if f == u'uci_id':
return _('UCI ID')
if f == u'uci_code':
return _('UCI Code')
if f.endswith(u'_name'):
Expand Down
2 changes: 1 addition & 1 deletion Version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AppVerName="StageRaceGC 0.0.6"
AppVerName="StageRaceGC 0.0.7"
Loading

0 comments on commit 0bf6f5f

Please sign in to comment.