Permalink
Browse files

Towards #8

* Split laps by distance only as lap time is completely unreliable as it exludes inactivity time.
* Erroneous (e.g., empty ones in the beginning) laps (e.g. accidental press) will have start time of the next proper lap.

Also Activity Id in UTC
  • Loading branch information...
1 parent 0f6d3d2 commit 404bdbd54998c74a6def248139c3b4b4466fa6b5 @mlt committed Jun 25, 2012
Showing with 3 additions and 15 deletions.
  1. +3 −15 src/csv2tcx.py
View
@@ -26,28 +26,25 @@
track_start = tz.localize(datetime.strptime(track["Start"], "%Y-%m-%d %H:%M:%S"))
except: # support for legacy format with standalone x1
track_start = tz.localize(datetime.strptime("{:s}:{:s}".format(track["Start"], track["x1"]), "%Y-%m-%d %H:%M:%S"))
- laps_left = int(track["Laps"])
# e = datetime.strptime(track["End"], "%Y-%m-%d %H:%M").replace(tzinfo=tz)
print("""<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd">
<Activities>
<Activity Sport="Running">
- <Id>{:s}</Id>""".format(track_start.isoformat()))
+ <Id>{:s}</Id>""".format(track_start.astimezone(utc).strftime("%Y-%m-%dT%H:%M:%SZ")))
lap_start = track_start
time_prev = 0.
kcal_prev = 0
dist_prev = 0.
beats_prev = 0
- sec_prev = 0
with open(base+".laps") as l, open(base+".points") as p:
laps = DictReader(l)
points = DictReader(p)
thePoint = next(points)
for theLap in laps:
- laps_left -= 1
time = float(theLap["Time"])
kcal = int(float(theLap["kcal"]))
lap_dist = float(theLap["Distance"])*1.e3
@@ -63,10 +60,6 @@
theLap["MaxSpeed"], \
kcal - kcal_prev, \
int((beats - beats_prev)/(time - time_prev))))
- sec = int(theLap["sec"])
- lap_start += timedelta(seconds=sec - sec_prev)
- # lap_start += timedelta(seconds=time - time_prev)
- sec_prev = sec
time_prev = time
kcal_prev = kcal
dist_prev = lap_dist
@@ -81,13 +74,8 @@
while True:
time = tz.localize(datetime.strptime(thePoint["Time"], "%Y-%m-%d %H:%M:%S"))
dist = float(thePoint["Distance"])*1.e3
- if dist > lap_dist: # if for some reason we didn't jump to next lap before
- # print("Point {:s} Over the lap {:s} by distance".format(thePoint["No"], theLap["Lap"]))
- lap_start = time
- break
- if time > lap_start and not int(theLap["autolap"]) and laps_left:
- # print("Point {:s} {:s} Over the lap {:s} {:s} by time".format(thePoint["No"], time.isoformat(), theLap["Lap"], lap_start.isoformat()))
- lap_start = time
+ if dist > lap_dist: # the only reliable next lap criteria
+ lap_start = time # the only source of absolute time
break
print(""" <Trackpoint>
<Time>{:s}</Time>

0 comments on commit 404bdbd

Please sign in to comment.