汇总在串联字符串中选择选项的次数 true/false
Summarizing amount of times options are selected true/false in a concatenated string
我是 KQL 的新手,使用它时遇到了困难(我没有统计背景,而且我也不是很擅长 SQL)。我有来自 Microsoft AppCenter 的遥测数据,我想将其解析成一些图表,但我试图首先弄清楚如何拆分一个连接的字符串,该字符串本质上是一个具有两个可能值的字典:true 和 false。我想计算每个键的数量,所以每个键都有 2 个值 (true/false),每个值也都有一个数字计数值。
我试图从中获取此数据的输入字符串的格式为 Remove Splash/Main Menu Branding=True;Disable Aim Assist=False
- 唯一项由 ; 分割每对被=分开。我试图弄清楚我的用户正在以这种方式使用哪些选项。此处的示例字符串将拆分为:
Remove Splash/Main Menu Branding = True (count 1)
Disable Aim Assist = False (count 1).
如果新项目是 Remove Splash/Main Menu Branding=True;Disable Aim Assist=True
,则汇总数据将是
Remove Splash/Main Menu Branding = True (count 2)
Disable Aim Assist = False (count 1).
Disable Aim Assist = True (count 1).
到目前为止,我有一个选择单个项目的查询,但我不知道如何跨多行计算它:
customEvents
| where timestamp > ago(7d)
| where name == "Installed a mod"
| extend Properties = todynamic(tostring(customDimensions.Properties))
| where isnotnull(Properties.["Alternate Options Selected"])
| extend OptionsStr = Properties.["Alternate Options Selected"] //The example string in above
| extend ModName = Properties.["Mod name"]
| where ModName startswith "SP Controller Support" //want to filter only to one mod's options
| extend optionsSplit = split(OptionsStr, ";")
| summarize any(optionsSplit)
虽然我不确定如何在字典中计算它。如果有人对此有任何建议或提示或示例,我将不胜感激,谢谢。
给你:
let MyTable = datatable(Flags:string) [
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=False",
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=True"
];
MyTable
| extend Flags = split(Flags, ";")
| mv-expand Flag = Flags to typeof(string)
| summarize Count = count() by Flag
这个输出是:
| Flag | Count |
|---------------------------------------|-------|
| Remove Splash/Main Menu Branding=True | 2 |
| Disable Aim Assist=False | 1 |
| Disable Aim Assist=True | 1 |
解释:
- 首先,您将每个输入字符串(包含多个标志)拆分为子字符串,以便每个子字符串只有一个标志 - 您可以使用
split
. 实现此目的
- 现在你的新
Flags
列有一个字符串列表(每个字符串包含一个标志),你想为每个字符串创建一个记录,所以你使用 mv-expand
运算符
- 最后,你想计算每个 key=value 对出现的次数,你用
summarize count() by Flag
如果您想在每个键中查看一条记录(在输出中),则可以改用以下查询:
let MyTable = datatable(Flags:string) [
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=False",
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=True"
];
MyTable
| extend Flags = split(Flags, ";")
| mv-expand Flag = Flags to typeof(string)
| parse Flag with Key "=" Value
| project Key, Value
| evaluate pivot(Value, count(Value))
它的输出是:
| Key | False | True |
|----------------------------------|-------|------|
| Remove Splash/Main Menu Branding | 0 | 2 |
| Disable Aim Assist | 1 | 1 |
您写道您是 KQL 的新手,因此您可能会发现以下免费的 Pluralsight 课程很有趣:
P.S。以后请提供 datatable
格式的示例输入(如果您使用的是 Kusto Explorer,只需 select 相关查询结果,right-click 在 selection 上,然后单击Copy as datatable() literal
),以及 table 格式的预期输出,这样会更容易理解您想要实现的目标。
我是 KQL 的新手,使用它时遇到了困难(我没有统计背景,而且我也不是很擅长 SQL)。我有来自 Microsoft AppCenter 的遥测数据,我想将其解析成一些图表,但我试图首先弄清楚如何拆分一个连接的字符串,该字符串本质上是一个具有两个可能值的字典:true 和 false。我想计算每个键的数量,所以每个键都有 2 个值 (true/false),每个值也都有一个数字计数值。
我试图从中获取此数据的输入字符串的格式为 Remove Splash/Main Menu Branding=True;Disable Aim Assist=False
- 唯一项由 ; 分割每对被=分开。我试图弄清楚我的用户正在以这种方式使用哪些选项。此处的示例字符串将拆分为:
Remove Splash/Main Menu Branding = True (count 1)
Disable Aim Assist = False (count 1).
如果新项目是 Remove Splash/Main Menu Branding=True;Disable Aim Assist=True
,则汇总数据将是
Remove Splash/Main Menu Branding = True (count 2)
Disable Aim Assist = False (count 1).
Disable Aim Assist = True (count 1).
到目前为止,我有一个选择单个项目的查询,但我不知道如何跨多行计算它:
customEvents
| where timestamp > ago(7d)
| where name == "Installed a mod"
| extend Properties = todynamic(tostring(customDimensions.Properties))
| where isnotnull(Properties.["Alternate Options Selected"])
| extend OptionsStr = Properties.["Alternate Options Selected"] //The example string in above
| extend ModName = Properties.["Mod name"]
| where ModName startswith "SP Controller Support" //want to filter only to one mod's options
| extend optionsSplit = split(OptionsStr, ";")
| summarize any(optionsSplit)
虽然我不确定如何在字典中计算它。如果有人对此有任何建议或提示或示例,我将不胜感激,谢谢。
给你:
let MyTable = datatable(Flags:string) [
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=False",
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=True"
];
MyTable
| extend Flags = split(Flags, ";")
| mv-expand Flag = Flags to typeof(string)
| summarize Count = count() by Flag
这个输出是:
| Flag | Count |
|---------------------------------------|-------|
| Remove Splash/Main Menu Branding=True | 2 |
| Disable Aim Assist=False | 1 |
| Disable Aim Assist=True | 1 |
解释:
- 首先,您将每个输入字符串(包含多个标志)拆分为子字符串,以便每个子字符串只有一个标志 - 您可以使用
split
. 实现此目的
- 现在你的新
Flags
列有一个字符串列表(每个字符串包含一个标志),你想为每个字符串创建一个记录,所以你使用mv-expand
运算符 - 最后,你想计算每个 key=value 对出现的次数,你用
summarize count() by Flag
如果您想在每个键中查看一条记录(在输出中),则可以改用以下查询:
let MyTable = datatable(Flags:string) [
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=False",
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=True"
];
MyTable
| extend Flags = split(Flags, ";")
| mv-expand Flag = Flags to typeof(string)
| parse Flag with Key "=" Value
| project Key, Value
| evaluate pivot(Value, count(Value))
它的输出是:
| Key | False | True |
|----------------------------------|-------|------|
| Remove Splash/Main Menu Branding | 0 | 2 |
| Disable Aim Assist | 1 | 1 |
您写道您是 KQL 的新手,因此您可能会发现以下免费的 Pluralsight 课程很有趣:
P.S。以后请提供 datatable
格式的示例输入(如果您使用的是 Kusto Explorer,只需 select 相关查询结果,right-click 在 selection 上,然后单击Copy as datatable() literal
),以及 table 格式的预期输出,这样会更容易理解您想要实现的目标。