diff options
-rw-r--r-- | index.pl | 21 | ||||
-rw-r--r-- | templates/intro.html.ep | 4 | ||||
-rw-r--r-- | templates/topform.html.ep | 51 | ||||
-rw-r--r-- | templates/toplist.html.ep | 10 |
4 files changed, 75 insertions, 11 deletions
@@ -439,7 +439,7 @@ get '/bar' => sub { return; }; -get '/top10' => sub { +get '/top' => sub { my $self = shift; my $where_clause = '1=1'; @@ -462,19 +462,18 @@ get '/top10' => sub { (scheduled_time, train_id) where $where_clause }; $rates[$msgnum] = $self->app->dbh->selectall_arrayref($query)->[0][0]; - - say "$msgnum: " . $rates[$msgnum] / $total; } my @argsort = reverse sort { $rates[$a] <=> $rates[$b] } ( 1 .. 99 ); - - for my $i (@argsort[0 .. 10]) { - printf("%s: %.2f%%\n", $translation{$i}, $rates[$i] * 100 / $total); - } - - say join(' ', @argsort[0 .. 10]); - - $self->render( 'intro', ); + my @toplist = map { + [ + $translation{$_} // $_, + sprintf( '%.2f%%', $rates[$_] * 100 / $total ), + $rates[$_] + ] + } @argsort; + + $self->render( 'toplist', toplist => \@toplist ); return; }; diff --git a/templates/intro.html.ep b/templates/intro.html.ep index 1ebb3c0..dcdfe2b 100644 --- a/templates/intro.html.ep +++ b/templates/intro.html.ep @@ -38,5 +38,9 @@ dabei ist ein Zug durchschnittlich </div> <div class="forms"> +<b>Bargraph</b>: %= include 'barform'; +<br/> +<b>Top-Liste</b>: +%= include 'topform'; </div> diff --git a/templates/topform.html.ep b/templates/topform.html.ep new file mode 100644 index 0000000..fae48cd --- /dev/null +++ b/templates/topform.html.ep @@ -0,0 +1,51 @@ +<div> +%= form_for top => begin +%= submit_button 'Go' +<br/> +% my $filter_opts = $self->barplot_filters; +Optionale Einschränkungen: +<div class="field"> + <div class="desc"> + Linie: + </div> + <div> + %= select_field filter_line => [map {[$_, $_]} @{$filter_opts->{lines}} ] + </div> +</div> +<div class="field"> + <div class="desc"> + Zugtyp: + </div> + <div> + %= select_field filter_train_type => [map {[$_, $_]} @{$filter_opts->{train_types}} ] + </div> +</div> +<div class="field"> + <div class="desc"> + Bahnhof: + </div> + <div> + %= select_field filter_station => [map {[$_, $_]} @{$filter_opts->{stations}} ] + </div> +</div> +<div class="field"> + <div class="desc"> + Zielbahnhof: + </div> + <div> + %= select_field filter_destination => [map {[$_, $_]} @{$filter_opts->{destinations}} ] + </div> +</div> +<div class="field"> + <div class="desc"> + Verspätung zwischen + </div> + <div> + %= text_field 'filter_delay_min', class => 'delay', placeholder => '-∞' + und + %= text_field 'filter_delay_max', class => 'delay', placeholder => '+∞' + Minuten (inklusive). + </div> +</div> +% end +<div> diff --git a/templates/toplist.html.ep b/templates/toplist.html.ep new file mode 100644 index 0000000..2784386 --- /dev/null +++ b/templates/toplist.html.ep @@ -0,0 +1,10 @@ +%= include 'topform'; + +<div class="toplist"> +<table> +<tr><th>Meldung</th><th>Anteil</th><th>Anzahl</th></tr> +% for my $entry (@{ stash('toplist') // [] }) { +<tr><td><%= $entry->[0] %></td><td><%= $entry->[1] %></td><td><%= $entry->[2] %></td></tr> +% } +</table> +</div> |