mirror of
https://github.com/derf/travelynx
synced 2024-12-04 02:09:09 +00:00
Commute stats: count days, not journeys
This commit is contained in:
parent
0a87135e35
commit
94ea5a089f
2 changed files with 26 additions and 23 deletions
|
@ -534,37 +534,39 @@ sub commute {
|
||||||
);
|
);
|
||||||
|
|
||||||
my %journeys_by_month;
|
my %journeys_by_month;
|
||||||
|
my %count_by_month;
|
||||||
my $total = 0;
|
my $total = 0;
|
||||||
|
|
||||||
|
my $prev_doy = 0;
|
||||||
for my $journey ( reverse @journeys ) {
|
for my $journey ( reverse @journeys ) {
|
||||||
my $month = $journey->{rt_departure}->month;
|
my $month = $journey->{rt_departure}->month;
|
||||||
if (
|
if (
|
||||||
$filter_type eq 'exact'
|
(
|
||||||
and ( $journey->{to_name} eq $station
|
$filter_type eq 'exact' and ( $journey->{to_name} eq $station
|
||||||
or $journey->{from_name} eq $station )
|
or $journey->{from_name} eq $station )
|
||||||
)
|
)
|
||||||
{
|
or (
|
||||||
push( @{ $journeys_by_month{$month} }, $journey );
|
|
||||||
$total++;
|
|
||||||
}
|
|
||||||
elsif (
|
|
||||||
$filter_type eq 'substring'
|
$filter_type eq 'substring'
|
||||||
and ( $journey->{to_name} =~ m{\Q$station\E}
|
and ( $journey->{to_name} =~ m{\Q$station\E}
|
||||||
or $journey->{from_name} =~ m{\Q$station\E} )
|
or $journey->{from_name} =~ m{\Q$station\E} )
|
||||||
)
|
)
|
||||||
{
|
or (
|
||||||
push( @{ $journeys_by_month{$month} }, $journey );
|
|
||||||
$total++;
|
|
||||||
}
|
|
||||||
elsif (
|
|
||||||
$filter_type eq 'regex'
|
$filter_type eq 'regex'
|
||||||
and ( $journey->{to_name} =~ m{$station}
|
and ( $journey->{to_name} =~ m{$station}
|
||||||
or $journey->{from_name} =~ m{$station} )
|
or $journey->{from_name} =~ m{$station} )
|
||||||
)
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
push( @{ $journeys_by_month{$month} }, $journey );
|
push( @{ $journeys_by_month{$month} }, $journey );
|
||||||
|
|
||||||
|
my $doy = $journey->{rt_departure}->day_of_year;
|
||||||
|
if ( $doy != $prev_doy ) {
|
||||||
|
$count_by_month{$month}++;
|
||||||
$total++;
|
$total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$prev_doy = $doy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->param( year => $year );
|
$self->param( year => $year );
|
||||||
|
@ -575,6 +577,7 @@ sub commute {
|
||||||
template => 'commute',
|
template => 'commute',
|
||||||
with_autocomplete => 1,
|
with_autocomplete => 1,
|
||||||
journeys_by_month => \%journeys_by_month,
|
journeys_by_month => \%journeys_by_month,
|
||||||
|
count_by_month => \%count_by_month,
|
||||||
total_journeys => $total,
|
total_journeys => $total,
|
||||||
months => [
|
months => [
|
||||||
qw(Januar Februar März April Mai Juni Juli August September Oktober November Dezember)
|
qw(Januar Februar März April Mai Juni Juli August September Oktober November Dezember)
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
% for my $i (0 .. $#{$months}) {
|
% for my $i (0 .. $#{$months}) {
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= $months->[$i] %></td>
|
<td><%= $months->[$i] %></td>
|
||||||
<td><%= scalar @{$journeys_by_month->{$i+1} // []} %></td>
|
<td><%= $count_by_month->{$i+1} // 0 %></td>
|
||||||
</tr>
|
</tr>
|
||||||
% }
|
% }
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
Loading…
Reference in a new issue