diff options
author | Daniel Friesel <derf@finalrewind.org> | 2015-03-07 16:27:43 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2015-03-07 16:27:43 +0100 |
commit | 8f10edc76c8ede3ab19aca5e0d6cec532cfc32e6 (patch) | |
tree | 1fef453cdf1d8ad926f2d5c6322ef142e3054755 | |
parent | ab524754caf72694297437a083d6e3c2f4b8801c (diff) |
add filters (mostly working, even)
-rw-r--r-- | index.pl | 41 | ||||
-rw-r--r-- | templates/bargraph.html.ep | 2 |
2 files changed, 41 insertions, 2 deletions
@@ -121,7 +121,7 @@ helper barplot_filters => sub { ], destinations => [ q{}, - map { decode('utf8', $_->[0]) } @{ + map { decode( 'utf8', $_->[0] ) } @{ $dbh->selectall_arrayref( "select distinct destination from $table order by destination" ) @@ -221,6 +221,24 @@ get '/2ddata.tsv' => sub { my $metric = $self->param('metric') // 'avg_delay'; my $msgnum = int( $self->param('msgnum') // 0 ); + my %filter = ( + line => scalar $self->param('filter_line'), + train_type => scalar $self->param('filter_train_type'), + station => scalar $self->param('filter_station'), + destination => scalar $self->param('filter_destination'), + delay_min => scalar $self->param('filter_delay_min'), + delay_max => scalar $self->param('filter_delay_max'), + ); + + for my $key ( keys %filter ) { + $filter{$key} =~ tr{a-zA-Z0-9öäüÖÄÜß }{}cd; + } + + $filter{delay_min} + = length( $filter{delay_min} ) ? int( $filter{delay_min} ) : undef; + $filter{delay_max} + = length( $filter{delay_max} ) ? int( $filter{delay_max} ) : undef; + my @weekdays = qw(So Mo Di Mi Do Fr Sa); if ( $msgnum < 0 or $msgnum > 99 ) { @@ -253,6 +271,27 @@ get '/2ddata.tsv' => sub { } } + if ( $filter{line} ) { + my ( $train_type, $line_no ) = split( / /, $filter{line} ); + $where_clause + .= " and train_type = '$train_type' and line_no = '$line_no'"; + } + if ( $filter{train_type} ) { + $where_clause .= " and train_type = '$filter{train_type}'"; + } + if ( $filter{station} ) { + $where_clause .= " and station = '$filter{station}'"; + } + if ( $filter{destination} ) { + $where_clause .= " and destination = '$filter{destination}'"; + } + if ( defined $filter{delay_min} ) { + $where_clause .= " and delay >= $filter{delay_min}"; + } + if ( defined $filter{delay_max} ) { + $where_clause .= " and delay <= $filter{delay_max}"; + } + given ($metric) { when ('avg_delay') { $query = qq{ diff --git a/templates/bargraph.html.ep b/templates/bargraph.html.ep index 7e989e6..5b6282d 100644 --- a/templates/bargraph.html.ep +++ b/templates/bargraph.html.ep @@ -2,7 +2,7 @@ %= javascript begin -show_bargraph('/2ddata.tsv?aggregate=<%= param('xsource') %>&metric=<%= param('ysource') %>&msgnum=<%= param('msgnum') %>', +show_bargraph('/2ddata.tsv?aggregate=<%= param('xsource') %>&metric=<%= param('ysource') %>&msgnum=<%= param('msgnum') %>&filter_line=<%= param('filter_line') %>&filter_train_type=<%= param('filter_train_type') %>&filter_station=<%= param('filter_station') %>&filter_destination=<%= param('filter_destination') %>&filter_delay_min=<%= param('filter_delay_min') %>&filter_delay_max=<%= param('filter_delay_max') %>', '<%= param('title') %>', '<%= param('xlabel') %>', '<%= param('ylabel') %>', '<%= param('yformat') %>', '<%= param('width') %>', '<%= param('height') %>'); |