|
42 | 42 | "formats": ["i", "S4", "S32", "S32", "S8"],
|
43 | 43 | }
|
44 | 44 | )
|
| 45 | +FitTypeHRT = np.dtype( |
| 46 | + { |
| 47 | + "names": [ |
| 48 | + "time", |
| 49 | + "bpm", |
| 50 | + ], # unix timestamp, heart bpm |
| 51 | + "formats": ["i", "S4"], |
| 52 | + } |
| 53 | +) |
45 | 54 |
|
46 | 55 | # device info
|
47 | 56 | user_agent = "CodoonSport(8.9.0 1170;Android 7;Sony XZ1)"
|
@@ -192,14 +201,14 @@ def tcx_output(fit_array, run_data):
|
192 | 201 | # HeartRateBpm
|
193 | 202 | # None was converted to bytes by np.dtype, becoming a string "None" after decode...-_-
|
194 | 203 | # as well as LatitudeDegrees and LongitudeDegrees below
|
195 |
| - if not bytes.decode(i["bpm"]) == "None": |
| 204 | + if "bpm" in i and not bytes.decode(i["bpm"]) == "None": |
196 | 205 | bpm = ET.Element("HeartRateBpm")
|
197 | 206 | bpm_value = ET.Element("Value")
|
198 | 207 | bpm.append(bpm_value)
|
199 | 208 | bpm_value.text = bytes.decode(i["bpm"])
|
200 | 209 | tp.append(bpm)
|
201 | 210 | # Position
|
202 |
| - if not bytes.decode(i["lati"]) == "None": |
| 211 | + if "lati" in i and not bytes.decode(i["lati"]) == "None": |
203 | 212 | position = ET.Element("Position")
|
204 | 213 | tp.append(position)
|
205 | 214 | # LatitudeDegrees
|
@@ -278,13 +287,26 @@ def tcx_job(run_data):
|
278 | 287 | hr = fit_hrs.get(unix_time, None)
|
279 | 288 |
|
280 | 289 | fit_list.append((unix_time, hr, latitude, longitude, elevation))
|
281 |
| - |
282 |
| - if fit_list: |
| 290 | + elif fit_hrs: |
| 291 | + # only heart rates |
| 292 | + print("No track points, only heart rates " + str(run_data["id"])) |
| 293 | + for unix_time, hr in fit_hrs.items(): |
| 294 | + fit_list.append((unix_time, hr)) |
| 295 | + |
| 296 | + if len(own_points) > 0 and fit_list: |
| 297 | + # track points |
283 | 298 | fit_array = np.array(fit_list, dtype=FitType)
|
284 | 299 | # order array
|
285 | 300 | fit_array = np.sort(fit_array, order="time")
|
286 | 301 | # write to TCX file
|
287 | 302 | tcx_output(fit_array, run_data)
|
| 303 | + elif len(own_points) == 0 and fit_hrs and fit_list: |
| 304 | + # only heart rate |
| 305 | + fit_array = np.array(fit_list, dtype=FitTypeHRT) |
| 306 | + # order array |
| 307 | + fit_array = np.sort(fit_array, order="time") |
| 308 | + # write to TCX file |
| 309 | + tcx_output(fit_array, run_data) |
288 | 310 | else:
|
289 | 311 | print("No data in " + str(run_data["id"]))
|
290 | 312 |
|
|
0 commit comments