-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General/API Cleanups and Added Data Processors
* Added custom data processor classes where the following methods are called on a per value basis - process_type_<type_name>(field_data) - process_field_<field_name>(field_data) - def process_message_<mesg_name>(data_message) * Updated profile.py and its data structures in record.py to leave out values in its `__init__` method and have None by default. (Updated profile export script as well) * Tweaked `__str__`/`__repr__` methods on records.py classes * Minor Refactor For Timestamp Field and Record Base Class * Made the argparse module a `setup.py`/pip requirement for Python 2.6 and lower in anticipation in using it for the fitdump script.
- Loading branch information
Showing
9 changed files
with
190 additions
and
1,983 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
from fitparse.base import FitFile, FitParseError | ||
from fitparse.processors import FitFileDataProcessor, StandardUnitsDataProcessor | ||
|
||
|
||
__version__ = '0.0.1-dev' | ||
__all__ = ['FitFile', 'FitParseError'] | ||
__all__ = [ | ||
'FitFileDataProcessor', 'FitFile', 'FitParseError', | ||
'StandardUnitsDataProcessor', | ||
] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import datetime | ||
|
||
|
||
class FitFileDataProcessor(object): | ||
# TODO: Document API | ||
#def process_type_<type_name> (field_data) | ||
#def process_field_<field_name> (field_data) -- can be unknown_DD but NOT recommended | ||
#def process_message_<mesg_name / mesg_type_num> (data_message) | ||
|
||
def process_type_bool(self, field_data): | ||
if field_data.value is not None: | ||
field_data.value = bool(field_data.value) | ||
|
||
def process_type_date_time(self, field_data): | ||
value = field_data.value | ||
if value is not None and value >= 0x10000000: | ||
field_data.value = datetime.datetime.utcfromtimestamp(631065600 + value) | ||
field_data.units = None # Units were 's', set to None | ||
|
||
def process_type_local_date_time(self, field_data): | ||
if field_data.value is not None: | ||
field_data.value = datetime.datetime.fromtimestamp(631065600 + field_data.value) | ||
field_data.units = None | ||
|
||
|
||
class StandardUnitsDataProcessor(FitFileDataProcessor): | ||
# Example use case | ||
def process_field_distance(self, field_data): | ||
if field_data.value is not None: | ||
field_data.value /= 1000.0 | ||
field_data.units = 'km' | ||
|
||
def process_field_speed(self, field_data): | ||
if field_data.value is not None: | ||
field_data.value *= 60.0 * 60.0 / 1000.0 | ||
field_data.units = 'km/h' | ||
|
||
def process_field_position_lat(self, field_data): | ||
if field_data.value is not None: | ||
field_data.value *= 180.0 / (2 ** 31) | ||
field_data.units = 'deg' | ||
process_field_position_long = process_field_position_lat |
Oops, something went wrong.