stats 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Convert the Y coordinate to an average
  2. eval "exec perl -sS $0 $*"
  3. if 0;
  4. @values = ();
  5. $sum = $n = 0;
  6. $min = 1.7E+308;
  7. $max = 2.2E-308;
  8. while (<>) {
  9. next if /^[%#]/;
  10. split;
  11. if ($_[0] > 1000000) {
  12. #warn "$file: ignoring $_";
  13. next;
  14. }
  15. if ($#_ >= 1) {
  16. $val = $_[1];
  17. } else {
  18. $val = $_[0];
  19. }
  20. push(@values, $val);
  21. $sum += $val;
  22. $min = $val if $val < $min;
  23. $max = $val if $val > $max;
  24. $n++;
  25. }
  26. # Do some statistics.
  27. @s = sort(@values);
  28. if ($n & 1) {
  29. $median = $s[($n + 1)/2];
  30. } else {
  31. $i = $n / 2;
  32. $median = ($s[$i] + $s[$i+1]) / 2;
  33. }
  34. $avg = $sum/$n;
  35. $avgdev = $var = 0;
  36. foreach $_ (@values) {
  37. $var += ($_ - $median) ** 2;
  38. $tmp = $_ - $median;
  39. $avgdev += $tmp > 0 ? $tmp : -$tmp;
  40. }
  41. $var /= $n - 1;
  42. $stddev = sqrt($var);
  43. $avgdev /= $n;
  44. #printf("%8s %8s %8s %8s %8s %4s %8s\n", "Min", "Max", "Average", "Median", "Std Dev", "%", "Avg Dev");
  45. #printf "%8.2f %8.2f %8.2f %8.2f %8.2f %4.1f%% %8.2f\n", $min, $max, $avg, $median, $stddev, $stddev/$median*100, $avgdev;
  46. printf "%4.1f%%\n", $stddev/$median*100;
  47. exit 0;