Skip to content

Commit

Permalink
switched timing resolution to tenth of a second
Browse files Browse the repository at this point in the history
  • Loading branch information
bletham committed Jan 4, 2015
1 parent 210fb9c commit 657c84c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
13 changes: 7 additions & 6 deletions fstimer/gui/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def time_format(t):

def time_parse(dt):
'''converts string time to datetime.timedelta'''
d = re.match(r'((?P<days>\d+) days, )?((?P<hours>\d+):)?'r'(?P<minutes>\d+):(?P<seconds>\d+)', dt).groupdict(0)
d = re.match(r'((?P<days>\d+) days, )?((?P<hours>\d+):)?(?P<minutes>\d+):(?P<seconds>\d+)(\.(?P<milliseconds>\d+))?', dt).groupdict(0)
d['milliseconds'] = int(d['milliseconds'])*100
return datetime.timedelta(**dict(((key, int(value)) for key, value in d.items())))

class TimingWin(gtk.Window):
Expand Down Expand Up @@ -213,7 +214,7 @@ def print_corrected_time(self, column, renderer, model, itr):
try:
th = time_parse(self.timing[bibid]['Handicap'])
nt = t - th
renderer.set_property('text', str(nt))
renderer.set_property('text', str(nt)[:-5])
except AttributeError:
#Handicap is present but is not formatted correctly.
renderer.set_property('text', '')
Expand Down Expand Up @@ -395,12 +396,12 @@ def editblocktimedone(self, pathlist, operation, timestr):
adj_time = time_parse(timestr)
# Combine the timedeltas to get the new time
if operation == 'ADD':
new_time = str(old_time + adj_time)
new_time = str(old_time + adj_time)[:-5]
elif operation == 'SUBTRACT':
if old_time > adj_time:
new_time = str(old_time - adj_time)
new_time = str(old_time - adj_time)[:-5]
else:
new_time = '0:00:00' #We don't allow negative times.
new_time = '0:00:00.0' #We don't allow negative times.
# Save them, and write out to the timemodel
self.rawtimes['times'][row] = str(new_time)
self.timemodel.set_value(treeiter, 1, str(new_time))
Expand Down Expand Up @@ -646,7 +647,7 @@ def record_time(self, jnk_unused):

def new_blank_time(self):
'''Record a new time'''
t = str(datetime.timedelta(seconds=int(time.time()-self.t0)))
t = str(datetime.timedelta(milliseconds=int(1000*(time.time()-self.t0))))[:-5]
self.rawtimes['times'].insert(0, t) #we prepend to rawtimes, just as we prepend to timemodel
if self.offset >= 0:
# No IDs in the buffer, so just prepend it to the liststore.
Expand Down
14 changes: 2 additions & 12 deletions fstimer/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@
from collections import defaultdict


def str2timedelta(time):
'''converts a time string to a timedelta'''
timePattern = r'((?P<days>-?\d+) day(s)?, )?((?P<hours>\d+):)?'r'(?P<minutes>\d+):(?P<seconds>\d+)' #hours is optional
# convert txt time to dict
d1 = re.match(timePattern, time).groupdict(0)
# convert txt to ints
d2 = {key:int(val) for key, val in d1.iteritems()}
# build timedelta
return datetime.timedelta(**d2)

class PyTimer(object):
'''main class of fsTimer'''

Expand Down Expand Up @@ -451,7 +441,7 @@ def get_sorted_results(self):
for tag, time in timeslist:
if tag and time and tag != self.passid:
try:
new_timeslist.append((tag, str(str2timedelta(time) - str2timedelta(self.timing[tag]['Handicap']))))
new_timeslist.append((tag, str(fstimer.gui.timing.time_parse(time) - fstimer.gui.timing.time_parse(self.timing[tag]['Handicap']))[:-5]))
except AttributeError:
#Either time or Handicap couldn't be converted to timedelta. It will be dropped.
pass
Expand Down Expand Up @@ -483,5 +473,5 @@ def get_sorted_results(self):
# And now the first lap
laptimesdic2[tag].append(laptimesdic[tag][0])
# And now the subsequent laps
laptimesdic2[tag].extend([str(str2timedelta(laptimesdic[tag][ii+1]) - str2timedelta(laptimesdic[tag][ii])) for ii in range(len(laptimesdic[tag])-1)])
laptimesdic2[tag].extend([str(fstimer.gui.timing.time_parse(laptimesdic[tag][ii+1]) - fstimer.gui.timing.time_parse(laptimesdic[tag][ii]))[:-5] for ii in range(len(laptimesdic[tag])-1)])
return sorted(laptimesdic2.items(), key=lambda entry: entry[1][0])

0 comments on commit 657c84c

Please sign in to comment.