I don't know much statistics, but it seemed like the average of the last x samples would do what you want. This code behaves how I interpreted what you want, changing samples will change how much data it holds to average over, that would be a matter of preference on your part. I would think if you don't restrict the samples you'll just end up with jibberhish, assuming you are sampling some source for this data on a regular basis. If that is the case than this will tell you if at any point the last x samples averaged over 15:1.

use strict; use warnings; use Data::Dumper; my @que = (); my $sample = 5; sub average_ratio { my @data = @_; my $ratio = 0; for (@data) { $ratio = $ratio + ($_->[1] != 0 ? ($_->[0] / $_->[1]) : 0); } return $ratio / scalar @data; } while(my $line = <DATA>) { chomp $line; my ($po, $fr) = split (m/\s/, $line); push @que, [$po, $fr]; shift @que if @que > $sample; my $avg = average_ratio(@que); print "Adding [$po,\t $fr]\t makes the avg_ratio: $avg\n"; print "DANGER\n" if $avg > 15; } __DATA__ 0 0 0 0 150 10 0 0 200 40 210 40 220 40 220 30 0 0 0 0 0 0 220 20 220 10 220 05 220 01 220 100 220 100 2200 100 2200 2 2200 2 0 0 2200 1 0 0 0 0 0 0 0 0 0 0 0 0

___________
Eric Hodges

In reply to Re: A lesson in statistics by eric256
in thread A lesson in statistics by 0xbeef

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.