addyrocker has asked for the wisdom of the Perl Monks concerning the following question:
Dear offerers of Perl Wisdom I have data with the following output
itemid FROM_UNIXTIME(clock) value 26603 2010-10-09 00:00:23 38784360.8136 26603 2010-10-09 00:01:23 36529742.6667 26603 2010-10-09 00:02:23 36966880.8000 26603 2010-10-09 00:03:23 35666405.8667 26603 2010-10-09 01:05:23 35600190.6667 26603 2010-10-09 02:06:23 39175029.2000 26603 2010-10-09 03:07:23 35386478.4000 26603 2010-10-09 04:08:27 35773482.7500 26603 2010-10-09 05:09:23 39073367.5714 26603 2010-10-09 06:10:23 34379049.8667 26603 2010-10-09 07:11:24 33984045.7705 26603 2010-10-09 09:12:23 36276301.8305 26603 2010-10-09 10:13:23 37248366.0000 up to time 23:59 26603 2010-10-09 23:59:23 39393421.3333
What I'm trying to do is count the number of readings/occurrences for each hour and divide that value to the sum of values for that hour. I've so far been only able to get the occurrences for each hour with the following code
#!/usr/bin/perl my $count={}; while (<>) { chop; @F = split; @J=split(/\:/,$F[2]); if ( $J[0] =~ /[0-9][0-9]/ ){ $count{$J[0]}++}; } foreach $key(sort(keys(%count))){ print "$key\t$count{$key}\n"; }
But I'm not able to get the hourly sum for each hour, I've tried different things like util sum and other code. If anyone can suggest a better way of summing up values based on hours I'll be really grateful
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calculate hourly averages
by roboticus (Chancellor) on Oct 15, 2010 at 15:15 UTC | |
|
Re: Calculate hourly averages
by toolic (Bishop) on Oct 15, 2010 at 15:19 UTC | |
|
Re: Calculate hourly averages
by dwm042 (Priest) on Oct 15, 2010 at 15:23 UTC | |
|
Re: Calculate hourly averages
by moritz (Cardinal) on Oct 15, 2010 at 15:28 UTC | |
|
Re: Calculate hourly averages
by locked_user sundialsvc4 (Abbot) on Oct 15, 2010 at 17:04 UTC | |
by addyrocker (Initiate) on Oct 20, 2010 at 13:02 UTC | |
|
Re: Calculate hourly averages
by Anonymous Monk on Oct 15, 2010 at 15:15 UTC |