From 89e7318805b09cf32c4f919f2b09f522830fb9ec Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Mon, 12 Aug 2013 11:57:27 +0100 Subject: Add a page with experimental statistics on public bodies The statistics on the status of the requests to a particular public body are too slow to calculate on-the-fly, so this commit adds: * Extra columns on public_bodies to store counts of the successful, not held, and overdue request counts for each public body. * A rake task which should be run periodically to update the overdue request count column. If Javascript is not available, the summary statistics are shown as tables. If Javascript is available, graphs are drawn with Flot. --- public/javascripts/stats-graphs.js | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 public/javascripts/stats-graphs.js (limited to 'public/javascripts/stats-graphs.js') diff --git a/public/javascripts/stats-graphs.js b/public/javascripts/stats-graphs.js new file mode 100644 index 000000000..5d3d52152 --- /dev/null +++ b/public/javascripts/stats-graphs.js @@ -0,0 +1,82 @@ +/* From http://stackoverflow.com/a/10284006/223092 */ +function zip(arrays) { + return arrays[0].map(function(_,i){ + return arrays.map(function(array){return array[i]}) + }); +} + +$(document).ready(function() { + $.each(graphs_data, function(index, graph_data) { + var graph_id = graph_data['id'], + dataset, + plot, + graph_data, + graph_div = $('#' + graph_id); + + graph_div.css('width', '700px'); + graph_div.css('height', '400px'); + + dataset = [ + {'color': 'orange', + 'bars': { + 'show': true, + 'barWidth': 0.5, + 'align': 'center' + }, + 'data': zip([graph_data['x_values'], + graph_data['y_values']]) + } + ] + + if (graph_data['errorbars']) { + dataset.push({ + 'color': 'orange', + 'points': { + // Don't show these, just draw error bars: + 'radius': 0, + 'errorbars': 'y', + 'yerr': { + 'asymmetric': true, + 'show': true, + 'upperCap': "-", + 'lowerCap': "-", + 'radius': 5 + } + }, + 'data': zip([graph_data['x_values'], + graph_data['y_values'], + graph_data['cis_below'], + graph_data['cis_above']]) + }); + } + + options = { + 'xaxis': { + 'ticks': graph_data['x_ticks'], + }, + 'yaxis': { + 'min': 0, + 'max': graph_data['y_max'] + }, + 'xaxes': [{ + 'axisLabel': graph_data['x_axis'], + 'axisLabelPadding': 20, + 'axisLabelColour': 'black' + }], + 'yaxes': [{ + 'axisLabel': graph_data['y_axis'], + 'axisLabelPadding': 20, + 'axisLabelColour': 'black' + }], + 'series': { + 'lines': { + 'show': false + } + }, + } + + plot = $.plot(graph_div, + dataset, + options); + }); +}); -- cgit v1.2.3