2

我在 Azure Monitor 日志中有这种格式的点击流数据:

       Timestamp             Category  Session_ID    Step_Name
10/22/2019, 9:28:14.868 AM      A        ++9Ti        step 1    
10/22/2019, 9:28:18.034 AM      A        ++9Ti        step 2    
10/22/2019, 9:28:22.487 AM      A        ++9Ti        step 3
10/23/2019, 7:02:02.527 AM      B        ++MoY        step 1    
10/23/2019, 7:02:09.244 AM      B        ++MoY        step 2    
10/23/2019, 7:02:21.156 AM      B        ++MoY        step 3        <-- 
10/23/2019, 7:02:27.195 AM      B        ++MoY        step 3        <--
10/23/2019, 7:15:13.544 AM      A        ++0a3        step 1    
10/23/2019, 7:15:35.438 AM      A        ++0a3        step 2        

我需要获取消费者在类别中的每个步骤上花费的平均时间

此外,当重复步骤时(如 session_ID = '++MoY' 中的步骤 3),我们需要在计算平均值时采用最新的时间戳。

示例:A 类第 2 步花费的平均时间为 (3.166 + 21.894)/2 = 12.53 秒。(注意:时间戳给出了完成步骤的时间)

4

1 回答 1

2

您可以尝试以下方法

a)使用arg_max()按步骤/类别获取最新的

b) 使用prev()afterorder by计算每个步骤的持续时间

datatable(Timestamp:datetime, Category:string, Session_ID:string, Step_Name:string)
[
    datetime(10/22/2019, 9:28:14.868 AM), 'A', '++9Ti', 'step 1',
    datetime(10/22/2019, 9:28:18.034 AM), 'A', '++9Ti', 'step 2',
    datetime(10/22/2019, 9:28:22.487 AM), 'A', '++9Ti', 'step 3',
    datetime(10/23/2019, 7:02:02.527 AM), 'B', '++MoY', 'step 1',
    datetime(10/23/2019, 7:02:09.244 AM), 'B', '++MoY', 'step 2',
    datetime(10/23/2019, 7:02:21.156 AM), 'B', '++MoY', 'step 3',
    datetime(10/23/2019, 7:02:27.195 AM), 'B', '++MoY', 'step 3',
    datetime(10/23/2019, 7:15:13.544 AM), 'A', '++0a3', 'step 1',
    datetime(10/23/2019, 7:15:35.438 AM), 'A', '++0a3', 'step 2',
]
| summarize arg_max(Timestamp, *) by Step_Name, Session_ID
| order by Session_ID asc, Timestamp asc
| extend duration = iff(Session_ID == prev(Session_ID), Timestamp - prev(Timestamp), 0s)
| summarize avg(duration) by Step_Name, Category
| where Step_Name == "step 2" and Category == "A"
于 2019-10-23T12:17:09.230 回答