in reply to Re: How to Determine Stable Y-Values... or Detect an Edge..?
in thread How to Determine Stable Y-Values... or Detect an Edge..?

Try C&P'ing your csv file after the __DATA_ tag, and run it with -MOVES=10

#! 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( <DATA> ) { 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__

Looking at the plot, there seem to be extra stable-ish plateaus at 100 and 110 as well as those at 44, 90 & 120. If you compare with and without those extra round points you'll see what I mean. Use -EXTRA on the command line to use them.

If you need just the 3 levels, the setting -MOVES=50 seems to produce good results.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW It is as I've been saying!(Audio until 20090817)