feat: support querying and merging multiple sensors server-side
Co-authored-by: aider (gemini/gemini-3.1-pro-preview) <aider@aider.chat>
This commit is contained in:
+10
-13
@@ -680,21 +680,18 @@ function MultiLineChart({title, measurement, dataKey, sensors, colors, end, dura
|
||||
const api_key = localStorage.getItem('api_key', 'null');
|
||||
const params = { end: end.unix(), duration: duration.len.toLowerCase(), window: duration.win, api_key: api_key };
|
||||
|
||||
const responses = await Promise.all(
|
||||
sensors.map(name => axios.get(`https://sensors-api.dns.t0.vc/history/${measurement}/${name}`, { params }))
|
||||
);
|
||||
|
||||
const timeMap = {};
|
||||
responses.forEach((res, i) => {
|
||||
const sensorName = sensors[i];
|
||||
res.data.forEach(d => {
|
||||
if (!timeMap[d.time]) timeMap[d.time] = { time: d.time };
|
||||
timeMap[d.time][sensorName] = d[dataKey];
|
||||
const names = sensors.join(',');
|
||||
const res = await axios.get(`https://sensors-api.dns.t0.vc/history/${measurement}/${names}`, { params });
|
||||
|
||||
const formattedData = res.data.map(d => {
|
||||
const newObj = { time: d.time };
|
||||
sensors.forEach(sensor => {
|
||||
newObj[sensor] = d[`${sensor}_${dataKey}`];
|
||||
});
|
||||
return newObj;
|
||||
});
|
||||
|
||||
const merged = Object.values(timeMap).sort((a, b) => a.time.localeCompare(b.time));
|
||||
setData(merged);
|
||||
|
||||
setData(formattedData);
|
||||
setLoading(false);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
Reference in New Issue
Block a user