Unverified Commit 3156d5f3 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

review: add top and bottom trips

parent 9dfe1c60
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -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;
}

+18 −0
Original line number Diff line number Diff line
@@ -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>