Skip to content

Instantly share code, notes, and snippets.

@scottchiefbaker
Created December 18, 2017 22:28
Show Gist options
  • Select an option

  • Save scottchiefbaker/32238f772b542096d6e891db15d1cbe3 to your computer and use it in GitHub Desktop.

Select an option

Save scottchiefbaker/32238f772b542096d6e891db15d1cbe3 to your computer and use it in GitHub Desktop.

Revisions

  1. scottchiefbaker created this gist Dec 18, 2017.
    84 changes: 84 additions & 0 deletions mitel-parse.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    #!/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;
    }
    }