Created
December 18, 2017 22:28
-
-
Save scottchiefbaker/32238f772b542096d6e891db15d1cbe3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Data::Dump::Color; | |
use Date::Parse; | |
############################################################################### | |
############################################################################### | |
my $calls = []; | |
my @starts = (); | |
# Gather up all the starts/stops | |
while (<>) { | |
my @col = split(",",$_); | |
my $start = $col[4]; | |
my $duration = $col[5]; | |
$start =~ s/"//g; | |
my @tp = split(/[\/ :]/,$start); | |
my $time = str2time($start); | |
$duration =~ s/"//g; | |
my @p = split(":",$duration); | |
my $dst = ($p[1] * 60) + $p[2]; | |
my $end = $time + $dst; | |
push(@$calls,[$time,$end]); | |
push(@starts,$time); | |
} | |
# $calls is a list of all the starts/stops of calls | |
# $starts is a list of all the start times of each call | |
# Loop through each call and see how many calls were going on at that time | |
foreach my $s (@starts) { | |
my $c = count_calls($s); | |
my $ts = localtime($s); | |
print "On '$ts' there were $c calls\n"; | |
} | |
############################################################################### | |
############################################################################### | |
# Go through the big list of calls and count how many were going on during a given reference point | |
sub count_calls { | |
my $time = shift(); | |
my $ret = 0; | |
foreach (@$calls) { | |
my $os = $_->[0]; | |
my $oe = $_->[1]; | |
if ($time >= $os && $time <= $oe) { | |
$ret++; | |
#print "Time $time is between $os and $oe\n"; | |
} | |
} | |
return $ret; | |
} | |
sub trim { | |
if (wantarray) { | |
my @ret; | |
foreach (@_) { | |
push(@ret,scalar(trim($_))); | |
} | |
return @ret; | |
} else { | |
my $s = shift(); | |
if (length($s) == 0) { return ""; } | |
$s =~ s/^\s*//; | |
$s =~ s/\s*$//; | |
return $s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment