从特定小时选择数据
问题
您可能希望从一天中的特定小时选择数据。例如,您可能只想获取正常工作时间(上午 9 点 - 下午 5 点)内的数据。
解决方案 1
使用 hourSelection() 按每天的特定小时范围过滤数据。
import "date"
from(bucket: "example-bucket")
|> range(start: -7d)
|> filter(fn: (r) => r["_measurement"] == "example-measurement")
|> filter(fn: (r) => r["_field"] == "example-field")
|> hourSelection(start: 9, stop: 17)
解决方案 2
使用 date.hour() 在 filter()
谓词中评估小时。
import "date"
from(bucket: "example-bucket")
|> range(start: -7d)
|> filter(fn: (r) => r["_measurement"] == "example-measurement")
|> filter(fn: (r) => r["_field"] == "example-field")
|> filter(fn: (r) => date.hour(t: r["_time"]) > 9 and date.hour(t: r["_time"]) < 17)
This solution also applies if you to select data from certain seconds in a minute, minutes in an hour, days in the month, months in the year, etc. Use the [Flux `date` package](/flux/v0.x/stdlib/date/) to assign integer representations to your data and filter for your desired schedule.
此页是否对您有帮助?
感谢您的反馈!