diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-03-29 19:04:12 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-03-29 19:04:12 +0200 |
commit | 66444356a76370ec9c1a5b15576b48ff63bbbed3 (patch) | |
tree | 6c29cb6e9f6157f7a923e00b518a4f48fbd30e33 | |
parent | 71353f58ba124cff889dffcaf0993e1df72e5067 (diff) | |
download | fietsboek-66444356a76370ec9c1a5b15576b48ff63bbbed3.tar.gz fietsboek-66444356a76370ec9c1a5b15576b48ff63bbbed3.tar.bz2 fietsboek-66444356a76370ec9c1a5b15576b48ff63bbbed3.zip |
profile: show longest duration & duration tracks
-rw-r--r-- | fietsboek/models/track.py | 13 | ||||
-rw-r--r-- | fietsboek/templates/profile.jinja2 | 10 | ||||
-rw-r--r-- | fietsboek/views/profile.py | 19 |
3 files changed, 42 insertions, 0 deletions
diff --git a/fietsboek/models/track.py b/fietsboek/models/track.py index e0d2820..4b85d11 100644 --- a/fietsboek/models/track.py +++ b/fietsboek/models/track.py @@ -550,6 +550,19 @@ class TrackWithMetadata: return self._meta()["end_time"] return self.cache.end_time + @property + def duration(self) -> datetime.timedelta: + """Returns the duration of this track. + + This is equivalent to ``end_time - start_time``, given that + no DST change happens between those points. + + Alternatively, it is equivalent to ``moving_time + stopped_time``. + + :return: The track duration. + """ + return self.end_time - self.start_time + def html_tooltip(self, localizer: Localizer) -> Markup: """Generate a quick summary of the track as a HTML element. diff --git a/fietsboek/templates/profile.jinja2 b/fietsboek/templates/profile.jinja2 index fe49990..4906247 100644 --- a/fietsboek/templates/profile.jinja2 +++ b/fietsboek/templates/profile.jinja2 @@ -105,6 +105,16 @@ <h2>{{ _("page.profile.shortest_distance_track") }}</h2> {{ render_track_card(total.shortest_distance_track) }} {% endif %} + + {% if total.longest_duration_track %} + <h2>{{ _("page.profile.longest_duration_track") }}</h2> + {{ render_track_card(total.longest_duration_track) }} + {% endif %} + + {% if total.shortest_duration_track %} + <h2>{{ _("page.profile.shortest_duration_track") }}</h2> + {{ render_track_card(total.shortest_duration_track) }} + {% endif %} </div> {% endblock %} diff --git a/fietsboek/views/profile.py b/fietsboek/views/profile.py index f7b1d79..bf1475c 100644 --- a/fietsboek/views/profile.py +++ b/fietsboek/views/profile.py @@ -23,6 +23,7 @@ class CumulativeStats: The values start out with default values, and tracks can be merged in via :meth:`add`. """ + # pylint: disable=too-many-instance-attributes count: int = 0 """Number of tracks added.""" @@ -51,6 +52,12 @@ class CumulativeStats: shortest_distance_track: Optional[TrackWithMetadata] = None """The track with the shortest distance.""" + longest_duration_track: Optional[TrackWithMetadata] = None + """The track with the longest time.""" + + shortest_duration_track: Optional[TrackWithMetadata] = None + """The track with the shortest time.""" + def add(self, track: TrackWithMetadata): """Adds a track to this stats collection. @@ -76,6 +83,18 @@ class CumulativeStats: ): self.shortest_distance_track = track + if ( + self.longest_duration_track is None + or self.longest_duration_track.duration < track.duration + ): + self.longest_duration_track = track + + if ( + self.shortest_duration_track is None + or self.shortest_duration_track.duration > track.duration + ): + self.shortest_duration_track = track + @property def avg_speed(self) -> float: """Average speed, in m/s.""" |