|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: |
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use List::Util qw(sum);
##### Open files
open(my $IN,"invim2.vim") or die "Could not open input: $!\n";
open(my $OUT,">outvim2.vim") or die "Could not open output: $!\n";
my @avgs1;
my @avgs2;
my ($maxavg1, $minavg1, $maxavg2, $minavg2);
##### Step 1: read a line, and split it on comma
while(<$IN>){
chomp;
my @arr = split /,/;
next unless @arr;
# discard 1st and 2nd last and last item
# shift @arr;
# pop @arr;
# pop @arr;
# pop @arr;
##### Step 2: Sort data into ascending order
@arr = sort {$a <=> $b} @arr;
# print "arr @arr\n";
##### Step 3: Calculate difference between neighboring pairs
my @diff = (map {$arr[$_] - $arr[$_-1]} (1..$#arr));
# print "diff @diff\n";
##### Step 4: Calculate amount in each group
my @groups = (0)x5;
foreach my $a (@arr) {
$groups[$a/10]++;
}
# print "group @groups\n";
##### Step 5: Calculate average
my $avg1 = sum(@arr)/@arr;
# printf "arr avg %.2f\n", $avg1;
if(!$maxavg1 || $avg1 > $maxavg1) { $maxavg1 = $avg1; }
if(!$minavg1 || $avg1 < $minavg1) { $minavg1 = $avg1; }
push @avgs1, $avg1;
my $avg2 = sum(@diff)/@diff;
# printf "diff avg %.2f\n", $avg2;
if(!$maxavg2 || $avg2 > $maxavg2) { $maxavg2 = $avg2; }
if(!$minavg2 || $avg2 < $minavg2) { $minavg2 = $avg2; }
push @avgs2, $avg2;
##### Step 6: Print results
print $OUT join("\t", @arr) . "\tavg " . sprintf("%.2f\t", $avg1) . "group " . join("", @groups) . "\n";
print $OUT join("\t", @diff) . "\t\tavg " . sprintf("%.2f\t", $avg2) . "\n";
print $OUT "\n";
}
# printf "input: maxavg %d minavg %d avgavg %d\n", $maxavg1, $minavg1, sum(@avgs1)/@avgs1;
printf $OUT "For data values:\t\t avg avg %.2f\t maximum avg %.2f\t minimum avg %.2f \n", sum(@avgs1)/@avgs1, $maxavg1, $minavg1 ;
# printf "diff: maxavg %d minavg %d avgavg %d\n", $maxavg2, $minavg2, sum(@avgs2)/@avgs2;
printf $OUT "For data difference values:\t avg avg %.2f\t maximum avg %.2f\t minimum avg %.2f \n", sum(@avgs2)/@avgs2, $maxavg2, $minavg2, ;
close($IN);
close($OUT);
|
Advertisement
| Hall of Fame |