I am trying to analyze call logs from our 3CX PBX in order to evaluate our peak calling hours. I would like to see for each day in said logs what was the max. simultaneous calls we had at one point during the day.
The call logs are stored in a CSV file and look like this. Each row represents a call from start to finish.
CallDate | CallStart | CallEnd |
---|---|---|
31.05.2021 | 11:09:37 | 11:10:29 |
31.05.2021 | 11:09:37 | 11:19:25 |
31.05.2021 | 11:09:40 | 11:11:41 |
31.05.2021 | 11:11:32 | 11:16:52 |
31.05.2021 | 11:12:06 | 11:14:15 |
31.05.2021 | 11:13:08 | 11:13:31 |
31.05.2021 | 11:13:42 | 11:17:02 |
31.05.2021 | 11:13:43 | 11:17:01 |
31.05.2021 | 11:15:18 | 11:16:07 |
31.05.2021 | 11:16:46 | 11:22:04 |
31.05.2021 | 11:16:58 | 11:27:18 |
31.05.2021 | 11:17:43 | 11:17:53 |
31.05.2021 | 11:18:53 | 11:19:22 |
31.05.2021 | 11:19:24 | 11:19:30 |
31.05.2021 | 11:19:24 | 11:21:15 |
31.05.2021 | 11:19:31 | 11:23:08 |
31.05.2021 | 11:20:21 | 11:20:35 |
31.05.2021 | 11:20:55 | 11:25:18 |
31.05.2021 | 11:21:07 | 11:21:56 |
31.05.2021 | 11:21:25 | 11:21:36 |
31.05.2021 | 11:21:39 | 11:28:50 |
31.05.2021 | 11:21:41 | 11:21:52 |
31.05.2021 | 11:22:22 | 11:22:43 |
31.05.2021 | 11:23:25 | 11:24:34 |
31.05.2021 | 11:24:10 | 11:29:53 |
31.05.2021 | 11:25:30 | 11:27:18 |
31.05.2021 | 11:27:57 | 11:28:32 |
31.05.2021 | 11:30:36 | 11:32:02 |
31.05.2021 | 11:31:44 | 11:32:09 |
31.05.2021 | 11:32:39 | 11:37:48 |
31.05.2021 | 11:34:19 | 11:50:04 |
31.05.2021 | 11:34:42 | 11:35:05 |
31.05.2021 | 11:35:35 | 11:39:09 |
31.05.2021 | 11:35:44 | 11:49:22 |
31.05.2021 | 11:36:41 | 11:37:00 |
31.05.2021 | 11:37:34 | 11:37:58 |
31.05.2021 | 11:37:57 | 11:38:33 |
31.05.2021 | 11:39:45 | 11:40:15 |
31.05.2021 | 11:39:56 | 11:41:20 |
31.05.2021 | 11:40:21 | 11:40:38 |
31.05.2021 | 11:41:17 | 11:42:07 |
31.05.2021 | 11:42:16 | 11:44:38 |
31.05.2021 | 11:42:52 | 11:46:54 |
31.05.2021 | 11:43:03 | 11:43:16 |
31.05.2021 | 11:43:35 | 11:44:17 |
31.05.2021 | 11:44:25 | 11:44:59 |
31.05.2021 | 11:44:59 | 11:48:00 |
31.05.2021 | 11:45:36 | 11:52:58 |
31.05.2021 | 11:45:48 | 11:46:11 |
31.05.2021 | 11:46:03 | 11:54:17 |
31.05.2021 | 11:46:11 | 11:46:42 |
31.05.2021 | 11:47:58 | 11:48:31 |
31.05.2021 | 11:50:19 | 11:50:26 |
31.05.2021 | 11:50:33 | 11:50:58 |
31.05.2021 | 11:50:36 | 11:50:43 |
31.05.2021 | 11:50:54 | 11:51:12 |
31.05.2021 | 11:51:19 | 11:51:28 |
31.05.2021 | 11:52:22 | 11:55:19 |
31.05.2021 | 11:53:43 | 11:55:24 |
31.05.2021 | 11:54:44 | 11:55:12 |
31.05.2021 | 11:55:45 | 11:55:55 |
31.05.2021 | 11:56:04 | 11:56:19 |
31.05.2021 | 11:56:26 | 11:56:28 |
31.05.2021 | 12:17:06 | 12:17:39 |
31.05.2021 | 12:17:53 | 12:18:39 |
31.05.2021 | 12:19:25 | 12:23:52 |
31.05.2021 | 12:20:02 | 12:23:02 |
31.05.2021 | 12:21:29 | 12:26:54 |
31.05.2021 | 12:33:27 | 12:39:38 |
31.05.2021 | 12:33:43 | 12:35:36 |
31.05.2021 | 12:39:46 | 12:40:52 |
31.05.2021 | 12:54:23 | 12:55:54 |
31.05.2021 | 12:55:17 | 12:55:39 |
31.05.2021 | 13:03:11 | 13:06:30 |
31.05.2021 | 13:04:47 | 13:13:33 |
31.05.2021 | 13:15:02 | 13:16:51 |
31.05.2021 | 13:16:14 | 13:16:49 |
31.05.2021 | 13:17:54 | 13:20:03 |
31.05.2021 | 13:27:53 | 13:29:41 |
31.05.2021 | 13:29:22 | 13:29:44 |
31.05.2021 | 13:29:56 | 13:38:59 |
31.05.2021 | 13:29:58 | 13:30:14 |
31.05.2021 | 13:30:26 | 13:34:24 |
31.05.2021 | 13:31:45 | 13:36:27 |
31.05.2021 | 13:32:04 | 13:33:03 |
31.05.2021 | 13:32:40 | 13:35:32 |
31.05.2021 | 13:34:54 | 13:35:24 |
31.05.2021 | 13:36:12 | 13:38:03 |
31.05.2021 | 13:38:24 | 13:39:05 |
31.05.2021 | 13:39:35 | 13:51:50 |
31.05.2021 | 13:42:12 | 13:56:16 |
31.05.2021 | 13:47:56 | 13:49:15 |
31.05.2021 | 13:49:55 | 13:55:08 |
31.05.2021 | 13:51:02 | 13:56:16 |
31.05.2021 | 13:55:17 | 13:55:27 |
31.05.2021 | 13:56:17 | 14:02:13 |
31.05.2021 | 14:00:35 | 14:01:27 |
31.05.2021 | 14:01:11 | 14:01:57 |
31.05.2021 | 14:02:13 | 14:03:54 |
31.05.2021 | 14:02:42 | 14:02:51 |
I think I'm quite close but I noticed a flaw in my logic. Currently, I compare if the CallStart of the next call is earlier than the CallEnd of the current call and if yes, that counts as a simultaneous call and I enter a while-loop that looks for more started calls before the end of the current call and add those too.
However, in this while-loop, I do not account for the possibility that one call might have ended while I am searching for more calls started earlier than the end date of the current call in my foreach loop which would account for one simultaneous call less.
Sorry if it is confusing. I hope you can understand what I am after.
Here is my script so far:
$CallDays = Import-Csv -Path C:\temp\calls.csv -Delimiter ";" | Group-Object {$_.CallDate}
$RawData = Import-Csv -Path C:\temp\calls.csv -Delimiter ";"
ForEach($CallDay in $CallDays)
{
$ActualCallDate = $CallDay.Name
if($ActualCallDate -eq "31.05.2021")
{
$AllCallsFromThatDay = $RawData | Where-Object CallDate -eq $ActualCallDate | Sort-Object -Property CallStart
[Object]$AllSimultaneousCalls = New-Object System.Collections.ArrayList
$SimultaneousCalls = 0
ForEach($Call in $AllCallsFromThatDay)
{
if($SimultaneousCalls - 1 -lt 0)
{
$SimultaneousCalls = 0
}
else
{
$SimultaneousCalls--
}
$CurrentRow = $AllCallsFromThatDay.IndexOf($Call)
$NextRow = $CurrentRow + 1
if($AllCallsFromThatDay[$CurrentRow] -ne $NULL)
{
$CurrentCallEnd = Get-Date ($ActualCallDate + " " + $Call.CallEnd)
$NextCallStart = Get-Date ($ActualCallDate + " " + ($AllCallsFromThatDay[$NextRow]).CallStart)
while($CurrentCallEnd -gt $NextCallStart)
{
$SimultaneousCalls++
$NextRow++
if($AllCallsFromThatDay[$NextRow] -ne $NULL)
{
$NextCallStart = Get-Date ($ActualCallDate + " " + ($AllCallsFromThatDay[$NextRow]).CallStart)
}
else
{
Break
}
}
$AllSimultaneousCalls.Add($SimultaneousCalls) | Out-Null
$SimultaneousCalls
}
}
Write-Host (($AllSimultaneousCalls | Measure-Object -Maximum).Maximum)
}
}
The output currently looks like this:
2
14
14
19
21
20
23
25
24
35
49
48
47
47
50
56
55
61
63
62
67
66
65
65
66
65
64
64
63
68
88
87
90
107
106
106
105
105
106
105
104
107
114
113
112
111
115
124
124
132
131
130
129
130
129
128
127
128
128
127
126
125
124
123
122
123
123
122
122
121
120
120
119
119
118
118
117
116
116
115
122
121
123
126
126
126
125
124
123
126
129
128
128
128
127
128
128
127
127
127
132
Thank you for any help!