From b4d2e77f43ef35ce481e5fe44a6fc7c758bf34fa Mon Sep 17 00:00:00 2001 From: Christoph Vanthuyne <52134985+CTHRU@users.noreply.github.com> Date: Mon, 25 Jul 2022 12:56:46 +0200 Subject: [PATCH 1/5] Version 5.1.1 # New features and changes - Added support for conversion of activities with dummy location (start) records. # Solved Issues - Conversion could fail in case of activities without any distance information (i.e. the calculated distance was zero). --- Hitrava.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Hitrava.py b/Hitrava.py index 9d4117b..fc5011f 100644 --- a/Hitrava.py +++ b/Hitrava.py @@ -51,9 +51,9 @@ PROGRAM_NAME = 'Hitrava' PROGRAM_MAJOR_VERSION = '5' PROGRAM_MINOR_VERSION = '1' -PROGRAM_PATCH_VERSION = '0' -PROGRAM_MAJOR_BUILD = '2108' -PROGRAM_MINOR_BUILD = '2601' +PROGRAM_PATCH_VERSION = '1' +PROGRAM_MAJOR_BUILD = '2207' +PROGRAM_MINOR_BUILD = '2501' OUTPUT_DIR = './output' GPS_TIMEOUT = dts_delta(seconds=10) @@ -81,7 +81,7 @@ class HiActivity: TYPE_MOUNTAIN_HIKE, TYPE_INDOOR_RUN, TYPE_INDOOR_CYCLE, TYPE_CROSS_TRAINER, TYPE_OTHER, TYPE_CROSSFIT, TYPE_CROSS_COUNTRY_RUN) - def __init__(self, activity_id: str, activity_type: str = TYPE_UNKNOWN, timestamp_ref: datetime = None): + def __init__(self, activity_id: str, activity_type: str = TYPE_UNKNOWN, timestamp_ref: datetime = None, start_timestamp_ref: datetime = None): logging.getLogger(PROGRAM_NAME).debug('New HiTrack activity to process <%s>', activity_id) self.activity_id = activity_id @@ -122,6 +122,7 @@ def __init__(self, activity_id: str, activity_type: str = TYPE_UNKNOWN, timestam self.last_swolf_data = None self.timestamp_ref = timestamp_ref + self.start_timestamp_ref = start_timestamp_ref @classmethod def from_json_pool_swim_data(cls, activity_id: str, start: datetime, json_pool_swim_dict): @@ -271,6 +272,11 @@ def add_location_data(self, data: []): if location_data['t'] == 0 and location_data['lat'] == 90 and location_data['lon'] == -80: # Pause/stop record without a valid epoch timestamp. Set it to the last timestamp recorded location_data['t'] = self.stop + elif location_data['t'] == 0 and location_data['lat'] == 0 and location_data['lon'] == 0: + # Exception (Guess) - this type of record seems to be generated once at the start of the activtiy when no GPS data is available. + # Set the start timestamp (only possible in case of json or zip conversion). + logging.getLogger(PROGRAM_NAME).debug('Found zero location record. Setting activity start to reference %s', self.start_timestamp_ref) + self.start = self.start_timestamp_ref else: # Regular location record or pause/stop record with valid epoch timestamp or seconds since start of day. # Convert the timestamp to a datetime @@ -809,7 +815,7 @@ def normalize_distances(self): # Make sure segment and distance data is calculated. segments = self.get_segments() - if self.calculated_distance == self.distance: + if self.calculated_distance == 0 or self.distance == 0 or self.calculated_distance == self.distance: return logging.getLogger(PROGRAM_NAME).debug('Normalizing distance data for activity %s', self.activity_id) @@ -949,7 +955,7 @@ class HiTrackFile: """The HiTrackFile class represents a single HiTrack file. It contains all file handling and parsing methods.""" def __init__(self, hitrack_filename: str, activity_type: str = HiActivity.TYPE_UNKNOWN, - timestamp_ref: datetime = None): + timestamp_ref: datetime = None, start_timestamp_ref: datetime = None): # Validate the file parameter and (try to) open the file for reading if not hitrack_filename: logging.getLogger(PROGRAM_NAME).error('Parameter HiTrack filename is missing') @@ -980,6 +986,9 @@ def __init__(self, hitrack_filename: str, activity_type: str = HiActivity.TYPE_U # Timestamp reference for calculating offset timestamp values in the HiTrack data self.timestamp_ref = timestamp_ref + # Start timestamp reference for calculating real start timestamp in case of exception tp=lbs record with all zeros. + self.start_timestamp_ref = start_timestamp_ref + def parse(self) -> HiActivity: """ Parses the HiTrack file and returns the parsed data in a HiActivity object @@ -991,7 +1000,11 @@ def parse(self) -> HiActivity: logging.getLogger(PROGRAM_NAME).info('Parsing file <%s>', self.hitrack_file.name) # Create a new activity object for the file - self.activity = HiActivity(os.path.basename(self.hitrack_file.name), self.activity_type, self.timestamp_ref) + self.activity = HiActivity( + os.path.basename(self.hitrack_file.name), + self.activity_type, + self.timestamp_ref, + self.start_timestamp_ref) data_list = [] line_number = 0 @@ -1405,7 +1418,7 @@ def _parse_activity(self, activity_dict: dict) -> HiActivity: month=activity_start.month, day=activity_start.day) - hitrack_file = HiTrackFile(hitrack_filename, timestamp_ref=timestamp_ref) + hitrack_file = HiTrackFile(hitrack_filename, timestamp_ref=timestamp_ref, start_timestamp_ref=activity_start) hi_activity = hitrack_file.parse() if sport != HiActivity.TYPE_UNKNOWN: hi_activity.set_activity_type(sport) From 86512114a8c51e57c4676a7f3efd110ef620ce38 Mon Sep 17 00:00:00 2001 From: Christoph Vanthuyne <52134985+CTHRU@users.noreply.github.com> Date: Mon, 25 Jul 2022 12:57:39 +0200 Subject: [PATCH 2/5] Version 5.1.1 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 898a440..687327f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project are documented in this file. ## Release Notes +### Version 5.1.1 (build 2207.2501) +#### New features and changes +- Added support for conversion of activities with dummy location (start) records. + +#### Solved Issues +- Conversion could fail in case of activities without any distance information (i.e. the calculated distance was zero). + ### Version 5.1.0 (build 2108.2601) #### New features and changes - JSON and ZIP conversion: Added normalization to all distances calculated from the raw Hitrack data. This From bc488a4f7b7750c69d7b7358d06c90325f40c756 Mon Sep 17 00:00:00 2001 From: Christoph Vanthuyne <52134985+CTHRU@users.noreply.github.com> Date: Tue, 26 Jul 2022 15:08:38 +0200 Subject: [PATCH 3/5] Version 5.1.1 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a5e0be9..60df664 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,10 @@ [![nposl3.0][shield nposl3.0]][tldrlegal nposl3.0] [![GitHub release (latest by date)][shield release]][latest release] [![GitHub Release Date][shield release date]][latest release] +[![PayPal][shield paypal]][paypal] [![Buy me a coffee][shield buymeacoffee]][buymeacoffee] + ---------- ## Introduction Hitrava converts health activities registered using a Honor or Huawei activity tracker or smart watch in the @@ -377,3 +379,5 @@ If you're more into a TL;DR approach, start [`here`][tldrlegal nposl3.0]. [latest release]: https://github.com/CTHRU/Hitrava/releases/latest [shield buymeacoffee]: https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg [buymeacoffee]: https://www.buymeacoffee.com/CTHRU +[shield paypal]: https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif +[paypal]: https://www.paypal.com/donate/?hosted_button_id=SSSHR299GZEKQ From 0a398f2de19241923bec47acee1b2b1db50b400e Mon Sep 17 00:00:00 2001 From: Christoph Vanthuyne <52134985+CTHRU@users.noreply.github.com> Date: Tue, 26 Jul 2022 15:12:55 +0200 Subject: [PATCH 4/5] Version 5.1.1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60df664..2f51725 100644 --- a/README.md +++ b/README.md @@ -363,7 +363,7 @@ For a full changelog of all versions, please look in [`CHANGELOG.md`](./CHANGELO ## Copyright and License [![nposl3.0][shield nposl3.0]][tldrlegal nposl3.0] -Copyright (c) 2019-2020 Christoph Vanthuyne +Copyright (c) 2019-2022 Christoph Vanthuyne Licensed under the Non-Profit Open Software License version 3.0 from Hitrava version 3.1.1 onward. From 9ac91ac8ad127ab2bc61fdd8ba0434106b97e135 Mon Sep 17 00:00:00 2001 From: Christoph Vanthuyne <52134985+CTHRU@users.noreply.github.com> Date: Tue, 26 Jul 2022 15:13:31 +0200 Subject: [PATCH 5/5] Update LICENSE.md --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index 31e64ac..dd3ee89 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ Non-Profit Open Software License 3.0 (NPOSL-3.0) -Copyright (c) 2019-2020 Christoph Vanthuyne +Copyright (c) 2019-2022 Christoph Vanthuyne This Non-Profit Open Software License ("Non-Profit OSL") version 3.0 (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: