Last active
June 15, 2018 07:05
-
-
Save hugokernel/7baa34d581bb10430f3e5197e7b49153 to your computer and use it in GitHub Desktop.
Test fit file
This file contains hidden or 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 fitparse import FitFile | |
from collections import OrderedDict | |
import datetime | |
UTC_REFERENCE = 631065600 | |
fitfile = FitFile('lagny_fim.fit') | |
data = {} | |
for _, msg in enumerate(fitfile.get_messages('hr')): | |
if msg.header.local_mesg_num == 12: | |
last_event_timestamp = msg.get('event_timestamp').raw_value | |
raw_timestamp = msg.get('timestamp').raw_value | |
#print('raw_timestamp', raw_timestamp) | |
continue | |
timestamps = [] | |
octets = msg.get('event_timestamp_12').raw_value | |
idx = 0 | |
odd = 0 | |
while octets and idx < len(octets) - 1: | |
last_event_timestamp12 = last_event_timestamp & 0xFFF; | |
if not odd % 2: | |
next_event_timestamp12 = octets[idx] + ((octets[idx + 1] & 0xF) << 8) | |
last_event_timestamp = (last_event_timestamp & 0xFFFFF000) + next_event_timestamp12 | |
else: | |
next_event_timestamp12 = 16 * octets[idx + 1] + ((octets[idx] & 0xF0) >> 4) | |
last_event_timestamp = (last_event_timestamp & 0xFFFFF000) + next_event_timestamp12 | |
idx += 1 | |
if next_event_timestamp12 < last_event_timestamp12: | |
last_event_timestamp += 0x1000 | |
timestamps.append(UTC_REFERENCE + raw_timestamp + (last_event_timestamp / 1024.0) / 1024) | |
idx += 1 | |
odd += 1 | |
for date, hr in zip(timestamps, msg.get('filtered_bpm').value): | |
if date in data: | |
data[date].append(hr) | |
else: | |
data[date] = [hr] | |
data = {k: sum(v) / len(v) for k, v in data.items()} | |
data = OrderedDict(sorted(data.items())) | |
for date, hr in data.items(): | |
print("%s,%s" % (get_date(date), hr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment