Data cannot be decoded successfully in Python SDK

Former Member
Former Member

Hi

I'm a Python SDK user.
I'm trying to extract my monitoring messages from .fit data by streaming.
When I read a .fit file contents from the decoder, the output messages do not have as many records as expected.

I found that some values in `target_field.type` field in my record file are `activity_type`, and it is not included in `FIELD_TYPE_TO_BASE_TYPE`.
so, the decode function maybe forced to finish and remaining records are not handled anymore.

The code is L448 in "decoder.py" (at 2023/2/1).
https://github.com/garmin/fit-python-sdk/blob/main/garmin_fit_sdk/decoder.py#L448

Could you check it, please?
Thank you!

  • Sorry, I meant to edit my second reply and deleted the entire thread :-(

    I missed that the current_activity_type_intensity field expands in to the activity_type field. activity_type is one of two expansion fields that are enums and it does not look like the Python SDK (or the JavaScript SDK) is handling that scenario very well.

    At a minimum the value of base_type needs to be checked to see if it is set to None before using it. That will keep the decoder from, presumable, crashing. Are you getting an error back? If so what it is?

    The other thing to try is adding 
    "activity_type": BASE_TYPE['UINT8'] to the FIELD_TYPE_TO_BASE_TYPE dictionary. __expand_components is called before_transform_values, and it is in _transform_values where the raw uint8 value is converted to the enum value. We can take a look at that this month.

  • A short term work around, while we look into this, is to disable component expansion. You can do this by passing "expand_sub_fields = False" to the read method. All of the options for the read method are listed here, along with an example of disabling component expansion.
    https://developer.garmin.com/fit/example-projects/python/

    If activity_type and intensity are values that you need for your project, then you can manually split the current_activity_type_intensity value into activity_type and intensity. Activity_type is the 5 LSB and intensity is the 3 MSB.

  • Former Member
    0 Former Member over 2 years ago in reply to Ben FIT

    The error is "KeyError('activity_type')".

    Thank you, but the work around does not work in this case.
    It still raise the same error.

    I just overrode the `__expand_components` method to avoid the KeyError.
    It uses `invalid_value = None` if the `type` is `activity_type`.
    I'm currently interested in another field, so it's OK just to avoid KeyError and continue the entire process.

    Your second proposal to split `current_activity_type_intensity` would also work, though i did not try.

  • We released v21.107 to PyPI today. There is a fix in this version for when the target of a component expansion is an enum type.


    You can see the unit test that matches your use-case here: 
    https://github.com/garmin/fit-python-sdk/blob/main/tests/test_decoder.py#L383

    Let us know if this resolves the issue for you.

  • Former Member
    0 Former Member over 2 years ago in reply to Ben FIT

    Thank you for your quick fix and release!!
    I checked the fixed version by running my scripts, and it worked successfully!

    This issue was resolved for me.
    Thank you!