我正在尝试分析来自 3CX PBX 的通话记录,以评估我们的通话高峰时间。我想在所述日志中查看每天的最大值是多少。我们在一天中的某个时间同时通话。
通话记录存储在 CSV 文件中,如下所示。每行代表一个从开始到结束的调用。
通话日期 | 呼叫开始 | 通话结束 |
---|---|---|
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 |
我想我已经很接近了,但我注意到我的逻辑有一个缺陷。目前,我比较下一次呼叫的 CallStart 是否早于当前呼叫的 CallEnd,如果是,则算作同时呼叫,然后我进入一个 while 循环,在当前呼叫结束之前查找更多已启动的呼叫并添加这些。
但是,在这个 while 循环中,我没有考虑到一个呼叫可能已经结束的可能性,而我正在搜索比我的 foreach 循环中当前呼叫的结束日期更早开始的更多呼叫,这将减少一个同时呼叫.
对不起,如果它令人困惑。我希望你能明白我在追求什么。
到目前为止,这是我的脚本:
$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)
}
}
当前的输出如下所示:
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
感谢您的任何帮助!