Created
June 2, 2011 11:41
-
-
Save dmitrybitman/1004282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use List::Util qw(sum min max); | |
use POSIX; | |
my %data = (); | |
my $max = 3000; | |
my $min = 0; | |
my $step = 50; | |
my $stepsCount = ($max - $min) / $step; | |
while (<>) { | |
my ($group, $time, $count) = split; | |
if (!defined $data{$group}) { | |
$data{$group}[$stepsCount] = 0; | |
} | |
next if $time <= $min; | |
$time = min($time, $max+1); # store very big values in one place for percentage calculations | |
$data{$group}[($time-$min) / $step] += $count; | |
} | |
my @gchartData = ''; | |
my @gchartGroups; | |
my $maxValue = 0; | |
while (my ($group, $stats) = each(%data)){ | |
next if !defined(@$stats); | |
my @singleGchartData = (); | |
push(@gchartGroups, $group); | |
my $sum = sum(@$stats); | |
my $rollingSum = 0; | |
pop(@$stats); # do not plot very big values | |
foreach my $count (@$stats) { | |
$rollingSum += defined($count) ? $count : 0; | |
push(@singleGchartData, sprintf("%.2f", $rollingSum * 100 / $sum)); | |
#push(@singleGchartData, sprintf("%.2f", $count * 100 / $sum)); | |
} | |
$maxValue = max($maxValue, max(@singleGchartData)); | |
push(@gchartData, join(',',@singleGchartData)); | |
} | |
shift(@gchartData); #remove first empty element | |
$maxValue = ceil($maxValue / 10) * 10; | |
print 'http://chart.apis.google.com/chart?chxr=0,0,',$maxValue,'|1,',$min,',',$max,'&chxs=0,676767,11.5,0,lt,676767|1,676767,11.5,0,lt,676767&chxt=y,x&chs=600x400&cht=ls&chco=3366CC,3D7930,FF9900&chds=0,',$maxValue,',0,',$maxValue,',0,',$maxValue,'&chd=t:',join('|',@gchartData),"&chdl=",join('|',@gchartGroups),"&chls=1|1|1&chma=|0,10&chg=-1,-1,1,9\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment