Skip to content

Instantly share code, notes, and snippets.

@pjlsergeant
Created August 17, 2013 07:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjlsergeant/6255791 to your computer and use it in GitHub Desktop.
Save pjlsergeant/6255791 to your computer and use it in GitHub Desktop.
Count new Pause IDs
#!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment