infuluxdb查询以返回给定时间板上的记录

发布于 2025-02-06 21:07:32 字数 736 浏览 3 评论 0原文

我正在使用时间序列分析,我正在使用涌入数据库来绘制有趣的图形。

用例

因此,这是我正在建立一个物联网项目来监视我的办公桌工厂的 。每次水分降至10%时,我都会触发泵并在InfuxdB上注册该活动。每次泵开时,都会注册另一个活动。

这是行协议中的一点

,该行程得以保存活动,操作=泵,传感器= 628CFBDDF5D8735E30504021,控制器= 61DD1BFA47E99385A5555555555555533,org = 61C06A2ADCFA2554DDA76676666616166161C 799,type = on count = 1i 1653406685616

activities,action=pump,sensor=628cfbddf5d8735e30504021,controller=61dd1bfa47e99385a55d4853,org=61c06a2adcfa254dda756796,service=61c06a7edcfa254dda756799,type=off count=1i 1653406871246

As you can see, I have a few ids stored as tags and only count= 1存储在现场。

挑战

因此,这是我想绘制NO图的 。在过去30天的时间里,泵每天每天都会切换泵。 我尝试了几种方法,但无法找到解决此问题的方法。

我真的希望这种用例可以实现。谢谢

Im using time series analysis and I'm using influx db to plot interesting graphs.

So here's the use case

I'm building an IOT project to monitor my desk plant. every time the moisture goes down to 10%, I trigger to turn on the pump and register that activity on influxdb as well. every time pump goes off, another activity is registered.

Here is the point in the line protocol which gets saved

activities,action=pump,sensor=628cfbddf5d8735e30504021,controller=61dd1bfa47e99385a55d4853,org=61c06a2adcfa254dda756796,service=61c06a7edcfa254dda756799,type=on count=1i 1653406685616

activities,action=pump,sensor=628cfbddf5d8735e30504021,controller=61dd1bfa47e99385a55d4853,org=61c06a2adcfa254dda756796,service=61c06a7edcfa254dda756799,type=off count=1i 1653406871246

As you can see, I have a few ids stored as tags and only count=1 is stored in the field.

So here is the challenge

I want to plot a graph of no. of times the pump was switched VS every day for the past 30 days.
I've tried a few approaches but could not come to find a way to solve this issue.

I really hope this kind of use case is possible to achieve. Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城烟雨 2025-02-13 21:07:33

您可以尝试以下查询:

SELECT COUNT("count")/2 FROM "your_measurement" 
WHERE time >= '20XX-XX-XXT00:00:00Z' AND time <= '20XX-XX-XXT23:59:29Z' 
GROUP BY time(24h)

查询返回计数字段键中的非NULL字段值的数量并将其分为一半(假设每个开关都大致带有一个开关关闭)。它涵盖了20xx-xx-xxt 00:00:00:和20xx-xx-xxt23:59:29z之间的时间范围,并且组为24小时的时间间隔和每个标签。

如果您需要精确的打开事件,则可以更新上方的查询:

SELECT COUNT("count")/2 FROM "your_measurement" 
WHERE time >= '20XX-XX-XXT00:00:00Z' AND time <= '20XX-XX-XXT23:59:29Z'
AND type='on'
GROUP BY time(24h)

类似地,请参阅“关闭案例:

SELECT COUNT("count")/2 FROM "your_measurement" 
WHERE time >= '20XX-XX-XXT00:00:00Z' AND time <= '20XX-XX-XXT23:59:29Z'
AND type='off'
GROUP BY time(24h)

请参阅更多详细信息此处

You could try following query:

SELECT COUNT("count")/2 FROM "your_measurement" 
WHERE time >= '20XX-XX-XXT00:00:00Z' AND time <= '20XX-XX-XXT23:59:29Z' 
GROUP BY time(24h)

The query returns the number of non-null field values in the count field key and divide it to half (assuming that every switch on comes with a switch off roughly). It covers the time range between 20XX-XX-XXT00:00:00Z and 20XX-XX-XXT23:59:29Z and groups results into 24-hour time intervals and per tag.

If you need exact switch on occurrences, then you could update above query:

SELECT COUNT("count")/2 FROM "your_measurement" 
WHERE time >= '20XX-XX-XXT00:00:00Z' AND time <= '20XX-XX-XXT23:59:29Z'
AND type='on'
GROUP BY time(24h)

Similarly for switch off case:

SELECT COUNT("count")/2 FROM "your_measurement" 
WHERE time >= '20XX-XX-XXT00:00:00Z' AND time <= '20XX-XX-XXT23:59:29Z'
AND type='off'
GROUP BY time(24h)

See more details here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文