1.2. processors

fitdecode.processors.FIT_UTC_REFERENCE = 631065600

Datetimes (uint32) represent seconds since this FIT_UTC_REFERENCE (unix timestamp for UTC 00:00 Dec 31 1989).

fitdecode.processors.FIT_DATETIME_MIN = 268435456

date_time typed fields for which value is below FIT_DATETIME_MIN represent the number of seconds elapsed since device power on.

class fitdecode.processors.DataProcessorBase

Data processing base class.

This class does nothing. It is meant to be derived.

The following methods are called by fitdecode.FitReader:

  • on_header, each time a fitdecode.FitHeader is reached

  • on_crc, each time a fitdecode.FitCRC (the FIT footer) is reached

This is convenient if you wish to reset some context-sensitive state in- between two chained FIT files for example.

Bear in mind that a malformed/corrupted file may miss either of these entities (header and/or CRC footer).

Also, the following methods are called (still by fitdecode.FitReader) for each field of every data message, in that order:

By default, the above processor methods call the following methods if they exist (hence the aforementioned caching):

def process_type_<type_name>(reader, field_data)
def process_field_<field_name>(reader, field_data)  # could be unknown_XYZ but NOT recommended  # noqa
def process_units_<unit_name>(reader, field_data)
def process_message_<mesg_name>(reader, data_message)

process_* methods are not expected to return any value and may alter the content of the passed field_data (fitdecode.FieldData) and data_message (fitdecode.FitDataMessage) arguments if needed.

on_header(reader, fit_header)
on_crc(reader, fit_crc)
on_process_type(reader, field_data)
on_process_field(reader, field_data)
on_process_unit(reader, field_data)
on_process_message(reader, data_message)
class fitdecode.processors.DefaultDataProcessor

This is the default data processor used by fitdecode.FitReader. It derives from DataProcessorBase.

This data processor converts some raw values to more comfortable ones.

process_type_bool(reader, field_data)

Just bool any bool typed FIT field unless value is None

process_type_date_time(reader, field_data)

Convert date_time typed field values into datetime.datetime object if possible.

That is, if value is not None and greater or equal than FIT_DATETIME_MIN.

The resulting datetime.datetime object is timezone-aware (UTC).

process_type_local_date_time(reader, field_data)

Convert date_time typed field values into datetime.datetime object unless value is None.

The resulting datetime.datetime object IS NOT timezone-aware, but this method assumes UTC at object construction to ensure consistency.

process_type_localtime_into_day(reader, field_data)

Convert localtime_into_day typed field values into datetime.time object unless value is None.

process_message_hr(reader, data_message)

Convert populated event_timestamp component values of the hr to datetime.datetime objects

class fitdecode.processors.StandardUnitsDataProcessor

A DefaultDataProcessor that also:

  • Converts distance and total_distance fields to km (standard’s default is m)

  • Converts all speed and *_speeds fields (by name) to km/h (standard’s default is m/s)

  • Converts GPS coordinates (i.e. FIT’s semicircles type) to deg

on_process_field(reader, field_data)

Convert all *_speed fields using process_field_speed.

All other units will use the default method.

process_field_distance(reader, field_data)
process_field_total_distance(reader, field_data)
process_field_speed(reader, field_data)
process_units_semicircles(reader, field_data)