#! perl -slw use strict; use GD::Graph::lines; use GD::Graph::colour qw(:colours :lists :files :convert); use Data::Dump qw[ pp ]; use List::Util qw[ sum ]; our $MOVES ||= 4; our $SRAND ||= 1; our $EXTRA ||= 0; my @rounds = $EXTRA ? ( 44, 90, 100, 110, 120 ) : ( 44, 90, 120 ); my @data = ( [], [], [] ); my @moving; while( ) { my( $hrs, $mins, $val ) = split ':|,'; my $time = $hrs + $mins / 60; push @{ $data[ 0 ] }, $time; push @{ $data[ 1 ] }, $val; push @moving, $val; next if $#moving < ($MOVES / 2); shift @moving if @moving >= $MOVES; my $ave = sum( @moving ) / @moving; my $i = 0; ++$i while $rounds[ $i ] < $ave; $ave = abs( $ave - $rounds[ $i - 1 ] ) < abs( $ave - $rounds[ $i ] ) ? $rounds[ $i - 1 ] : $rounds[ $i ]; push @{ $data[ 2 ] }, $ave; } #pp \@data; <>; my $file = '789655.png'; my $graph = GD::Graph::lines->new(3000, 768); $graph->set( 'bgclr' => 'white', 'transparent' => 0, 'interlaced' => 1, title => 'Some simple graph', x_label => 'X Label', x_max_value => 24, x_min_value => 0, x_tick_number => 24, y_label => 'Y label', y_max_value => 180, y_min_value => 0, y_tick_number => 12, y_label_skip => 2, y_long_ticks => 1, ) or die $graph->error; my $gd = $graph->plot(\@data) or die $graph->error; open IMG, '>', $file or die $!; binmode IMG; print IMG $gd->png; close IMG; system $file; ## Load the graph into the local default image viewer __DATA__