我的Azure Monitor日志中的Clickstream数据采用以下格式:
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秒。 (注意:时间戳记给出了完成步骤的时间)
答案 0 :(得分:1)
您可以尝试以下操作
a)使用arg_max()
按步骤/类别获取最新信息
b)在prev()
之后使用order 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"