From e8da1e3b11bcb41f044732d66493f0372ab3edfe Mon Sep 17 00:00:00 2001 From: lowtower Date: Sun, 19 Feb 2023 11:44:38 +0100 Subject: [PATCH] Bugfix/circular drawer units (#101) * - add wheel * - bump-year to 2022 * - use given units for circular_ring_max_distance * - use given units for circular_ring_max_distance * - make use of units for max_length * - update-readme * - remove min_length, convert after assert --------- Co-authored-by: Lowtower --- LICENSE | 2 +- Makefile | 2 +- README.md | 9 +++++---- gpxtrackposter/calendar_drawer.py | 2 +- gpxtrackposter/circular_drawer.py | 23 ++++++++++++----------- gpxtrackposter/cli.py | 2 +- gpxtrackposter/exceptions.py | 2 +- gpxtrackposter/github_drawer.py | 2 +- gpxtrackposter/grid_drawer.py | 2 +- gpxtrackposter/heatmap_drawer.py | 2 +- gpxtrackposter/localization.py | 2 +- gpxtrackposter/poster.py | 2 +- gpxtrackposter/quantity_range.py | 2 +- gpxtrackposter/timezone_adjuster.py | 2 +- gpxtrackposter/track.py | 2 +- gpxtrackposter/track_loader.py | 2 +- gpxtrackposter/tracks_drawer.py | 2 +- gpxtrackposter/units.py | 2 +- gpxtrackposter/utils.py | 2 +- gpxtrackposter/value_range.py | 2 +- gpxtrackposter/xy.py | 2 +- gpxtrackposter/year_range.py | 2 +- scripts/bump_year.py | 2 +- scripts/check_copyright.py | 2 +- scripts/update_readme.py | 2 +- tests/test_timezone_adjuster.py | 2 +- tests/test_track_loader.py | 2 +- tests/test_utils.py | 2 +- 28 files changed, 43 insertions(+), 41 deletions(-) diff --git a/LICENSE b/LICENSE index bde9e53..8609a00 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2021 Florian Pigorsch & Contributors +Copyright (c) 2016-2022 Florian Pigorsch & Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index a3bc359..11b720e 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ COPYRIGHT_FILES = README.md LICENSE gpxtrackposter/*.py tests/*.py scripts/*.py .PHONY: setup setup: python3 -m venv .env - .env/bin/pip install --upgrade pip + .env/bin/pip install --upgrade pip wheel .env/bin/pip install --upgrade -r requirements.txt .env/bin/pip install --upgrade -r requirements-dev.txt .env/bin/pip install . diff --git a/README.md b/README.md index 944600e..82b88a3 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ usage: create_poster [-h] [--gpx-dir DIR] [--output FILE] [--heatmap-center LAT,LNG] [--heatmap-radius RADIUS_KM] [--heatmap-line-transparency-width TRANSP_1,WIDTH_1, TRANSP_2,WIDTH_2, TRANSP_3,WIDTH_3] [--circular-rings] [--circular-ring-color COLOR] - [--circular-ring-max-distance DISTANCE KM] + [--circular-ring-max-distance DISTANCE] optional arguments: -h, --help show this help message and exit @@ -104,8 +104,9 @@ Circular Type Options: --circular-rings Draw distance rings. --circular-ring-color COLOR Color of distance rings. - --circular-ring-max-distance DISTANCE KM - Maximum distance for scaling the track length. + --circular-ring-max-distance DISTANCE + Maximum distance for scaling the track lengths (in + given units). ``` Example: @@ -249,6 +250,6 @@ E.g. use [Poedit](https://poedit.net/) or [Localise Online Editor](https://local `msgfmt gpxposter.po -o gpxposter.mo` ## License -[MIT](https://github.com/flopp/GpxTrackPoster/blob/master/LICENSE) © 2016-2021 Florian Pigorsch +[MIT](https://github.com/flopp/GpxTrackPoster/blob/master/LICENSE) © 2016-2022 Florian Pigorsch [strava-activity-type]: https://developers.strava.com/docs/reference/#api-models-ActivityType diff --git a/gpxtrackposter/calendar_drawer.py b/gpxtrackposter/calendar_drawer.py index 7e58724..d6d5eb5 100644 --- a/gpxtrackposter/calendar_drawer.py +++ b/gpxtrackposter/calendar_drawer.py @@ -1,5 +1,5 @@ """Draw a calendar poster.""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/circular_drawer.py b/gpxtrackposter/circular_drawer.py index 8ea012d..421678f 100644 --- a/gpxtrackposter/circular_drawer.py +++ b/gpxtrackposter/circular_drawer.py @@ -1,5 +1,5 @@ """Draw a circular Poster.""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. @@ -44,6 +44,7 @@ def __init__(self, the_poster: Poster) -> None: self._rings = False self._ring_color = "darkgrey" self._max_distance = None + self._unit = Units().km def create_args(self, args_parser: argparse.ArgumentParser) -> None: """Add arguments to the parser""" @@ -65,9 +66,9 @@ def create_args(self, args_parser: argparse.ArgumentParser) -> None: group.add_argument( "--circular-ring-max-distance", dest="circular_ring_max_distance", - metavar="DISTANCE KM", + metavar="DISTANCE", type=float, - help="Maximum distance for scaling the track length.", + help="Maximum distance for scaling the track lengths (in given units).", ) def fetch_args(self, args: argparse.Namespace) -> None: @@ -75,7 +76,7 @@ def fetch_args(self, args: argparse.Namespace) -> None: self._rings = args.circular_rings self._ring_color = args.circular_ring_color if args.circular_ring_max_distance: - self._max_distance = abs(args.circular_ring_max_distance) * Units().km + self._max_distance = abs(args.circular_ring_max_distance) def draw(self, dr: svgwrite.Drawing, g: svgwrite.container.Group, size: XY, offset: XY) -> None: """Draw the circular Poster using distances broken down by time""" @@ -84,6 +85,11 @@ def draw(self, dr: svgwrite.Drawing, g: svgwrite.container.Group, size: XY, offs if self.poster.length_range_by_date is None: return + if self.poster.units == "imperial": + self._unit = Units().mile + if self._max_distance: + self._max_distance = self._max_distance * self._unit + years = self.poster.years.count() _, counts = utils.compute_grid(years, size) if counts is None: @@ -194,11 +200,7 @@ def _draw_year(self, dr: svgwrite.Drawing, g: svgwrite.container.Group, size: XY def _determine_ring_distance(self, max_length: pint.Quantity) -> typing.Optional[pint.Quantity]: ring_distance = None - if self.poster.units == "metric": - unit = Units().km - else: - unit = Units().mile - for distance in [1.0 * unit, 5.0 * unit, 10.0 * unit, 50.0 * unit]: + for distance in [1.0 * self._unit, 5.0 * self._unit, 10.0 * self._unit, 50.0 * self._unit]: if max_length < distance: continue ring_distance = distance @@ -212,12 +214,11 @@ def _draw_rings( length_range = self.poster.length_range_by_date if not length_range.is_valid(): return - min_length = length_range.lower() max_length = length_range.upper() if self._max_distance: max_length = self._max_distance - assert min_length is not None assert max_length is not None + max_length = max_length.to(self._unit) ring_distance = self._determine_ring_distance(max_length) if ring_distance is None: return diff --git a/gpxtrackposter/cli.py b/gpxtrackposter/cli.py index 528ae46..e5106f2 100755 --- a/gpxtrackposter/cli.py +++ b/gpxtrackposter/cli.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/exceptions.py b/gpxtrackposter/exceptions.py index 304ca1c..08ce234 100644 --- a/gpxtrackposter/exceptions.py +++ b/gpxtrackposter/exceptions.py @@ -1,4 +1,4 @@ -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/github_drawer.py b/gpxtrackposter/github_drawer.py index 6b513c5..274b23f 100644 --- a/gpxtrackposter/github_drawer.py +++ b/gpxtrackposter/github_drawer.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2020-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/grid_drawer.py b/gpxtrackposter/grid_drawer.py index 5b34cd7..f8d9c16 100644 --- a/gpxtrackposter/grid_drawer.py +++ b/gpxtrackposter/grid_drawer.py @@ -1,5 +1,5 @@ """Draw a grid poster.""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/heatmap_drawer.py b/gpxtrackposter/heatmap_drawer.py index 0777858..d6664df 100644 --- a/gpxtrackposter/heatmap_drawer.py +++ b/gpxtrackposter/heatmap_drawer.py @@ -1,5 +1,5 @@ """Draw a heatmap poster.""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/localization.py b/gpxtrackposter/localization.py index 676ab32..c82ba60 100644 --- a/gpxtrackposter/localization.py +++ b/gpxtrackposter/localization.py @@ -1,4 +1,4 @@ -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/poster.py b/gpxtrackposter/poster.py index e46573b..cb4a7cf 100644 --- a/gpxtrackposter/poster.py +++ b/gpxtrackposter/poster.py @@ -1,5 +1,5 @@ """Create a poster from track data.""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/quantity_range.py b/gpxtrackposter/quantity_range.py index a2e9e63..7f7be0b 100644 --- a/gpxtrackposter/quantity_range.py +++ b/gpxtrackposter/quantity_range.py @@ -1,4 +1,4 @@ -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/timezone_adjuster.py b/gpxtrackposter/timezone_adjuster.py index 9dde750..c306e8b 100644 --- a/gpxtrackposter/timezone_adjuster.py +++ b/gpxtrackposter/timezone_adjuster.py @@ -1,4 +1,4 @@ -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/track.py b/gpxtrackposter/track.py index 6556cd4..fd31834 100644 --- a/gpxtrackposter/track.py +++ b/gpxtrackposter/track.py @@ -1,5 +1,5 @@ """Create and maintain info about a given activity track (corresponding to one GPX file).""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/track_loader.py b/gpxtrackposter/track_loader.py index c1795f3..be830e5 100644 --- a/gpxtrackposter/track_loader.py +++ b/gpxtrackposter/track_loader.py @@ -1,7 +1,7 @@ """Handle parsing of GPX files and writing/loading of cached data""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/tracks_drawer.py b/gpxtrackposter/tracks_drawer.py index 50c5028..da1e536 100644 --- a/gpxtrackposter/tracks_drawer.py +++ b/gpxtrackposter/tracks_drawer.py @@ -1,5 +1,5 @@ """Contains the base class TracksDrawer, which other Drawers inherit from.""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/units.py b/gpxtrackposter/units.py index 1b5b520..937eea0 100644 --- a/gpxtrackposter/units.py +++ b/gpxtrackposter/units.py @@ -1,4 +1,4 @@ -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/utils.py b/gpxtrackposter/utils.py index 7e0a559..b0d76db 100644 --- a/gpxtrackposter/utils.py +++ b/gpxtrackposter/utils.py @@ -1,5 +1,5 @@ """Assorted utility methods for use in creating posters.""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/value_range.py b/gpxtrackposter/value_range.py index 077b6dd..0e5f04a 100644 --- a/gpxtrackposter/value_range.py +++ b/gpxtrackposter/value_range.py @@ -1,5 +1,5 @@ """Represent a range of numerical values""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/xy.py b/gpxtrackposter/xy.py index 9712fce..385a888 100644 --- a/gpxtrackposter/xy.py +++ b/gpxtrackposter/xy.py @@ -1,5 +1,5 @@ """Represent x,y coords with properly overloaded operations.""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/gpxtrackposter/year_range.py b/gpxtrackposter/year_range.py index fd7c602..2c57c2b 100644 --- a/gpxtrackposter/year_range.py +++ b/gpxtrackposter/year_range.py @@ -1,5 +1,5 @@ """Represent a range of years, with ability to update based on a track""" -# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/scripts/bump_year.py b/scripts/bump_year.py index 763c1e4..179046b 100755 --- a/scripts/bump_year.py +++ b/scripts/bump_year.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2018-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2018-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/scripts/check_copyright.py b/scripts/check_copyright.py index c676d68..e62ceea 100755 --- a/scripts/check_copyright.py +++ b/scripts/check_copyright.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2018-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2018-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/scripts/update_readme.py b/scripts/update_readme.py index a181efd..4c9d628 100755 --- a/scripts/update_readme.py +++ b/scripts/update_readme.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2018-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2018-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/tests/test_timezone_adjuster.py b/tests/test_timezone_adjuster.py index b1c777f..4805a23 100644 --- a/tests/test_timezone_adjuster.py +++ b/tests/test_timezone_adjuster.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2020-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/tests/test_track_loader.py b/tests/test_track_loader.py index c6e9fd8..0d6301a 100644 --- a/tests/test_track_loader.py +++ b/tests/test_track_loader.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2020-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file. diff --git a/tests/test_utils.py b/tests/test_utils.py index 5ff48ce..e5e0ccd 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,4 @@ -# Copyright 2018-2021 Florian Pigorsch & Contributors. All rights reserved. +# Copyright 2018-2022 Florian Pigorsch & Contributors. All rights reserved. # # Use of this source code is governed by a MIT-style # license that can be found in the LICENSE file.