rowingdata 3.6.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rowingdata/__init__.py +2 -0
- rowingdata/__main__.py +2 -0
- rowingdata/boatedit.py +15 -0
- rowingdata/checkdatafiles.py +216 -0
- rowingdata/copystats.py +22 -0
- rowingdata/crewnerdplot.py +37 -0
- rowingdata/crewnerdplottime.py +37 -0
- rowingdata/csvparsers.py +3114 -0
- rowingdata/ergdataplot.py +31 -0
- rowingdata/ergdataplottime.py +31 -0
- rowingdata/ergdatatotcx.py +32 -0
- rowingdata/ergstickplot.py +31 -0
- rowingdata/ergstickplottime.py +32 -0
- rowingdata/ergsticktotcx.py +32 -0
- rowingdata/example.csv +5171 -0
- rowingdata/gpxtools.py +70 -0
- rowingdata/gpxwrite.py +151 -0
- rowingdata/konkatenaadje.py +19 -0
- rowingdata/laptesting.py +293 -0
- rowingdata/obsolete.py +654 -0
- rowingdata/otherparsers.py +718 -0
- rowingdata/painsled_desktop_plot.py +30 -0
- rowingdata/painsled_desktop_plottime.py +29 -0
- rowingdata/painsled_desktop_toc2.py +30 -0
- rowingdata/painsledplot.py +27 -0
- rowingdata/painsledplottime.py +27 -0
- rowingdata/painsledtoc2.py +23 -0
- rowingdata/roweredit.py +15 -0
- rowingdata/rowingdata.py +6941 -0
- rowingdata/rowproplot.py +31 -0
- rowingdata/rowproplottime.py +31 -0
- rowingdata/speedcoachplot.py +31 -0
- rowingdata/speedcoachplottime.py +31 -0
- rowingdata/speedcoachtoc2.py +36 -0
- rowingdata/tcxplot.py +38 -0
- rowingdata/tcxplot_nogeo.py +38 -0
- rowingdata/tcxplottime.py +33 -0
- rowingdata/tcxplottime_nogeo.py +33 -0
- rowingdata/tcxtoc2.py +30 -0
- rowingdata/tcxtools.py +417 -0
- rowingdata/trainingparser.py +302 -0
- rowingdata/utils.py +135 -0
- rowingdata/windcorrected.py +48 -0
- rowingdata/writetcx.py +312 -0
- rowingdata-3.6.8.dist-info/LICENSE +21 -0
- rowingdata-3.6.8.dist-info/METADATA +1149 -0
- rowingdata-3.6.8.dist-info/RECORD +49 -0
- rowingdata-3.6.8.dist-info/WHEEL +5 -0
- rowingdata-3.6.8.dist-info/top_level.txt +1 -0
rowingdata/writetcx.py
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import print_function
|
|
3
|
+
import time
|
|
4
|
+
import datetime
|
|
5
|
+
from dateutil import parser as ps
|
|
6
|
+
import lxml
|
|
7
|
+
import arrow
|
|
8
|
+
import numpy as np
|
|
9
|
+
from lxml import etree, objectify
|
|
10
|
+
from lxml.etree import XMLSyntaxError
|
|
11
|
+
import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse
|
|
12
|
+
import ssl
|
|
13
|
+
from six.moves import range
|
|
14
|
+
import xml.etree.ElementTree as et
|
|
15
|
+
|
|
16
|
+
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
|
|
17
|
+
from xml.dom import minidom
|
|
18
|
+
|
|
19
|
+
import sys
|
|
20
|
+
if sys.version_info[0]<=2:
|
|
21
|
+
pythonversion = 2
|
|
22
|
+
textwritemode = 'w'
|
|
23
|
+
else:
|
|
24
|
+
pythonversion = 3
|
|
25
|
+
textwritemode = 'wt'
|
|
26
|
+
from io import open
|
|
27
|
+
|
|
28
|
+
def prettify(elem):
|
|
29
|
+
"""Return a pretty-printed XML string for the Element.
|
|
30
|
+
"""
|
|
31
|
+
rough_string = tostring(elem, 'utf-8')
|
|
32
|
+
reparsed = minidom.parseString(rough_string)
|
|
33
|
+
return reparsed.toprettyxml(indent=" ")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_empty_tcx():
|
|
38
|
+
top = Element('TrainingCenterDatabase')
|
|
39
|
+
top.attrib['xmlns'] = "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"
|
|
40
|
+
activities = SubElement(top,'Activities')
|
|
41
|
+
activity = SubElement(activities,'Activity')
|
|
42
|
+
activity.attrib['Sport'] = "Other"
|
|
43
|
+
id = SubElement(activity,'Id')
|
|
44
|
+
id.text = '2015-03-28T20:45:15.000Z'
|
|
45
|
+
creator = SubElement(activity,'Creator')
|
|
46
|
+
creator.attrib['xsi:type'] = 'Device_t'
|
|
47
|
+
creator.attrib['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance'
|
|
48
|
+
name = SubElement(creator,'Name')
|
|
49
|
+
name.text = 'Empty File'
|
|
50
|
+
unitid = SubElement(creator,'UnitId')
|
|
51
|
+
unitid.text = '0'
|
|
52
|
+
productid = SubElement(creator,'ProductID')
|
|
53
|
+
productid.text = '0'
|
|
54
|
+
|
|
55
|
+
return prettify(top)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
namespace='http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2'
|
|
59
|
+
|
|
60
|
+
def lap_begin(f,datetimestring,totalmeters,avghr,maxhr,avgspm,totalseconds):
|
|
61
|
+
f.write(' <Lap StartTime="{s}">\n'.format(s=datetimestring))
|
|
62
|
+
f.write(' <TotalTimeSeconds>{s}</TotalTimeSeconds>\n'.format(s=totalseconds))
|
|
63
|
+
f.write(' <DistanceMeters>{s}</DistanceMeters>\n'.format(s=totalmeters))
|
|
64
|
+
f.write(' <Calories>1</Calories>\n')
|
|
65
|
+
f.write(' <AverageHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">\n')
|
|
66
|
+
f.write(' <Value>{s}</Value>\n'.format(s=avghr))
|
|
67
|
+
f.write(' </AverageHeartRateBpm>\n')
|
|
68
|
+
|
|
69
|
+
f.write(' <MaximumHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">\n')
|
|
70
|
+
f.write(' <Value>{s}</Value>\n'.format(s=maxhr))
|
|
71
|
+
f.write(' </MaximumHeartRateBpm>\n')
|
|
72
|
+
f.write(' <Intensity>Active</Intensity>\n')
|
|
73
|
+
f.write(' <Cadence>{s}</Cadence>\n'.format(s=avgspm))
|
|
74
|
+
f.write(' <TriggerMethod>Manual</TriggerMethod>\n')
|
|
75
|
+
f.write(' <Track>\n')
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def lap_end(f):
|
|
79
|
+
f.write(' </Track>\n')
|
|
80
|
+
f.write(' <Notes>rowingdata export</Notes>\n')
|
|
81
|
+
f.write(' </Lap>\n')
|
|
82
|
+
|
|
83
|
+
def create_tcx(df,row_date="2016-01-01", notes="Exported by rowingdata",
|
|
84
|
+
sport="Other"):
|
|
85
|
+
if notes is None:
|
|
86
|
+
notes="Exported by rowingdata"
|
|
87
|
+
|
|
88
|
+
notes = notes.encode('utf-8')
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
totalseconds=int(df['TimeStamp (sec)'].max()-df['TimeStamp (sec)'].min())
|
|
92
|
+
except ValueError:
|
|
93
|
+
totalseconds = 0
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
totalmeters=int(df['cum_dist'].max())
|
|
97
|
+
except ValueError:
|
|
98
|
+
totalmeters = 0
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
totalcalories=int(df[' Calories (kCal)'].max())
|
|
102
|
+
except ValueError:
|
|
103
|
+
totalcalories = 0
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
avghr=int(df[' HRCur (bpm)'].mean())
|
|
107
|
+
except ValueError:
|
|
108
|
+
avghr = 1
|
|
109
|
+
if avghr == 0:
|
|
110
|
+
avghr=1
|
|
111
|
+
try:
|
|
112
|
+
maxhr=int(df[' HRCur (bpm)'].max())
|
|
113
|
+
except ValueError:
|
|
114
|
+
maxhr = 1
|
|
115
|
+
if maxhr == 0:
|
|
116
|
+
maxhr=1
|
|
117
|
+
|
|
118
|
+
try:
|
|
119
|
+
avgspm=int(df[' Cadence (stokes/min)'].mean())
|
|
120
|
+
except ValueError:
|
|
121
|
+
avgspm = 10
|
|
122
|
+
|
|
123
|
+
seconds=df['TimeStamp (sec)'].values
|
|
124
|
+
distancemeters=df['cum_dist'].values
|
|
125
|
+
heartrate=df[' HRCur (bpm)'].values.astype(int)
|
|
126
|
+
cadence=np.round(df[' Cadence (stokes/min)'].values).astype(int)
|
|
127
|
+
|
|
128
|
+
nr_rows=len(seconds)
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
lat=df[' latitude'].values
|
|
132
|
+
except KeyError:
|
|
133
|
+
lat=np.zeros(nr_rows)
|
|
134
|
+
|
|
135
|
+
try:
|
|
136
|
+
lon=df[' longitude'].values
|
|
137
|
+
except KeyError:
|
|
138
|
+
lon=np.zeros(nr_rows)
|
|
139
|
+
|
|
140
|
+
haspower=1
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
power=df[' Power (watts)'].values
|
|
144
|
+
except KeyError:
|
|
145
|
+
haspower=0
|
|
146
|
+
|
|
147
|
+
s="2000-01-01"
|
|
148
|
+
tt=ps.parse(s)
|
|
149
|
+
|
|
150
|
+
timezero=arrow.get(tt).timestamp()
|
|
151
|
+
if seconds[0]<timezero:
|
|
152
|
+
dateobj=ps.parse(row_date)
|
|
153
|
+
unixtimes=seconds+arrow.get(dateobj).timestamp() #time.mktime(dateobj.timetuple())
|
|
154
|
+
|
|
155
|
+
top = Element('TrainingCenterDatabase')
|
|
156
|
+
top.attrib['xmlns'] = "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"
|
|
157
|
+
top.attrib['xmlns:ax'] = "http://www.garmin.com/xmlschemas/ActivityExtension/v2"
|
|
158
|
+
top.attrib['xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
|
|
159
|
+
top.attrib['xsi:schemaLocation'] = "http://www.garmin.com/xmlschemas/ActivityExtension/v2 http://www.garmin.com/xmlschemas/ActivityExtensionv2.xsd http://www.garmin.com/xmlschemas/FatCalories/v1 http://www.garmin.com/xmlschemas/fatcalorieextensionv1.xsd http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd"
|
|
160
|
+
|
|
161
|
+
activities = SubElement(top,'Activities')
|
|
162
|
+
activity = SubElement(activities,'Activity')
|
|
163
|
+
activity.attrib['Sport'] = sport
|
|
164
|
+
id = SubElement(activity,'Id')
|
|
165
|
+
id.text = row_date
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# Lap averages
|
|
169
|
+
lap = SubElement(activity,'Lap')
|
|
170
|
+
lap.attrib['StartTime'] = row_date
|
|
171
|
+
totaltime = SubElement(lap,'TotalTimeSeconds')
|
|
172
|
+
totaltime.text = '{s}'.format(s=totalseconds)
|
|
173
|
+
distancemeters_el = SubElement(lap,'DistanceMeters')
|
|
174
|
+
distancemeters_el.text = '{m}'.format(m=totalmeters)
|
|
175
|
+
calories = SubElement(lap,'Calories')
|
|
176
|
+
calories.text = '{c}'.format(c=totalcalories)
|
|
177
|
+
avghr_el = SubElement(lap,'AverageHeartRateBpm')
|
|
178
|
+
avghr_el.attrib['xsi:type'] = 'HeartRateInBeatsPerMinute_t'
|
|
179
|
+
value = SubElement(avghr_el,'Value')
|
|
180
|
+
value.text = '{s}'.format(s=avghr)
|
|
181
|
+
|
|
182
|
+
maxhr_el = SubElement(lap,'MaximumHeartRateBpm')
|
|
183
|
+
maxhr_el.attrib['xsi:type'] = 'HeartRateInBeatsPerMinute_t'
|
|
184
|
+
value = SubElement(maxhr_el,'Value')
|
|
185
|
+
value.text = '{s}'.format(s=maxhr)
|
|
186
|
+
|
|
187
|
+
intensity = SubElement(lap,'Intensity')
|
|
188
|
+
intensity.text = 'Active'
|
|
189
|
+
|
|
190
|
+
cadence_el = SubElement(lap,'Cadence')
|
|
191
|
+
cadence_el.text = '{s}'.format(s=avgspm)
|
|
192
|
+
|
|
193
|
+
triggermethod = SubElement(lap,'TriggerMethod')
|
|
194
|
+
triggermethod.text = 'Manual'
|
|
195
|
+
|
|
196
|
+
track = SubElement(lap,'Track')
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
for i in range(nr_rows):
|
|
200
|
+
hri=heartrate[i]
|
|
201
|
+
if hri == 0:
|
|
202
|
+
hri=1
|
|
203
|
+
|
|
204
|
+
trackpoint = SubElement(track,'Trackpoint')
|
|
205
|
+
|
|
206
|
+
s = arrow.get(unixtimes[i]).isoformat()
|
|
207
|
+
time = SubElement(trackpoint,'Time')
|
|
208
|
+
time.text = '{s}'.format(s=s)
|
|
209
|
+
|
|
210
|
+
if (lat[i] != 0) and (lon[i] != 0):
|
|
211
|
+
position = SubElement(trackpoint,'Position')
|
|
212
|
+
latitudedegrees = SubElement(position,'LatitudeDegrees')
|
|
213
|
+
latitudedegrees.text = '{lat}'.format(lat=lat[i])
|
|
214
|
+
longitudedegrees = SubElement(position,'LongitudeDegrees')
|
|
215
|
+
longitudedegrees.text = '{lon}'.format(lon=lon[i])
|
|
216
|
+
|
|
217
|
+
dist = SubElement(trackpoint,'DistanceMeters')
|
|
218
|
+
dist.text = '{d}'.format(d=distancemeters[i])
|
|
219
|
+
|
|
220
|
+
hrbpm = SubElement(trackpoint,'HeartRateBpm')
|
|
221
|
+
hrbpm.attrib['xsi:type'] = 'HeartRateInBeatsPerMinute_t'
|
|
222
|
+
val = SubElement(hrbpm,'Value')
|
|
223
|
+
val.text = '{s}'.format(s=hri)
|
|
224
|
+
|
|
225
|
+
spm_el = SubElement(trackpoint,'Cadence')
|
|
226
|
+
spm_el.text = '{s}'.format(s=cadence[i])
|
|
227
|
+
|
|
228
|
+
if haspower:
|
|
229
|
+
ext = SubElement(trackpoint,'Extensions')
|
|
230
|
+
tpx = SubElement(ext,'TPX')
|
|
231
|
+
tpx.attrib['xmlns'] = "http://www.garmin.com/xmlschemas/ActivityExtension/v2"
|
|
232
|
+
watts = SubElement(tpx,'Watts')
|
|
233
|
+
try:
|
|
234
|
+
watts.text = '{s}'.format(s=int(power[i]))
|
|
235
|
+
except (ValueError, OverflowError):
|
|
236
|
+
watts.text = 'NaN'
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
notes = SubElement(activity,'Notes')
|
|
240
|
+
notes.text = '{n}'.format(n=notes)
|
|
241
|
+
|
|
242
|
+
creator = SubElement(top,'Creator')
|
|
243
|
+
name = SubElement(creator,'Name')
|
|
244
|
+
name.text = 'rowsandall.com/rowingdata'
|
|
245
|
+
|
|
246
|
+
author = SubElement(top,'Author')
|
|
247
|
+
author.attrib['xsi:type'] = 'Application_t'
|
|
248
|
+
|
|
249
|
+
name = SubElement(author,'Name')
|
|
250
|
+
name.text = 'rowingdata'
|
|
251
|
+
|
|
252
|
+
build = SubElement(author,'Build')
|
|
253
|
+
|
|
254
|
+
version = SubElement(build,'Version')
|
|
255
|
+
|
|
256
|
+
versionmajor = SubElement(version,'VersionMajor')
|
|
257
|
+
versionmajor.text = '0'
|
|
258
|
+
|
|
259
|
+
versionminor = SubElement(version,'VersionMinor')
|
|
260
|
+
versionminor.text = '75'
|
|
261
|
+
|
|
262
|
+
type = SubElement(build,'Type')
|
|
263
|
+
type.text = 'Release'
|
|
264
|
+
|
|
265
|
+
lang = SubElement(author,'LangID')
|
|
266
|
+
lang.text = 'EN'
|
|
267
|
+
|
|
268
|
+
partnumber = SubElement(author,'PartNumber')
|
|
269
|
+
partnumber.text = '000-00000-00'
|
|
270
|
+
|
|
271
|
+
return prettify(top)
|
|
272
|
+
|
|
273
|
+
def write_tcx(tcxFile,df,row_date="2016-01-01",notes="Exported by rowingdata",
|
|
274
|
+
sport="Other"):
|
|
275
|
+
|
|
276
|
+
tcxtext = create_tcx(df,row_date=row_date, notes=notes, sport=sport)
|
|
277
|
+
|
|
278
|
+
with open(tcxFile,'w') as fop:
|
|
279
|
+
fop.write(tcxtext)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
try:
|
|
283
|
+
ctx = ssl.create_default_context()
|
|
284
|
+
ctx.check_hostname = False
|
|
285
|
+
ctx.verify_mode = ssl.CERT_NONE
|
|
286
|
+
xsd_file=six.moves.urllib.request.urlopen("https://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd",context=ctx)
|
|
287
|
+
output=open('TrainingCenterDatabasev2.xsd',textwritemode)
|
|
288
|
+
if pythonversion <= 2:
|
|
289
|
+
output.write(xsd_file.read().replace('\n',''))
|
|
290
|
+
else:
|
|
291
|
+
output.write(xsd_file.read().decode('utf-8').replace('\n',''))
|
|
292
|
+
output.close()
|
|
293
|
+
xsd_filename="TrainingCenterDatabasev2.xsd"
|
|
294
|
+
|
|
295
|
+
# Run some tests
|
|
296
|
+
try:
|
|
297
|
+
tree=objectify.parse(tcxFile)
|
|
298
|
+
try:
|
|
299
|
+
schema=etree.XMLSchema(file=xsd_filename)
|
|
300
|
+
parser=objectify.makeparser(schema=schema)
|
|
301
|
+
objectify.fromstring(some_xml_string, parser)
|
|
302
|
+
except XMLSyntaxError:
|
|
303
|
+
pass
|
|
304
|
+
except:
|
|
305
|
+
pass
|
|
306
|
+
|
|
307
|
+
except six.moves.urllib.error.URLError:
|
|
308
|
+
pass
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
return 1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Sander Roosendaal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|