summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-03-03 17:08:01 +0100
committerDaniel Friesel <derf@finalrewind.org>2015-03-03 17:08:01 +0100
commit9392bec63bd1057f263dacdd985b628f40fd04bf (patch)
treed575d4e67cf053af5f35ed7400a0b92fa4324ebb
parent5268977803fde3e15ad59bdd1673cb7d85d0a01f (diff)
show total/matched number of samples in barplot hover
-rw-r--r--index.pl36
-rw-r--r--public/js/d3funcs.js10
2 files changed, 29 insertions, 17 deletions
diff --git a/index.pl b/index.pl
index 6fb9832..c29c314 100644
--- a/index.pl
+++ b/index.pl
@@ -188,7 +188,7 @@ get '/2ddata.tsv' => sub {
my $where_clause = '1 = 1';
- my $res = "x\ty\n";
+ my $res = "x\ty\ty_total\ty_matched\n";
my $query;
my $format = 'strftime("%H", scheduled_time, "unixepoch")';
@@ -215,46 +215,52 @@ get '/2ddata.tsv' => sub {
given ($metric) {
when ('avg_delay') {
$query = qq{
- select $format as aggregate,
- avg(delay) from $table where not is_canceled and $where_clause group by aggregate
+ select $format as aggregate, avg(delay), count()
+ from $table where not is_canceled and $where_clause group by aggregate
};
}
when ('cancel_num') {
$query = qq{
- select $format as aggregate,
- count() from $table where is_canceled > 0 and $where_clause group by aggregate
+ select $format as aggregate, count(), count()
+ from $table where is_canceled > 0 and $where_clause group by aggregate
};
}
when ('cancel_rate') {
$query = qq{
- select $format as aggregate,
- avg(is_canceled) from $table where $where_clause group by aggregate
+ select $format as aggregate, avg(is_canceled), count(),
+ sum(is_canceled = 1)
+ from $table where $where_clause group by aggregate
};
}
when ('delay0_rate') {
$query = qq{
- select $format as aggregate,
- avg(delay < 1) from $table where $where_clause group by aggregate
+ select $format as aggregate, avg(delay < 1), count(),
+ sum(delay < 1)
+ from $table where $where_clause group by aggregate
};
}
when ('delay5_rate') {
$query = qq{
- select $format as aggregate,
- avg(delay > 5) from $table where $where_clause group by aggregate
+ select $format as aggregate, avg(delay > 5), count(),
+ sum(delay > 5)
+ from $table where $where_clause group by aggregate
};
}
when ('message_rate') {
$query = qq{
select $format as aggregate,
- avg(msgtable.train_id is not null) from $table
+ avg(msgtable.train_id is not null), count(),
+ sum(msgtable.train_id is not null)
+ from $table
left outer join msg_$msgnum as msgtable using
(scheduled_time, train_id) where $where_clause group by aggregate
};
}
when ('realtime_rate') {
$query = qq{
- select $format as aggregate,
- avg(delay is not null) from $table
+ select $format as aggregate, avg(delay is not null),
+ count(), sum(delay is not null)
+ from $table
where $where_clause group by aggregate
};
}
@@ -277,7 +283,7 @@ get '/2ddata.tsv' => sub {
}
for my $row ( @{$dbres} ) {
- $res .= sprintf( "%s\t%s\n", @{$row} );
+ $res .= join("\t", @{$row} ) . "\n";
}
$self->render( data => $res );
diff --git a/public/js/d3funcs.js b/public/js/d3funcs.js
index 0b68bcb..fb50345 100644
--- a/public/js/d3funcs.js
+++ b/public/js/d3funcs.js
@@ -33,8 +33,14 @@ show_bargraph = function(datasource, title, xLabel, yLabel, yFormat, width, heig
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) {
- return "<strong>Frequency:</strong> <span style='color:red'>" + d.y + "</span>";
- })
+ if (d.y_matched == undefined) {
+ return "n=<span style='color:orangered'>" + d.y_total + "</span>";
+ }
+ else {
+ return "<span style='color:orangered'>" + d.y_matched + "</span> von " +
+ "<span style='color:orangered'>" + d.y_total + "</span>";
+ }
+ });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)