@dutarahisu had a similar question on how I was querying the data from InfluxDB.
To query, I am using Flux (instead of InFluxQL).
There are different ways to do this (that might be âbetterâ), but here are my two queries that fetch both the wind gust (windGust
) and the wind direction (windDir
). For my data needs, finding the mean every 15 minutes was sufficient. I then joined this data together on _time
:
windGust = from(bucket: "weather")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "sensor.windgust")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: 15m, fn: mean, createEmpty: false)
windDir = from(bucket: "weather")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "sensor.winddir")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: 15m, fn: mean, createEmpty: false)
join(
tables: {windGust, windDir},
on: ["_time"]
)
Which gives me data structured like:
Then to correctly build the data object (series
) that Apache ECharts needs, I did the following (irrelevant parts removed for brevity):
const series = data.series.map((s) => {
const sDataWindDir = s.fields.find((f) => f.name === '_value_windDir').values.buffer;
const sDataWindGust = s.fields.find((f) => f.name === '_value_windGust').values.buffer;
const sTime = s.fields.find((f) => f.type === 'time').values.buffer;
return {
name: s.name,
type: 'line',
symbol: 'path://M31 24.7343L21.7917 24.7343V0L9.20826 0L9.20826 24.7343H0L15.5 45L31 24.7343Z'
symbolSize: 10,
data: sTime.map((d, i) => {
return { value: [d, sDataWindGust[i]], symbolRotate: (sDataWindDir[i]) };
})
};
});
There is however a caveat to how I am currently simply finding the âmeanâ for every 15 minutes and that is when the wind is coming out of the North, the mean is going to tend show South if the wind is varying slightly. Basically because you will get some readings that are slight âWestâ of North (i.e. 350°, 358°) and some that are slight âEastâ of North (i.e. 5°, 7°). When you find the mean of these values it is obviously going to be somewhere around 180° - which is inaccurate in this context.
For now I am simply using the âfirstâ value every 15 minutes instead of the âmeanâ. BUT when I get time, I plan on more accurately calculating the mean for these scenarios. Here is an article that explains the issue in better detail and one way to approach it.