gpt4 book ai didi

用于检测特定 deviceId 缺失事件事件的 Azure 流分析查询

转载 作者:行者123 更新时间:2023-12-03 01:04:13 24 4
gpt4 key购买 nike

我没有找到一种方法可以使用 azure 流分析查询语言来分析缺少特定事件的流。该流可能包含 DeviceAlive 和 BeaconDetected 事件,其中包含 DeviceId,并且在 BeaconDetected 的情况下还包含 BeaconId。现在,如果 DeviceAlive 事件丢失,我想生成一个错误事件。

我怎样才能实现这个目标?我尝试将引用数据与所有有效的 deviceId 一起使用。但我不允许执行这样的 linq-wise“包含”查询

SELECT * FROM
inputStream
WHERE DeviceId IN (SELECT Id FROM DeviceReferenceData)

我该如何进行这样的查询。通过将 inputStream 与 DeviceReferenceData 表连接起来可以实现这一点吗?我想我只是没有看到明显的事情。

事件例如看起来像这样:

 {
"EventType": "DeviceAlive",
"DeviceId": "winiot-pi",
"EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
},
{
"EventType": "BeaconDetected",
"BeaconId": "2",
"DeviceId": "winiot-pi",
"EventEnqueuedUtcTime": "2018-11-19T11:00:20.5594584+01:00"
}

执行这样的查询不会产生预期的结果:

SELECT
iothub.*,r.id as rerId
into output
FROM
iothub TIMESTAMP BY EventEnqueuedUtcTime
Left OUTER Join devicesReference r on iothub.DeviceId = r.Id

这只会为每个 DeviceAlive 事件返回 NULL referenceId。 csv 输出:

eventenqueuedutctime;EventType;BeaconId;DeviceId;SignalStrength;rerid
19.11.2018 10:00:20;BeaconDetected;1;winiot-pi;-40;winiot-pi
19.11.2018 10:00:20;BeaconDetected;1;winiot-pi2;-80;winiot-pi2
19.11.2018 10:00:20;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
19.11.2018 10:00:21;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
19.11.2018 10:00:21;BeaconDetected;2;winiot-pi;-80;winiot-pi
19.11.2018 10:00:21;BeaconDetected;2;winiot-pi2;-40;winiot-pi2
19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi;winiot-pi;;
19.11.2018 10:00:25;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
19.11.2018 10:00:31;BeaconDetected;1;winiot-pi2;-40;winiot-pi2
19.11.2018 10:00:31;BeaconDetected;1;winiot-pi;-80;winiot-pi
19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:00:32;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:00:33;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
19.11.2018 10:00:36;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:00:46;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
19.11.2018 10:00:46;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:00:57;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
19.11.2018 10:00:57;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:01:07;BeaconDetected;2;winiot-pi2;-80;winiot-pi2
19.11.2018 10:01:07;BeaconDetected;2;winiot-pi;-40;winiot-pi
19.11.2018 10:01:20;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;
19.11.2018 10:01:30;ReceiverDeviceAlive;winiot-pi2;winiot-pi2;;

但是我需要的是每个时间窗口的信息,即使该窗口不包含任何事件。我想我们可以把它分解为这个问题:如何查询和查看没有所需事件的时间窗口。这完全可能吗?

感谢您的帮助。

最佳答案

与同事交谈是一个很好的建议,即使他并不完全理解您在说什么。 ;-)以下是通过借助引用设备表检测专用设备在 30 秒窗口内是否存在事件事件来生成错误事件的解决方案。这些链接帮助我更多地了解它:

azure stream analytics query to detect missing alive event for a specific device

how to find absence of signal in a stream analytics job

WITH OneEvent AS /* generate one event per period, any event */
(
SELECT
COUNT(*) As eventCount,
System.Timestamp as EndOfWindow
FROM iothub TIMESTAMP BY EventEnqueuedUtcTime
GROUP BY TumblingWindow(s, 30)
),
AllReferenceDevices AS /* generate one event per deviceId per period */
(
SELECT devicesReference.Id, OneEvent.EndOfWindow
FROM OneEvent JOIN devicesReference
ON OneEvent.EndOfWindow = OneEvent.EndOfWindow
),
/* Select only the devices where we cannot find an event for */
DeviceConnectivityErrorDetection AS
(
SELECT
'DeviceConnectivityErrorDetected' AS EventType,
AllReferenceDevices.Id as FromDeviceId,
AllReferenceDevices.Id as ToDeviceId,
AllReferenceDevices.EndOfWindow as EventEnqueuedUtcTime
FROM
AllReferenceDevices
LEFT join iothub TIMESTAMP BY EventEnqueuedUtcTime
ON DATEDIFF(s, iothub, AllReferenceDevices ) BETWEEN 0 and 30
AND iothub.DeviceId = AllReferenceDevices.Id
WHERE iothub IS NULL
)


SELECT *
INTO ReceiverDeviceConnectivityErrorDetectedOutput
FROM DeviceConnectivityErrorDetection

关于用于检测特定 deviceId 缺失事件事件的 Azure 流分析查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53416560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com