InfluxQL:计算状态变化的周期
我的 InfluxDB 中有一个停车传感器表,它发送占用 (1) 和空置 (9) 的状态。 现在我想创建一个查询,显示状态更改之间的时间段,以便我可以创建停车场占用和空闲时间的报告。 数据由停车传感器生成,并通过 node-red 插入到 influxdb 中。 数据位于 Ubuntu 20.04 上的 InfluxDB 版本 1.8.10 中。 表数据实际上具有以下结构:
名称:parkinginfo |时间 |状态编号| | -------- | -------------- | | 1646302488500839186 | 1 | | 1646302488500203666 | 1 | | 1646302488499932866 | 2 | | 1646302488499826263 | 1 |
statusnumbered:1 = 空缺,2 = 占用
有人可以帮助我为此创建查询吗? 谢谢!
I have a table in my InfluxDB for a parking sensor which sends a state for occupied (1) and vacant (9).
Now I want to create a query which shows me the time period between the status changes so that I can create a report for the time the parkingslot was occupied and free.
The data is generated by the parking sensor and inserted via node-red into the influxdb.
The data is located in InfluxDB version 1.8.10 on Ubuntu 20.04.
The table data has actually the following structure:
name: parkinginfo
| time | statusnumbered |
| -------- | -------------- |
| 1646302488500839186 | 1 |
| 1646302488500203666 | 1 |
| 1646302488499932866 | 2 |
| 1646302488499826263 | 1 |
statusnumbered: 1 = vacant, 2 = occupied
Can someone help me for creating a query for this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 InfluxDB 中报告给定状态的总持续时间是可行的,但只能在 Flux 中报告,而不是在 InfluxQL 中(很容易)。
您可以:
通过配置更改在 v1.8 中启用 Flux 此处
样本通量可以是:
from(bucket: "yourDatabaseName/autogen") |>;范围(开始:2022-03-03T00:00:00Z,停止:2022-03-03T23:59:59Z)|>过滤器(fn:(r)=> r._measurement ==“yourMeasurementName”)|> stateDuration(fn: (r) => r._value == 1, 列: "状态", 单位: 1m)
from(bucket: "yourDatabaseName/autogen") |>;范围(开始:2022-03-03T00:00:00Z,停止:2022-03-03T23:59:59Z)|>过滤器(fn:(r)=> r._measurement ==“yourMeasurementName”)|> stateDuration(fn: (r) => r._value == 2, 列: "状态", 单位: 1m)
同样,尽管社区已经等待了一段时间,但在 InfluxQL 中仍然无法做到这一点。请在此处查看更多详细信息。
It is feasible to report the total duration for a given state in InfluxDB but only in Flux not InfluxQL (easily).
You could:
Enable Flux in v1.8 with the configuration change here
Sample Flux could be:
from(bucket: "yourDatabaseName/autogen") |> range(start: 2022-03-03T00:00:00Z, stop: 2022-03-03T23:59:59Z) |> filter(fn: (r) => r._measurement == "yourMeasurementName") |> stateDuration(fn: (r) => r._value == 1, column: "state", unit: 1m)
from(bucket: "yourDatabaseName/autogen") |> range(start: 2022-03-03T00:00:00Z, stop: 2022-03-03T23:59:59Z) |> filter(fn: (r) => r._measurement == "yourMeasurementName") |> stateDuration(fn: (r) => r._value == 2, column: "state", unit: 1m)
Again it's still not possible to do it in InfluxQL yet though the community has been waiting for this for a while. See more details here.