-
Notifications
You must be signed in to change notification settings - Fork 185
Problem on timestamp extraction #69
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Same issue here with an HRM-Tri strap. I stumbled upon a working example after some head scratching: from fitparse import FitFile
fitfile = FitFile('lagny_fim.fit')
for _, msg in enumerate(fitfile.get_messages('hr')):
if msg.header.local_mesg_num == 12:
last_event_timestamp = msg.get('event_timestamp').raw_value
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(last_event_timestamp / 1024.0)
idx += 1
odd += 1
print('%s,%s' % (
'|'.join(str(bpm) for bpm in msg.get('filtered_bpm').value),
'|'.join(str(t) for t in timestamps)
)) The way I understand how There seem to be 2 issues here:
EDIT: improved code to avoid overflow errors (logic from GoldenCheetah) |
I will try that as soon as possible. |
Hi polyvertex, |
Hey @pdura, Regarding the timestamps, fitparse, makes them available to you. |
Hi,
I work on a tool to extract data from Swimming Strap HRM from fit files and when I try to display data as chart, I see big difference between real chart (from Garmin Connect) and data extracted from fit-parse.
After investigation, I found a difference in the fitparse timestamp calculation compared to same data extracted from the Garmin FitCSVTool.
First 4 lines of Strap HRM data extracted with Garmin FitCSVTool (format: filtered_bpm, event_timestamp) :
I use this code to extract and format data :
Data extracted with this script :
As you ca see, there are an error of +2 seconds on calculated timestamp and maybe other errors that occur in the extraction that would explain the overall errors in extracting heart rate data.
Do you have an idea of what can happen?
Am I making a mistake in extracting data?
I can provide the original fit file for investigation.
Thank you.
The text was updated successfully, but these errors were encountered: