现在,您的数字孪生生成器(预览版)数据已投影到事件中心,您可以使用 KQL 查询集进行检查,并通过 Real-Time 仪表板进行可视化。 在本教程的这一部分中,你将使用示例查询设置 KQL(Kusto 查询语言)查询集,以便从数据中提取见解,然后使用 Real-Time 仪表板可视化这些见解。
重要
此功能目前为预览版。
使用 KQL 查询数据
在你的 Tutorial_queryset 中,从教程的上一部分开始。
使用上述 + 查询窗格,创建以下新查询。 (有关创建 KQL 查询的详细信息,请参阅 KQL 查询集中的查询数据。
延迟状态
此查询通过将当前时间与到达下一站的预计时间与计划的到达时间进行比较,计算每个公交行程的延迟。
//Start with the function generated by the eventhouse projection to get your time series bus data
Bus_timeseries()
// Parse your travel‑time string into a timespan
| extend TimeToNextStationSpan = totimespan(TimeToNextStation)
// Compute when the bus will actually arrive
| extend PredictedArrival = PreciseTimestamp + TimeToNextStationSpan
// Compare that prediction to the schedule
| extend Delay = PredictedArrival - ScheduleTime
| extend DelayRounded = format_timespan(Delay, 'hh:mm:ss')
// Flag and label a delay of more than 5 minutes
| extend IsDelayed = Delay > 5m
| extend DelayLabel = iff(IsDelayed, "Delayed", "On‑Time")
// Select final output columns
| project
TripId,
BusLine,
StopCode,
DelayLabel,
DelayRounded,
PreciseTimestamp,
TimeToNextStationSpan,
PredictedArrival,
ScheduledArrival = ScheduleTime
运行查询并查看结果。
按站点的延误
此查询从公交站的角度计算有关延迟的信息,包括车站的平均延迟时间,以及到站的行程通常会晚多久。
// Compute delay for each event
let delays =
Bus_timeseries()
| extend TimeToNextStationSpan = totimespan(TimeToNextStation)
| extend PredictedArrival = PreciseTimestamp + TimeToNextStationSpan
| extend Delay = PredictedArrival - todatetime(ScheduleTime);
// Join to Stop metadata
delays
| join kind=inner (
Stop_property()
| project Stop_Code, DisplayName, Borough, Suggested_Locality
) on $left.StopCode == $right.Stop_Code
// Aggregate
| summarize
AvgDelayMinutes = avg(Delay) // average timespan
/ 1m, // convert to minutes
TotalRuns = count(),
LateRuns = countif(Delay > 5m)
by Stop_Code, DisplayName, Borough, Locality=Suggested_Locality
| extend PercentLate = round((todouble(LateRuns) / TotalRuns * 100), 2)
| sort by AvgDelayMinutes
运行查询并查看结果。
公交车线路延误情况
此查询从公交线路的角度计算有关延迟的信息,计算每条公交线路和站点代码组合的平均延迟。
Bus_timeseries()
| extend
// inline compute delay minutes without a two‑step PredictedArrival alias
DelayMinutes =
(
PreciseTimestamp
+ totimespan(TimeToNextStation)
- todatetime(ScheduleTime)
) / 1m
| summarize
AvgDelayMin = round(avg(DelayMinutes), 0) // round to whole minutes
by BusLine, StopCode
| sort by AvgDelayMin
运行查询并查看结果。
预计迟到时间
此查询根据当前时间和下一站到下一站的时间预测公共汽车是否迟到。
Bus_timeseries()
// Compute when the bus will actually arrive at the next stop
| extend PredictedArrival = PreciseTimestamp + totimespan(TimeToNextStation)
// Classify "will be late" as a boolean
| extend WillBeLate = PredictedArrival > todatetime(ScheduleTime) + 5m
// Select final output columns
| project
PreciseTimestamp,
StopCode,
PredictedArrival,
WillBeLate
运行查询并查看结果。
在 Real-Time 仪表板中将数据进行可视化
有了一些 KQL 查询,可以从数字孪生生成器(预览)数据中提取见解,现在可以在 Real-Time 仪表板中可视化这些查询的结果。
在本部分中,你将使用模板文件填充 Real-Time 仪表板,其中包含在上一部分中创建的查询中的数据,以及一些额外的查询。
下面是仪表板的外观(请注意上一部分中的查询:延迟状态、按车站的延迟、按公交和路线的延迟以及估计的延迟):
创建新的仪表板
首先,在 Fabric 工作区中创建一个空 Real-Time 仪表板。
实时仪表板存在于工作区的上下文中。 新的实时仪表板始终与创建时使用的工作区相关联。
- 浏览到所需的工作区。
- 选择 “+ 新建项 ”,然后选择 Real-Time 仪表板 项。
- 输入仪表板名称,然后选择“创建”。
在工作区中创建新的仪表板。
上传模板并连接数据源
接下来,使用模板文件,将先前 KQL 查询生成的磁贴填充到仪表板中。
从 GitHub 中的示例文件夹中下载 DTB+RTI_dashboard.json 仪表板模板: digital-twin-builder/bus-scenario。
在 Real-Time 仪表板中,选择管理选项卡,然后用文件替换。
打开下载的仪表板模板文件。 继续处理 迁移警告,标记模板中的数据库和工作区 ID 占位符值。
模板文件使用多个磁贴填充仪表板,尽管磁贴无法获取数据,因为尚未连接数据源。
在“管理”选项卡中,选择“数据源”。 此作将打开“ 数据源 ”窗格,其中包含数据的示例源。 选择 教程 数据源的编辑图标。
在 “数据库”下,选择下拉箭头和 Eventhouse /KQL 数据库。 选择 教程 KQL 数据库,然后选择 连接。 选择 “应用”,然后关闭 “数据源 ”窗格。
几秒钟后,视觉对象会填充数据库中的数据。
小窍门
仪表板将当前时间保留为 UTC,因此时间范围选择器可能与本地时间不匹配。 如果您在磁贴中看不到数据,请扩大时间范围。
花些时间浏览仪表板。 可以使用每个磁贴上的 “编辑 ”和 “浏览数据 ”图标来查看基础查询,尝试更改时间范围筛选器和其他磁贴选项,并尝试添加自己的新查询和磁贴。
通过此可视化效果,将数字孪生生成器(预览版)与 Real-Time Intelligence 配合使用的端到端教程已完成。 你使用数字孪生工具为来自 Real-Time Intelligence 的流式传输示例总线数据提供上下文,然后将本体数据映射到 Eventhouse,以便通过 KQL 查询和 Real-Time 仪表板获取更深入的见解。
相关内容
详细了解本教程中使用的 KQL 运算符: