Skip to content

Commit

Permalink
Merge pull request #70 from CTHRU/dev-5.1.1
Browse files Browse the repository at this point in the history
Version 5.1.1
  • Loading branch information
CTHRU authored Jul 26, 2022
2 parents 51da841 + 9ac91ac commit 12f5b48
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions Hitrava.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -361,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.

Expand All @@ -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

0 comments on commit 12f5b48

Please sign in to comment.