From 8352715ae8ae26d77be42f10f4988821ce833f20 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 7 Mar 2015 23:40:37 +0100 Subject: implement toplist --- index.pl | 21 ++++++++++--------- templates/intro.html.ep | 4 ++++ templates/topform.html.ep | 51 +++++++++++++++++++++++++++++++++++++++++++++++ templates/toplist.html.ep | 10 ++++++++++ 4 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 templates/topform.html.ep create mode 100644 templates/toplist.html.ep diff --git a/index.pl b/index.pl index b12a274..2782520 100644 --- a/index.pl +++ b/index.pl @@ -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
+Bargraph: %= include 'barform'; +
+Top-Liste: +%= include 'topform';
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 @@ +
+%= form_for top => begin +%= submit_button 'Go' +
+% my $filter_opts = $self->barplot_filters; +Optionale Einschränkungen: +
+
+ Linie: +
+
+ %= select_field filter_line => [map {[$_, $_]} @{$filter_opts->{lines}} ] +
+
+
+
+ Zugtyp: +
+
+ %= select_field filter_train_type => [map {[$_, $_]} @{$filter_opts->{train_types}} ] +
+
+
+
+ Bahnhof: +
+
+ %= select_field filter_station => [map {[$_, $_]} @{$filter_opts->{stations}} ] +
+
+
+
+ Zielbahnhof: +
+
+ %= select_field filter_destination => [map {[$_, $_]} @{$filter_opts->{destinations}} ] +
+
+
+
+ Verspätung zwischen +
+
+ %= text_field 'filter_delay_min', class => 'delay', placeholder => '-∞' + und + %= text_field 'filter_delay_max', class => 'delay', placeholder => '+∞' + Minuten (inklusive). +
+
+% end +
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'; + +
+ + +% for my $entry (@{ stash('toplist') // [] }) { + +% } +
MeldungAnteilAnzahl
<%= $entry->[0] %><%= $entry->[1] %><%= $entry->[2] %>
+
-- cgit v1.2.3