summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.pl67
-rw-r--r--public/css/default.css8
-rw-r--r--public/js/d3funcs.js2
-rw-r--r--templates/barform.html.ep17
-rw-r--r--templates/bargraph.html.ep2
-rw-r--r--templates/intro.html.ep4
6 files changed, 99 insertions, 1 deletions
diff --git a/index.pl b/index.pl
index a76ce5b..1e7888b 100644
--- a/index.pl
+++ b/index.pl
@@ -25,6 +25,54 @@ app->attr(
}
);
+helper barplot_args => sub {
+ my ( $self ) = @_;
+
+ return {
+ x => {
+ hour => {
+ desc => 'Stunde',
+ label => 'Angebrochene Stunde',
+ },
+ line => {
+ desc => 'Linie',
+ },
+ station => {
+ desc => 'Bahnhof',
+ },
+ train_type => {
+ desc => 'Zugtyp',
+ },
+ weekday => {
+ desc => 'Wochentag',
+ },
+ weekhour => {
+ desc => 'Wochentag und Stunde',
+ label => 'Wochentag und angebrochene Stunde',
+ },
+ },
+ y => {
+ cancel_num => {
+ desc => 'Anzahl Zugausfälle',
+ label => 'Zugausfälle',
+ },
+ cancel_rate => {
+ desc => 'Zugausfälle',
+ yformat => '.1%',
+ },
+ delay => {
+ desc => 'Durchschnittliche Verspätung',
+ label => 'Minuten',
+ yformat => '.1f',
+ },
+ realtime_rate => {
+ desc => 'Echtzeitdaten vorhanden',
+ yformat => '.1%',
+ },
+ },
+ };
+};
+
helper count_unique_column => sub {
my ( $self, $column ) = @_;
my $dbh = $self->app->dbh;
@@ -231,6 +279,25 @@ get '/all' => sub {
get '/bar' => sub {
my $self = shift;
+
+ my $xsource = $self->param('xsource');
+ my $ysource = $self->param('ysource');
+
+ my %args = %{$self->barplot_args};
+
+ if (not $self->param('xlabel')) {
+ $self->param(xlabel => $args{x}{$xsource}{label} // $args{x}{$xsource}{desc});
+ }
+ if (not $self->param('ylabel')) {
+ $self->param(ylabel => $args{y}{$ysource}{label} // $args{y}{$ysource}{desc});
+ }
+ if (not $self->param('xformat') and $args{x}{$xsource}{xformat}) {
+ $self->param(xformat => $args{x}{$xsource}{xformat});
+ }
+ if (not $self->param('yformat') and $args{y}{$ysource}{yformat}) {
+ $self->param(yformat => $args{y}{$ysource}{yformat});
+ }
+
$self->render('bargraph');
return;
};
diff --git a/public/css/default.css b/public/css/default.css
index 57cf602..7b37068 100644
--- a/public/css/default.css
+++ b/public/css/default.css
@@ -2,6 +2,14 @@ body {
font-family: sans-serif;
}
+input, select {
+ border: 1px solid black;
+}
+
+input.dimension {
+ width: 4em;
+}
+
svg {
font: 10px sans-serif;
}
diff --git a/public/js/d3funcs.js b/public/js/d3funcs.js
index ec6699d..0b68bcb 100644
--- a/public/js/d3funcs.js
+++ b/public/js/d3funcs.js
@@ -1,6 +1,6 @@
show_bargraph = function(datasource, title, xLabel, yLabel, yFormat, width, height) {
- var margin = {top: 40, right: 20, bottom: 30, left: 40};
+ var margin = {top: 40, right: 20, bottom: 40, left: 45};
if (!width) {
width = 960;
diff --git a/templates/barform.html.ep b/templates/barform.html.ep
new file mode 100644
index 0000000..4d43f42
--- /dev/null
+++ b/templates/barform.html.ep
@@ -0,0 +1,17 @@
+%= form_for bar => begin
+Bargraph:
+% my %yargs = %{$self->barplot_args->{y}};
+% my @yarg_keys = sort keys %yargs;
+%= select_field ysource => [map {[$yargs{$_}->{desc}, $_]} @yarg_keys]
+aufgeteilt nach
+% my %xargs = %{$self->barplot_args->{x}};
+% my @xarg_keys = sort keys %xargs;
+%= select_field xsource => [map {[$xargs{$_}->{desc}, $_]} @xarg_keys]
+mit
+Abmessungen
+%= text_field 'width' => 960, class => 'dimension'
+x
+%= text_field 'height' => 500, class => 'dimension'
+Pixel.
+%= submit_button 'Go'
+% end
diff --git a/templates/bargraph.html.ep b/templates/bargraph.html.ep
index 310220f..3d5eda2 100644
--- a/templates/bargraph.html.ep
+++ b/templates/bargraph.html.ep
@@ -1,3 +1,5 @@
+%= include 'barform';
+
%= javascript begin
show_bargraph('/2ddata.tsv?aggregate=<%= param('xsource') %>&metric=<%= param('ysource') %>',
diff --git a/templates/intro.html.ep b/templates/intro.html.ep
index 885cd14..1ebb3c0 100644
--- a/templates/intro.html.ep
+++ b/templates/intro.html.ep
@@ -36,3 +36,7 @@ Insgesamt wurden
dabei ist ein Zug durchschnittlich
<b><%= sprintf('%.2f', $stats->{delay_avg}) %> Minuten</b> zu spät.
</div>
+
+<div class="forms">
+%= include 'barform';
+</div>