Skip to content

Commit

Permalink
Merge pull request #69 from CTHRU/dev-5.1.0
Browse files Browse the repository at this point in the history
Version 5.1.0
  • Loading branch information
CTHRU authored Aug 31, 2021
2 parents 391b1a9 + a9b07d7 commit c8fd134
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project are documented in this file.

## Release Notes
### 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
eliminates the distance differences between Huawei Health and Strava. Note that all distances are slightly shifted to
get this result. TCX output with normalized distances has become the default mode from this version. If you prefer
using the raw calculated distances from previous versions, use the new --tcx_use_raw_distance_data command line
argument.

### Version 5.0.0 (build 2104.2801)
#### Solved Issues
- Added support for the new Huawei data format as of late April 2021. Closes #64.
Expand Down
31 changes: 28 additions & 3 deletions Hitrava.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
# Global Constants
PROGRAM_NAME = 'Hitrava'
PROGRAM_MAJOR_VERSION = '5'
PROGRAM_MINOR_VERSION = '0'
PROGRAM_MINOR_VERSION = '1'
PROGRAM_PATCH_VERSION = '0'
PROGRAM_MAJOR_BUILD = '2104'
PROGRAM_MINOR_BUILD = '2801'
PROGRAM_MAJOR_BUILD = '2108'
PROGRAM_MINOR_BUILD = '2601'

OUTPUT_DIR = './output'
GPS_TIMEOUT = dts_delta(seconds=10)
Expand Down Expand Up @@ -805,6 +805,24 @@ def get_segment_data(self, segment: dict) -> list:
segment_data = [value for (key, value) in sorted(segment_data_dict.items())]
return segment_data

def normalize_distances(self):
# Make sure segment and distance data is calculated.
segments = self.get_segments()

if self.calculated_distance == self.distance:
return

logging.getLogger(PROGRAM_NAME).debug('Normalizing distance data for activity %s', self.activity_id)

normalize_ratio = self.calculated_distance / self.distance
for n, segment in enumerate(segments):
segment['distance'] = segment['distance'] / normalize_ratio
segment_data = self.get_segment_data(segment)
if segment_data:
for data in segment_data:
if 'distance' in data:
data['distance'] = data['distance'] / normalize_ratio

def get_swim_data(self) -> Optional[list]:
if self.get_activity_type() == self.TYPE_POOL_SWIM:
if self.swim_data:
Expand Down Expand Up @@ -2005,6 +2023,11 @@ def pool_length_type(arg):
help='When an activity has altitude information, inserts the last known altitude in \
every track point of the generated TCX file.',
action='store_true')
tcx_group.add_argument('--tcx_use_raw_distance_data',
help='In JSON or ZIP mode, when using this option the converted TCX files will use the raw \
distance data as calculated from the raw HiTrack data. When not specified (default), all \
distances in the TCX files will be normalized to match the original Huawei distance.' ,
action='store_true')

output_group = parser.add_argument_group('OUTPUT options')
output_group.add_argument('--output_dir', help='The path to the directory to store the output files. The default \
Expand Down Expand Up @@ -2116,6 +2139,8 @@ def main():
for n, hi_activity in enumerate(hi_activity_list, start=1):
if args.pool_length:
hi_activity.set_pool_length(args.pool_length)
if not args.tcx_use_raw_distance_data:
hi_activity.normalize_distances()
output_file_suffix = output_file_suffix_format % (n % 1000)
tcx_activity = TcxActivity(hi_activity, tcx_xml_schema, args.output_dir, args.output_file_prefix,
output_file_suffix, args.tcx_insert_altitude_data)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ TCX options:
When an activity has altitude information, inserts the
last known altitude in every track point of the
generated TCX file.
--tcx_use_raw_distance_data
In JSON or ZIP mode, when using this option the
converted TCX files will use the raw distance data as
calculated from the raw HiTrack data. When not
specified (default), all distances in the TCX files
will be normalized to match the original Huawei
distance.
OUTPUT options:
--output_dir OUTPUT_DIR
Expand Down

0 comments on commit c8fd134

Please sign in to comment.