diff options
-rw-r--r-- | fietsboek/templates/profile.jinja2 | 80 | ||||
-rw-r--r-- | fietsboek/views/profile.py | 31 |
2 files changed, 95 insertions, 16 deletions
diff --git a/fietsboek/templates/profile.jinja2 b/fietsboek/templates/profile.jinja2 index 516cee9..fe49990 100644 --- a/fietsboek/templates/profile.jinja2 +++ b/fietsboek/templates/profile.jinja2 @@ -1,5 +1,59 @@ {% extends "layout.jinja2" %} +{% macro render_track_card(track) %} + <div class="card mb-3"> + <h5 class="card-header"> + <a href="{{ request.route_url('details', track_id=track.id) }}">{{ track.title | default(track.date, true) }}</a> + {% if track.text_tags() %} + {% for tag in track.tags %}<span class="badge bg-info text-dark">{{ tag.tag }}</span> {% endfor %} + {% endif %} + </h5> + <div class="card-body"> + <table class="table table-hover table-sm browse-summary"> + <tbody> + <tr> + <th scope="row">{{ _("page.details.date") }}</th> + <td>{{ track.date | format_datetime }}</td> + <th scope="row">{{ _("page.details.length") }}</th> + <td>{{ (track.length / 1000) | round(2) | format_decimal }} km</td> + </tr> + <tr> + <th scope="row">{{ _("page.details.start_time") }}</th> + <td>{{ track.start_time | format_datetime }}</td> + <th scope="row">{{ _("page.details.end_time") }}</th> + <td>{{ track.end_time | format_datetime }}</td> + </tr> + <tr> + <th scope="row">{{ _("page.details.uphill") }}</th> + <td>{{ track.uphill | round(2) | format_decimal }} m</td> + <th scope="row">{{ _("page.details.downhill") }}</th> + <td>{{ track.downhill | round(2) | format_decimal }} m</td> + </tr> + <tr> + <th scope="row">{{ _("page.details.moving_time") }}</th> + <td>{{ track.moving_time }}</td> + <th scope="row">{{ _("page.details.stopped_time") }}</th> + <td>{{ track.stopped_time }}</td> + </tr> + <tr> + <th scope="row">{{ _("page.details.max_speed") }}</th> + <td>{{ mps_to_kph(track.max_speed) | round(2) | format_decimal }} km/h</td> + <th scope="row">{{ _("page.details.avg_speed") }}</th> + <td>{{ mps_to_kph(track.avg_speed) | round(2) | format_decimal }} km/h</td> + </tr> + </tbody> + </table> + + <ul> + <li>{{ track.owner.name }}</li> + {% for user in track.tagged_people %} + <li>{{ user.name }}</li> + {% endfor %} + </ul> + </div> + </div> +{% endmacro %} + {% block content %} <div class="container"> <h1>{{ user.name }}</h1> @@ -10,37 +64,47 @@ <table class="table table-hover table-sm"> <th scope="row">{{ _("page.profile.length") }}</th> - <td id="profileLength">{{ (total_length / 1000) | round(2) | format_decimal }} km</td> + <td id="profileLength">{{ (total.length / 1000) | round(2) | format_decimal }} km</td> </tr> <tr> <th scope="row">{{ _("page.profile.uphill") }}</th> - <td id="profileUphill">{{ total_uphill | round(2) | format_decimal }} m</td> + <td id="profileUphill">{{ total.uphill | round(2) | format_decimal }} m</td> </tr> <tr> <th scope="row">{{ _("page.profile.downhill") }}</th> - <td id="profileDownhill">{{ total_downhill | round(2) | format_decimal }} m</td> + <td id="profileDownhill">{{ total.downhill | round(2) | format_decimal }} m</td> </tr> <tr> <th scope="row">{{ _("page.profile.moving_time") }}</th> - <td id="profileMovingTime">{{ total_moving_time }}</td> + <td id="profileMovingTime">{{ total.moving_time }}</td> </tr> <tr> <th scope="row">{{ _("page.profile.stopped_time") }}</th> - <td id="profileStoppedTime">{{ total_stopped_time }}</td> + <td id="profileStoppedTime">{{ total.stopped_time }}</td> </tr> <tr> <th scope="row">{{ _("page.profile.max_speed") }}</th> - <td id="profileMaxSpeed">{{ mps_to_kph(max_speed) | round(2) | format_decimal }} km/h</td> + <td id="profileMaxSpeed">{{ mps_to_kph(total.max_speed) | round(2) | format_decimal }} km/h</td> </tr> <tr> <th scope="row">{{ _("page.profile.avg_speed") }}</th> - <td id="profileAvgSpeed">{{ mps_to_kph(avg_speed) | round(2) | format_decimal }} km/h</td> + <td id="profileAvgSpeed">{{ mps_to_kph(total.avg_speed) | round(2) | format_decimal }} km/h</td> </tr> <tr> <th scope="row">{{ _("page.profile.number_of_tracks") }}</th> - <td id="profileNumberOfTracks">{{ number_of_tracks }}</td> + <td id="profileNumberOfTracks">{{ total.count }}</td> </tr> </table> + + {% if total.longest_distance_track %} + <h2>{{ _("page.profile.longest_distance_track") }}</h2> + {{ render_track_card(total.longest_distance_track) }} + {% endif %} + + {% if total.shortest_distance_track %} + <h2>{{ _("page.profile.shortest_distance_track") }}</h2> + {{ render_track_card(total.shortest_distance_track) }} + {% endif %} </div> {% endblock %} diff --git a/fietsboek/views/profile.py b/fietsboek/views/profile.py index 2a4203e..df49c3c 100644 --- a/fietsboek/views/profile.py +++ b/fietsboek/views/profile.py @@ -2,6 +2,7 @@ import datetime import sqlite3 from dataclasses import dataclass +from typing import Optional from pyramid.httpexceptions import HTTPNotFound from pyramid.request import Request @@ -44,6 +45,12 @@ class CumulativeStats: max_speed: float = 0.0 """Overall maximum speed, in m/s.""" + longest_distance_track: Optional[TrackWithMetadata] = None + """The track with the longest distance.""" + + shortest_distance_track: Optional[TrackWithMetadata] = None + """The track with the shortest distance.""" + def add(self, track: TrackWithMetadata): """Adds a track to this stats collection. @@ -57,6 +64,18 @@ class CumulativeStats: self.stopped_time += track.stopped_time self.max_speed = max(self.max_speed, track.max_speed) + if ( + self.shortest_distance_track is None + or self.longest_distance_track.length < track.length + ): + self.longest_distance_track = track + + if ( + self.shortest_distance_track is None + or self.shortest_distance_track.length > track.length + ): + self.shortest_distance_track = track + @property def avg_speed(self) -> float: """Average speed, in m/s.""" @@ -92,6 +111,9 @@ def profile(request: Request) -> dict: meta = TrackWithMetadata(track, request.data_manager) total.add(meta) + total.moving_time = round_to_seconds(total.moving_time) + total.stopped_time = round_to_seconds(total.stopped_time) + heatmap_url = None tilehunt_url = None try: @@ -126,15 +148,8 @@ def profile(request: Request) -> dict: return { "user": request.context, - "total_length": total.length, - "total_uphill": total.uphill, - "total_downhill": total.downhill, - "total_moving_time": round_to_seconds(total.moving_time), - "total_stopped_time": round_to_seconds(total.stopped_time), - "max_speed": total.max_speed, - "avg_speed": total.avg_speed, + "total": total, "mps_to_kph": util.mps_to_kph, - "number_of_tracks": total.count, "heatmap_url": heatmap_url, "tilehunt_url": tilehunt_url, } |