#!/usr/bin/env perl # problem-creation-graph: # Plot graph of rate of problem creation # # 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; my $DIR; BEGIN { use File::Basename qw(dirname); use File::Spec; $DIR = dirname(dirname(File::Spec->rel2abs($0))); require "$DIR/setenv.pl"; } use File::Temp qw(tempfile); use FixMyStreet::DB; my %config = ( gplot_output => "set terminal png font 'Vera.ttf' 9 size 1200,400", extension => '.png', #gplot_output => "set terminal fig color big thickness 1" #extension => ".fig" #gplot_output => "set terminal svg size 800 250" #extension => ".svg" ); my $base_url = FixMyStreet->config('BASE_URL'); $config{date} = '2007-02-01'; $config{date} = '2011-03-03' if $base_url =~ /fiksgatami/; $config{date} = '2008-10-01' if $base_url =~ /emptyhomes/; my %sources; sub grab_data { my ($type, $selection) = @_; my ($fh, $filename) = tempfile("fms-creation-rate-graph-data-XXXXXXXXXX", UNLINK => 1); $sources{$type} = $filename; my @entries = FixMyStreet::DB->resultset('Problem')->search( $selection, { columns => [ { 'date' => { date => 'created' } }, { 'count' => { count => '*' } } ], group_by => [ 'date' ], order_by => [ 'date' ], } ); @entries = map { { $_->get_columns } } @entries; foreach (@entries) { $fh->print($_->{date}, ' ', $_->{count}, "\n"); } } # rather nastily, work out the cumulative heights in reverse, so can # plot impulses on top of each other grab_data('unconfirmed', {}); my @states_to_ignore = ('unconfirmed'); grab_data('open', { state => { -not_in => \@states_to_ignore } }); push @states_to_ignore, FixMyStreet::DB::Result::Problem->open_states(); grab_data('fixed', { state => { -not_in => \@states_to_ignore } }); push @states_to_ignore, FixMyStreet::DB::Result::Problem->fixed_states(); grab_data('closed', { state => { -not_in => \@states_to_ignore } }); push @states_to_ignore, FixMyStreet::DB::Result::Problem->closed_states(); grab_data('hidden', { state => { -not_in => \@states_to_ignore } }); push @states_to_ignore, 'hidden'; grab_data('other', { state => { -not_in => \@states_to_ignore } }); my $gp = < $DIR/web/fms-live-creation$config{extension} 2> /dev/null") or die $!; $gnuplot->print($gp); close $gnuplot;