From d14e3af4b280f3236f8ed8080fad667a519ca176 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 9 Apr 2016 18:10:13 +0200 Subject: allow filtering by month --- index.pl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.pl b/index.pl index 06fcf9c..2ca52e8 100644 --- a/index.pl +++ b/index.pl @@ -47,6 +47,9 @@ helper barplot_args => sub { line => { desc => 'Linie', }, + month => { + desc => 'Monat', + }, station => { desc => 'Bahnhof', }, @@ -368,6 +371,8 @@ helper 'get_2ddata' => sub { my ( $filter, $filter_clause ) = $self->parse_filter_args; my @weekdays = qw(So Mo Di Mi Do Fr Sa); + my @months = qw(BUG Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez); + $months[3] = encode( 'utf-8', $months[3] ); if ( $msgnum < 0 or $msgnum > 99 ) { $msgnum = 0; @@ -389,6 +394,9 @@ helper 'get_2ddata' => sub { $format = 'extract(dow from scheduled_time at time zone \'GMT\') || \' \' || to_char(scheduled_time at time zone \'GMT\', \'HH24\')'; } + when ('month') { + $format = 'extract(month from scheduled_time at time zone \'GMT\')'; + } when ('line') { $format = 'train_types.name || \' \' || lines.name'; $where_clause = 'line_no is not null'; @@ -505,6 +513,11 @@ helper 'get_2ddata' => sub { # SQL starts on sunday, we'd like to start on monday @{$dbres} = ( @{$dbres}[ 1 .. 6 ], $dbres->[0] ); } + elsif ( $aggregate eq 'month' ) { + for my $row ( @{$dbres} ) { + splice( @{$row}, 0, 1, $months[ $row->[0] ] ); + } + } elsif ( $aggregate eq 'weekhour' ) { # the result only contains columns for datetimes with departures, so -- cgit v1.2.3