Created
November 17, 2012 00:17
-
-
Save vestel/4092112 to your computer and use it in GitHub Desktop.
Adds Suunto HR information (from Movescount) to workout in Endomondo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is draft version | |
# so code is ugly | |
# Possible todos: | |
* Code cleanup :) | |
* Accept filenames from command lines | |
* Create new file from date | |
* Create missing Trackpoints (for location based sports, like swimming) | |
* Refactor merge (do believe it might go slow on long distance run) | |
* Update sport name in file | |
# Long future to-dos: | |
* Download tcx from Endomondo | |
* Download xlsx from Movescount | |
* Upload file to Endomondo | |
* Find step-count free service and learn how to retrieve date and merge Cadence in tcx as well |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xlrd import open_workbook | |
from datetime import datetime, timedelta | |
o = open_workbook("Walking.xlsx") | |
sheet = o.sheets()[0] | |
print sheet.name | |
hrm_dates = [] | |
hrm_bpms = [] | |
offset = timedelta(hours=2) | |
for row in range(2,sheet.nrows): | |
hrmdate = datetime.strptime(sheet.cell(row,sheet.ncols-3).value,"%Y-%m-%d %H:%M:%S") | |
hrmdate = hrmdate - offset | |
hrm_dates.append(hrmdate) | |
hrm_bpms.append(sheet.cell(row,sheet.ncols-1).value) | |
print "LEN:", len(hrm_bpms) | |
#print hrm_data | |
from lxml import etree | |
tree = etree.parse('Walking.tcx') | |
root = tree.getroot() | |
#print root | |
ns = '{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2}' | |
index = 0 | |
appends = 0 | |
total = 0 | |
for point in root.getiterator(ns+'Trackpoint'): | |
for each in root.getiterator(ns+'Time'): | |
total += 1 | |
current = hrm_dates[index] | |
endotime = datetime.strptime(each.text,"%Y-%m-%dT%H:%M:%SZ") | |
if endotime in hrm_dates: | |
index = hrm_dates.index(endotime) | |
bpm = etree.SubElement(point, "HeartRateBpm") | |
bpm.text = "%d" % int(hrm_bpms[index]) | |
appends += 1 | |
diff = current - endotime if current > endotime else endotime - current | |
if abs(diff.seconds) < 10: | |
bpm = etree.SubElement(point, "HeartRateBpm") | |
bpm.text = "%d" % int(hrm_bpms[index]) | |
index += 1 | |
appends += 1 | |
print "RES:", appends, " of ", total | |
output = open("result.tcx","w") | |
output.write( etree.tostring(root) ) | |
output.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment