WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite. Learn more about what this means for you and how you can improve your security with WatchGuard today!
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
my $file = shift;
open(F, $file);
my @count_3 = ();
my $working_date = '';
my $working_time = '';
my $working_hour = 0;
my @avgs = ();
use Data::Dumper;
use List::Util qw(sum);
sub convert_hour($$) {
my $hour = shift;
my $minutes = shift;
return 60 * $hour + $minutes;
}
while (<F>) {
next unless /\S/;
chomp;
my (@data) = split(/\,/);
next unless $data[1] =~ m|(\d+/\d+/\d+) (\d+)\:(\d\d)|;
my $current_date = $1;
my $current_time = "$1 $2:$3";
my $current_hour = convert_hour($2,$3);
next if $data[2] < 0 || $data[2] == 999;
if ($current_date ne $working_date) {
$working_date = $current_date;
$working_time = $current_time;
$working_hour = $current_hour;
@count_3 = ($data[2]);
next;
}
if ($current_hour >= $working_hour + 180 && @count_3 >= 3) {
push(
@avgs,
[$data[0], $working_time, sum(@count_3)/@count_3],
);
@count_3 = ();
$working_time = $current_time;
$working_hour = $current_hour;
}
push(@count_3, $data[2]);
}
print join(
"\n", map(
join(" ",@{$_}),
@avgs)
), "\n";
You want to convert values for every date to three average:
One between 00:00 and 07:59
One between 08:00 and 15:59
One between 16:00 and 23:59
Ignoring negative values and 999 ?
Right?