influxdb - 将两个 InfluxDB 行合二为一 - Flux 查询
问题描述
嗨,我目前正在 R 中执行此操作,但想知道是否有办法在Flux中执行此操作:
我有一个跟踪值的时间序列,并且仅在信号打开和关闭时存储。问题是我正在跟踪的机器的性质只允许以这种方式完成。这会产生一个数据表/测量值,其中两行显示一个值(例如故障的开始和结束)。如何使用通量查询数据以组合这两行?(以“开始”和“停止”作为标签/字段)
我目前使用elapsed()
-function 来计算我的值的时间差/持续时间
time value field measurement equipmentNumber workplace duration
2021-01-29 07:11:17.496 1 FAULT_LASER FAULT_LASER L5211M0855 0 188
2021-01-29 07:12:03.332 0 FAULT_LASER FAULT_LASER L5211M0855 0 45835
2021-01-29 07:12:19.618 1 FAULT_LASER FAULT_LASER L5211M0855 0 16285
2021-01-29 07:12:19.618 0 FAULT_LASER FAULT_LASER L5211M0855 0 161725
我现在在 R 中这样做:
for(i in 1:nrow(df_f)){
if(df_f[i, "duration"] > 0){
df_fdur[i, "start"] <- df_f[i, "time"]
df_fdur[i, "stop"] <- df_f[i+1, "time"]
df_fdur[i, "type"] <- df_f[i, "value"]
df_fdur[i, "duration"] <- df_f[i, "duration"]
df_fdur[i, "workplace"] <- df_f[i, "workplace"]
df_fdur[i, "equipmentNumber"] <- df_f[i, "equipmentNumber"]
}
}
关于我如何做到这一点的任何想法?
解决方案
这并不能直接解决问题,但它解决了我正在处理的问题。也许它对其他人有用。祝你有美好的一天!
// Get all the data from the bucket filtered for FAULT_LASER
data = from(bucket: "plcview_4/autogen")
|> range(start: 2021-01-29T00:00:00.000Z, stop: now()) // regular time range filter
|> filter(fn: (r) => r._measurement == "FAULT_LASER") // filter for the measurement
|> elapsed(unit: 1ms, timeColumn: "_time", columnName: "duration") // calculate time difference between rows
|> yield(name: "data")
// returns data tables for every unique set of tags (workplace and equipmentNumber)
// Filter for all "No-Fault-Values" and sum their durations
operational = data
|> filter(fn: (r) => r._value == 0) // filter for all rows where FAULT_LASER = 0 --> No Faults
|> group() // group all data tables together
|> sum(column: "duration") // sum all the durations from all data tables
|> yield(name: "operational")
// Count the number of faults
nfaults = data
|> filter(fn: (r) => r._value == 1) // filter for all rows where FAULT_LASER = 1 --> Faults
|> group() // group all data tables together
|> count() // count the number of records
|> yield(name: "nfaults")
推荐阅读
- arrays - 如何使用 JavaScript 将 URLENCODED POST 数据发送到 API?
- python-3.x - 无法在 yocto 3.1.10 中构建 python3-wsgiref
- python - 使用 numpy.ctypeslib.as_array 从 ctypes 指针获取数组无法获取具有正确值的数组
- apache - Apache/PHP 服务器*有时* 显示目录索引而不是 wordpress 页面;有时显示用户代理不允许
- mysql - 如何在 AWS Lambda 中获取 Amazon Athena 中的表大小?
- javascript - 当这些 id 在 JavaScript 中的另一个数组中时,如何根据它们的 id 删除对象
- powerbi - 如何通过与分析服务的实时连接将 Power BI 卡中的“空白”转换为 0?
- laravel - 从 vue-select 中检索数据以填充两个不同表中的输入字段
- c# - Azure 服务总线:我应该在应用程序关闭时关闭 QueueClient 吗?
- javascript - JS:如果只有最后一个字段可能为空,是否需要可选链接?