-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamp_16 support #46
Comments
As an FYI for testing this there is already a file that has these |
Any progress on this issue? I am struggling to make sense of heartrate records which utilize timestamp_16. |
Hi @buma, I seem to be doing something wrong. How should fix_times be called? for message in fix_times(fitfile.get_messages()):
ts = message.get_value('timestamp_16')
if ts:
print ts
Traceback (most recent call last):
File "/home/bs/.local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2878, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-64-a1a3e382974a>", line 1, in <module>
for message in fix_times(fitfile.get_messages()):
File "<ipython-input-25-b548c6307590>", line 33, in fix_times
FieldData(
NameError: global name 'FieldData' is not defined |
Happy to test any updated code. |
Hello! Happy to see this discussed here :) I downloaded my heart rate data recorded on May 1st 2019 from the Garmin Connect web page, i.e. the first data point is at 12AM. Looping through the
Following the instructions linked above, I set
but as a result of the above formula I get
which is wrong! Has anyone found a fix to this? |
I tried to look at things in detail going step by step in the above formula:
and, as before the result is wrong by more than 12 hours. Also, the instructions say
but the final result is not a 32-bit variable in which the first 16 are from the original On the other hand I tried to build it by hand, and I get the final binary variable as:
which then translates to this datetime:
which, again, is wrong :\ but different from before! |
Does this maybe help? |
thanks @tuxinaut ! I tried it but I still get a sizeable difference, i.e.: On the other hand I browsed the details of the code and I see that the UTC offset shift due to Garmin's different starting time is applied to Following this hypothesis I tried to work with raw
The result is [here is the full notebook, just search for "925596000"] This is the closest I got so far to the right result, and it is shifted only by one hour (the minute might be due to the granularity of the data) which might now be a timezone related issue. What do you think @dtcooper ? |
@francescolosterzo really cool work 👍 and yes I'm pretty sure that's timezone related (take a look on the code below)
|
This is what I came up with after reading this thread. The generated timestamps and bpms are in line with the data in Garming Connect. import fitparse
from datetime import datetime, timezone
from glob import glob
garmin_epoch = int(datetime.timestamp(datetime(1989, 12, 31, tzinfo=timezone.utc)))
files = sorted(glob("2023-10-25/*WELLNESS*.fit"))
for f in files:
fitfile = fitparse.FitFile(f)
last_timestamp = None
for m in fitfile.get_messages("monitoring"):
last_timestamp = m.get_raw_value("timestamp") or last_timestamp
heart_rate = m.get_raw_value("heart_rate")
timestamp16 = m.get_raw_value("timestamp_16")
if last_timestamp and heart_rate and timestamp16:
timestamp = last_timestamp
timestamp += (timestamp16 - (last_timestamp & 0xFFFF)) & 0xFFFF
date = datetime.fromtimestamp(garmin_epoch + timestamp, tz=timezone.utc)
print(date.astimezone().strftime("%Y-%m-%dT%H:%M:%S %Z"), heart_rate)
|
Currently in FIT we have timestamps which are 32bit and timestamp_16 which are 16bit difference from previous timestamp and are currently not read into nice values.
I wrote generator function based on ParseVivosmartHR. Here seems to be offical function how to do it (in Java):
It works but it definitely isn't written as it should, but I don't know fitparse enough to improve it.
The text was updated successfully, but these errors were encountered: