如果输入参数发生变化,有没有办法计算流分析的持续时间?

Is there a way to calculate the duration in stream analytics in case a input parameter has changed?

我正在尝试计算来自连接到 Azure IoT 中心和流分析的数据记录器的信号 (DI_1) 的持续时间。

输入数据如下:

DateTime              Digital Input
22.04.2019 14:17:00        0
22.04.2019 14:16:00        1
22.04.2019 14:15:00        0
22.04.2019 14:14:00        0
22.04.2019 14:13:00        0
22.04.2019 14:12:00        0
22.04.2019 14:11:00        1
22.04.2019 14:10:00        1
22.04.2019 14:09:00        1
22.04.2019 14:08:00        1
22.04.2019 14:07:00        1
22.04.2019 14:06:00        0
22.04.2019 14:05:00        0
22.04.2019 14:04:00        0
22.04.2019 14:03:00        0
22.04.2019 14:02:00        1
22.04.2019 14:01:00        1
22.04.2019 14:00:00        0

结果应该是这样的:

DateTime               Duration
22.04.2019 14:16:00    00:01:00
22.04.2019 14:07:00    00:05:00
22.04.2019 14:01:00    00:02:00

有没有人知道如何在 Azure 流分析中实现它?

目前 ASA 输出是一个数据集,当数字输入发生变化时,时间和数字输入(1 或 0)。

DateTime              Digital Input
22.04.2019 14:17:00        0
22.04.2019 14:16:00        1
22.04.2019 14:15:00        0
22.04.2019 14:14:00        1
22.04.2019 14:13:00        0
22.04.2019 14:12:00        1

通过以下代码实现:

SELECT 
  PE, UID, system.timestamp AS Time,
  GetArrayElement(GetArrayElement(Record,0), 3) AS DI_0
INTO
   [PowerBI]
FROM
   [IoTHub]
WHERE
LAG(GetArrayElement(GetArrayElement(Record,0), 3), 1) 
OVER (LIMIT DURATION(minute, 10)) <> GetArrayElement(GetArrayElement(Record,0), 3)

这里我要计算PowerBI中的时差。现在我想直接在 azure 流分析中计算它以避免在 PowerBI 中计算。

非常感谢您的帮助!

我刚刚解决了:

SELECT
   UID,
   GetArrayElement(GetArrayElement(Record,0),3) AS DI_0,
   system.timestamp AS Start
FROM
   [IotHub]
WHERE
   LAG(GetArrayElement(GetArrayElement(Record,0), 3),1)
   OVER (LIMIT DURATION(minute, 10)) <> 
   GetArrayElement(GetArrayElement(Record,0), 3))

SELECT   
   DATEDIFF (second, LAG(system.timestamp,1)
   OVER (LIMIT DURATION(minute, 10)), system.timestamp) AS zeitdiff,
   UID, Start, DI_0
INTO
   [toPowerBI]
FROM
   Startzeit 
WHERE
   UID = 'WISE-4012_00D0C9E43D10'