diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-04-18 21:58:46 +0200 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2014-11-11 15:57:04 +0000 |
commit | b3c664ba49f9555038025e16dd8474bd99e90d13 (patch) | |
tree | 515ec9167c056f686a04f6cc9404deb3e6011687 /bin/problems-filed-graph | |
parent | 1bd78da3b7e1125fe6e30118f61e5265f805c2fd (diff) |
Switch graph generation programs to Perl.
This means they access the database the same way all the other scripts
do, preventing any issues due to different setups. Also tidy up state
grouping in graph, add Norway start date.
Diffstat (limited to 'bin/problems-filed-graph')
-rwxr-xr-x | bin/problems-filed-graph | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/bin/problems-filed-graph b/bin/problems-filed-graph index e5946b078..d3e132f8e 100755 --- a/bin/problems-filed-graph +++ b/bin/problems-filed-graph @@ -1,61 +1,62 @@ -#!/bin/bash -# problems-filed-graph +#!/usr/bin/env perl + +# problems-filed-graph: # Plot graph of FixMyStreet problem report creation rate. # -# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. -# Email: francis@mysociety.org. WWW: http://www.mysociety.org/ -# -# $Id: problems-filed-graph,v 1.2 2008-04-11 11:05:36 francis Exp $ - -GPLOT_OUTPUT="set terminal png font 'Vera.ttf' 9 size 1200,600" -EXTENSION=".png" -#GPLOT_OUTPUT="set terminal fig color big thickness 1" -#EXTENSION=".fig" -#GPLOT_OUTPUT="set terminal svg size 800 250" -#EXTENSION=".svg" - -cd `dirname $0` -cd ../../ -source fixmystreet/commonlib/shlib/deployfns - -read_conf fixmystreet/conf/general.yml - -SOURCEO=/tmp/fms-report-rate-graph-data-nonwmc-$RANDOM$RANDOM -GPSCRIPT=/tmp/fms-report-rate-graph-script-$RANDOM$RANDOM - -echo "select - date(created), count(*) - from problem - where state not in ('unconfirmed', 'hidden') - group by date(created) - order by date(created) - ;" | psql --host $OPTION_FMS_DB_HOST --port $OPTION_FMS_DB_PORT -A -F " " $OPTION_FMS_DB_NAME $OPTION_FMS_DB_USER | egrep -v "date|rows" >$SOURCEO -#echo "source $SOURCEO" - -cat >$GPSCRIPT <<END +# Copyright (c) 2014 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org + +use strict; +use warnings; +require 5.8.0; + +use FindBin; +use File::Temp qw(tempfile); + +use FixMyStreet::App; + +chdir("$FindBin::Bin/../"); + +my %config = ( + gplot_output => "set terminal png font 'Vera.ttf' 9 size 1200,600", + extension => '.png', +); + +my ($fh, $source) = tempfile("fms-report-rate-graph-data-nonwmc-XXXXXXXXXX", UNLINK => 1); + +my @entries = FixMyStreet::App->model('DB::Problem')->search({ + state => { -not_in => [ 'unconfirmed', 'hidden', 'partial' ] }, + }, { + columns => [ + { 'date' => { date => 'created' } }, + { 'count' => { count => '*' } } + ], + group_by => [ 'date' ], + order_by => [ 'date' ], + } +); +@entries = map { { $_->get_columns } } @entries; +foreach (@entries) { + $fh->print($_->{date}, ' ', $_->{count}, "\n"); +} + +my $gp = <<END; unset border - $GPLOT_OUTPUT + $config{gplot_output} set xdata time; set timefmt "%Y-%m-%d"; - # set xrange ["2005-01-01":"2006-01-01"]; set format x "%b %Y" - # set xlabel "WriteToThem.com in 2005" unset xlabel - #set nokey - #set ylabel "cumulative messages" set ylabel "problems filed / calendar day" set xtics nomirror set ytics nomirror - # set y2tics nomirror tc lt 3 n = 0 - plot "$SOURCEO" using 1:2 with lines axes x1y2 lt 3 title "FixMyStreet problem reports" -# "< awk 'BEGIN { n = 0 } { n += \$2; print \$1, \$2, n; }' $SOURCE" using 1:3 with lines lt 2 title "cumulative messages created", + plot "$source" using 1:2 with lines axes x1y2 lt 3 title "FixMyStreet problem reports" END -#echo "gpscript $GPSCRIPT" - -export GDFONTPATH=/usr/share/fonts/truetype/ttf-bitstream-vera -gnuplot < $GPSCRIPT > fixmystreet/web/fms-live-line$EXTENSION 2>/dev/null +open(my $gnuplot, '|-', "GDFONTPATH=/usr/share/fonts/truetype/ttf-bitstream-vera gnuplot > web/fms-live-line$config{extension} 2> /dev/null"); +$gnuplot->print($gp); +close $gnuplot; |