summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-12-27 22:04:09 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-12-27 22:04:09 +0100
commit3156d5f372707df965933b1885137857652466f5 (patch)
tree23fc2f643fea0326d4a2614d1ed18587a896f898
parent9dfe1c60ab417556798ad12fa3ec86671d63f5a6 (diff)
review: add top and bottom trips
-rwxr-xr-xlib/Travelynx/Model/Journeys.pm45
-rw-r--r--templates/year_in_review.html.ep18
2 files changed, 63 insertions, 0 deletions
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm
index 093aa1f..5721726 100755
--- a/lib/Travelynx/Model/Journeys.pm
+++ b/lib/Travelynx/Model/Journeys.pm
@@ -1056,6 +1056,7 @@ sub compute_review {
my %num_by_wrtype;
my %num_by_linetype;
my %num_by_stop;
+ my %num_by_trip;
if ( not $stats or not @journeys or $stats->{num_trains} == 0 ) {
return;
@@ -1117,6 +1118,10 @@ sub compute_review {
if ( $journey->{to_name} ) {
$num_by_stop{ $journey->{to_name} } += 1;
}
+ if ( $journey->{from_name} and $journey->{to_name} ) {
+ $num_by_trip{ $journey->{from_name} . '|' . $journey->{to_name} }
+ += 1;
+ }
if ( $journey->{sched_dep_ts} and $journey->{rt_dep_ts} ) {
$journey->{delay_dep}
@@ -1171,6 +1176,8 @@ sub compute_review {
map { [ $_, $num_by_linetype{$_} ] } keys %num_by_linetype;
my @stops = sort { $b->[1] <=> $a->[1] }
map { [ $_, $num_by_stop{$_} ] } keys %num_by_stop;
+ my @trips = sort { $b->[1] <=> $a->[1] }
+ map { [ $_, $num_by_trip{$_} ] } keys %num_by_trip;
my @reasons = sort { $b->[1] <=> $a->[1] }
map { [ $_, $num_by_message{$_} ] } keys %num_by_message;
@@ -1331,6 +1338,44 @@ sub compute_review {
= sprintf( '%.1f%%', $review{punctual_percent} );
$review{punctual_percent_h} =~ tr{.}{,};
+ my $top_trip_count = 0;
+ my $single_trip_count = 0;
+ for my $i ( 0 .. 3 ) {
+ if ( $trips[$i] ) {
+ push( @{ $review{top_trips} },
+ [ split( qr{[|]}, $trips[$i][0] ) ] );
+ $top_trip_count += $trips[$i][1];
+ }
+ }
+
+ for my $trip (@trips) {
+ if ( $trip->[1] == 1 ) {
+ $single_trip_count += 1;
+ if ( @{ $review{single_trips} // [] } < 3 ) {
+ push(
+ @{ $review{single_trips} },
+ [ split( qr{[|]}, $trip->[0] ) ]
+ );
+ }
+ }
+ }
+
+ $review{top_trip_count} = $top_trip_count;
+ $review{top_trip_percent_h}
+ = sprintf( '%.1f%%', $top_trip_count * 100 / $stats->{num_trains} );
+
+ $review{single_trip_count} = $single_trip_count;
+ $review{single_trip_percent_h}
+ = sprintf( '%.1f%%', $single_trip_count * 100 / $stats->{num_trains} );
+
+ if ( @stops >= 3 ) {
+ my $desc = q{};
+ $review{typical_stops_3} = [ $stops[0][0], $stops[1][0], $stops[2][0] ];
+ }
+ elsif ( @stops == 2 ) {
+ $review{typical_stops_2} = [ $stops[0][0], $stops[1][0] ];
+ }
+
return \%review;
}
diff --git a/templates/year_in_review.html.ep b/templates/year_in_review.html.ep
index 548245e..456fb37 100644
--- a/templates/year_in_review.html.ep
+++ b/templates/year_in_review.html.ep
@@ -144,6 +144,24 @@
</div>
<div class="carousel-item" href="#six">
<h2>Last, but not least</h2>
+ % if ($review->{top_trip_count}) {
+ <p>
+ <strong><%= $review->{top_trip_percent_h} %></strong> deiner Check-Ins konzentrierten sich auf diese Strecken:<br/>
+ % for my $i (0 .. $#{$review->{top_trips}}) {
+ % my $trip = $review->{top_trips}[$i];
+ <%= $trip->[0] %> → <%= $trip->[1] %><br/>
+ % }
+ </p>
+ % }
+ % if ($review->{single_trip_count}) {
+ <p>
+ <strong><%= $review->{single_trip_percent_h} %></strong> aller Verbindungen bist du nur genau einmal gefahren. Zum Beispiel:<br/>
+ % for my $i (0 .. $#{$review->{single_trips}}) {
+ % my $trip = $review->{single_trips}[$i];
+ <%= $trip->[0] %> → <%= $trip->[1] %><br/>
+ % }
+ </p>
+ % }
<p><em>Thank you for traveling with travelynx</em></p>
</div>
</div>