Changeset 353


Ignore:
Timestamp:
Nov 6, 2006, 6:21:49 PM (13 years ago)
Author:
Dominic Hargreaves
Message:

Date stats as graph

Location:
trunk/npemap.org.uk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/perllib/NPEMap/Postcodes.pm

    r348 r353  
    1010use NPEMap::Config;
    1111use Date::Format;
     12use Chart::Strip;
    1213
    1314require Exporter;
    1415@ISA    = qw(Exporter);
    15 @EXPORT = qw(build_home_stats missing_district_stats);
     16@EXPORT = qw(build_home_stats missing_district_stats build_submission_graph);
    1617
    1718sub _getAllStats {
     
    3536    my $dbh = shift;
    3637    my $sql = <<"HERE";
    37 SELECT TO_CHAR(DATE_TRUNC('day', created_at), 'YYYY-MM-DD') AS day,
     38SELECT extract(epoch FROM date_trunc('day', created_at)) AS time,
    3839       COUNT(*) AS all,
    39        SUM(CASE WHEN source=0 THEN 1 ELSE 0 END) AS us
     40       SUM(CASE WHEN source=0 THEN 1 ELSE 0 END) AS value
    4041FROM postcodes WHERE deleted ='f'
    4142GROUP BY  date_trunc('day', created_at)
     
    128129}
    129130
     131sub build_submission_graph {
     132    my $dbh = shift;
     133    my $chart = Chart::Strip->new(
     134        title => 'Postcodes collected over time',
     135    );
     136
     137    $chart->add_data(_getDateStats($dbh), {});
     138    open PNG, ">$staticdir/stats/submission_graph.png" or die $!;
     139    print PNG $chart->png();
     140    close PNG;
     141    return 1;
     142}
     143
    1301441;
Note: See TracChangeset for help on using the changeset viewer.