public
Created

Count new Pause IDs

  • Download Gist
gistfile1.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#!perl
 
use strict;
use warnings;
 
use LWP::Simple;
use DateTime;
use Data::Google::Visualization::DataTable;
 
# Create a datatable
my $datatable = Data::Google::Visualization::DataTable->new();
$datatable->add_columns(
{ id => 'date', label => "Month Beginning", type => 'date' },
{ id => 'count', label => "New Users", type => 'number' }
);
 
# Add the row
$datatable->add_rows({
date => DateTime->new({ year => 2000 + $_->[0], month => $_->[1], day => 1 }),
count => $_->[2]
}) for
sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] }
# Get the HTML page
map {
my $content = get $_->[2];
if ( $content ) {
my $count = () = $content =~ m/Welcome new user/g;
[ @$_[0, 1], $count ]
} else {
()
}
}
# Get the URL
map {
my ($year, $month) = map { sprintf "%02d", $_ } @$_;
 
my $url = sprintf(
'http://www.nntp.perl.org/group/perl.modules/20%s/%s.html',
$year, $month
);
[$year, $month, $url];
}
# All months and years
map { my $m = $_; map { [ $_, $m ] } 00 .. 13 } 01 .. 12;
 
# Print it out in to the template
my $data = $datatable->output_javascript( pretty => 1 );
my $template = join '', (<DATA>);
$template =~ s/MARKER/$data/;
print $template;
 
__DATA__
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart","table"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable( MARKER );
var options = { title: 'New PAUSE ID registrations by month' };
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: false});
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
<div id='table_div'></div>
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.