session_count 插件session_count plugin
针对某个时间线基于 ID 列计算会话计数。Calculates sessions count based on ID column over a timeline.
T | evaluate session_count(id, datetime_column, startofday(ago(30d)), startofday(now()), 1min, 30min, dim1, dim2, dim3)
语法Syntax
T | evaluate
session_count(
IdColumn,
TimelineColumn,
Start,
End,
Bin,
LookBackWindow [,
dim1,
dim2,
...])
T | evaluate
session_count(
IdColumn,
TimelineColumn,
Start,
End,
Bin,
LookBackWindow [,
dim1,
dim2,
...])
参数Arguments
- T :输入表格表达式。T : The input tabular expression.
- IdColumn:列的名称,其 ID 值表示用户活动。IdColumn : The name of the column with ID values that represent user activity.
- TimelineColumn:表示时间线的列的名称。TimelineColumn : The name of the column that represents the timeline.
- 开始 :带有分析开始时段值的标量。Start : Scalar with value of the analysis start period.
- End:带有分析结束时段值的标量。End : Scalar with value of the analysis end period.
- Bin :会话分析步骤时间段的标量常数值。Bin : scalar constant value of session analysis step period.
- LookBackWindow :表示会话回看期的标量常数值。LookBackWindow : scalar constant value representing session lookback period. 如果
IdColumn
中的 ID 在LookBackWindow
之内的时间窗口中出现,则该会话被视为现有会话。If the ID fromIdColumn
appears in a time window withinLookBackWindow
, the session is considered to be an existing one. 如果该 ID 未出现,则该会话被视为新会话。If the ID doesn't appear, then the session is considered to be new. - dim1 , dim2 , ...:(可选)维度列的列表,用于切分会话计数计算。dim1 , dim2 , ...: (optional) list of the dimensions columns that slice the session count calculation.
返回Returns
返回一个表,该表包含每个时间线期间的以及每个现有维度组合的会话计数值。Returns a table that has the session count values for each timeline period and for each existing dimensions combination.
输出表架构如下:Output table schema is:
TimelineColumnTimelineColumn | dim1dim1 | .... | dim_ndim_n | count_sessionscount_sessions |
---|---|---|---|---|
类型:自 TimelineColumn 起type: as of TimelineColumn | .... | .... | .... | longlong |
示例Examples
对于此示例,数据是确定性的,并且我们使用具有两列的表:For this example, the data is deterministic, and we use a table with two columns:
- 时间线:一个 1 至 10,000 之间的顺序号Timeline: a running number from 1 to 10,000
- ID:1 至 50 之间的用户 IDId: Id of the user from 1 to 50
如果 Id
是 Timeline
的除数(时间线 % Id == 0),则该 ID 会出现在特定的 Timeline
时段。Id
appears at the specific Timeline
slot if it's a divider of Timeline
(Timeline % Id == 0).
Id==1
的事件将出现在任何 Timeline
时段,Id==2
的事件将每隔一个 Timeline
时段出现,依此类推。An event with Id==1
will appear at any Timeline
slot, an event with Id==2
at every second Timeline
slot, and so on.
下面是很少的 20 行数据:Here are few 20 lines of the data:
let _data = range Timeline from 1 to 10000 step 1
| extend __key = 1
| join kind=inner (range Id from 1 to 50 step 1 | extend __key=1) on __key
| where Timeline % Id == 0
| project Timeline, Id;
// Look on few lines of the data
_data
| order by Timeline asc, Id asc
| limit 20
时间线Timeline | IDId |
---|---|
11 | 11 |
22 | 11 |
22 | 22 |
33 | 11 |
33 | 33 |
44 | 11 |
44 | 22 |
44 | 44 |
55 | 11 |
55 | 55 |
66 | 11 |
66 | 22 |
66 | 33 |
66 | 66 |
77 | 11 |
77 | 77 |
88 | 11 |
88 | 22 |
88 | 44 |
88 | 88 |
我们换一种说法来定义会话:只要用户 (Id
) 在 100 个时段的时间范围内出现至少一次,而会话回看窗口是 41 个时段,则会话被视为活跃。Let's define a session in next terms: session considered to be active as long as user (Id
) appears at least once at a timeframe of 100 time slots, while session look-back window is 41 time slots.
下一个查询根据上述定义显示活跃会话的计数。The next query shows the count of active sessions according to the definition above.
let _data = range Timeline from 1 to 9999 step 1
| extend __key = 1
| join kind=inner (range Id from 1 to 50 step 1 | extend __key=1) on __key
| where Timeline % Id == 0
| project Timeline, Id;
// End of data definition
_data
| evaluate session_count(Id, Timeline, 1, 10000, 100, 41)
| render linechart