From ccc93413a28d03fd3d2ccf2d86831ad00c77cfe2 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 29 Dec 2022 14:14:12 +0100 Subject: review: link to list of all single-trip checkins --- lib/Travelynx/Controller/Traveling.pm | 7 ++++++- lib/Travelynx/Model/Journeys.pm | 16 ++++++++++++++++ templates/history_by_year.html.ep | 8 ++++++++ templates/year_in_review.html.ep | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 7a00cd0..01a9059 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -1513,7 +1513,8 @@ sub year_in_review { sub yearly_history { my ($self) = @_; - my $year = $self->stash('year'); + my $year = $self->stash('year'); + my $filter = $self->param('filter'); my @journeys; # DateTime is very slow when looking far into the future due to DST changes @@ -1540,6 +1541,10 @@ sub yearly_history { with_datetime => 1 ); + if ( $filter and $filter eq 'single' ) { + @journeys = $self->journeys->grep_single(@journeys); + } + if ( not @journeys ) { $self->render( 'not_found', message => 'Keine Zugfahrten im angefragten Jahr gefunden.' ); diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm index 1adf95e..f23c2b1 100755 --- a/lib/Travelynx/Model/Journeys.pm +++ b/lib/Travelynx/Model/Journeys.pm @@ -1039,6 +1039,22 @@ sub get_travel_distance { $distance_beeline, $skipped ); } +sub grep_single { + my ( $self, @journeys ) = @_; + + my %num_by_trip; + for my $journey (@journeys) { + if ( $journey->{from_name} and $journey->{to_name} ) { + $num_by_trip{ $journey->{from_name} . '|' . $journey->{to_name} } + += 1; + } + } + + return + grep { $num_by_trip{ $_->{from_name} . '|' . $_->{to_name} } == 1 } + @journeys; +} + sub compute_review { my ( $self, $stats, @journeys ) = @_; my $longest_km; diff --git a/templates/history_by_year.html.ep b/templates/history_by_year.html.ep index 9f9b022..adc4840 100644 --- a/templates/history_by_year.html.ep +++ b/templates/history_by_year.html.ep @@ -23,6 +23,14 @@ %= include '_history_months_for_year'; +% if (param('filter') and param('filter') eq 'single') { +
+
+

Die folgende Auflistung enthält nur Fahrten, deren Kombination aus Start und Ziel im aktuellen Jahr einmalig ist.

+
+
+% } + % if (stash('journeys')) { %= include '_history_trains', date_format => '%d.%m.', journeys => stash('journeys'); % } diff --git a/templates/year_in_review.html.ep b/templates/year_in_review.html.ep index 9a19c8f..dae45bc 100644 --- a/templates/year_in_review.html.ep +++ b/templates/year_in_review.html.ep @@ -155,7 +155,7 @@ % } % if ($review->{single_trip_count}) {

- <%= $review->{single_trip_percent_h} %> aller Verbindungen bist du nur genau einmal gefahren. Zum Beispiel:
+ <%= $review->{single_trip_percent_h} %> aller Verbindungen bist du nur genau einmal gefahren. Zum Beispiel:
% for my $i (0 .. $#{$review->{single_trips}}) { % my $trip = $review->{single_trips}[$i]; <%= $trip->[0] %> → <%= $trip->[1] %>
-- cgit v1.2.3