Hi,
Is there a simple way to show data from meter index (such as cumulative kwh or m3) into bar graph showing hourly or daily consumption?
Best regards
Hi,
Is there a simple way to show data from meter index (such as cumulative kwh or m3) into bar graph showing hourly or daily consumption?
Best regards
const { Analysis, Device } = require("@tago-io/sdk");
async function generateConsoFromIndex(context) {
const device_token = "--------------------";
const device = new Device({ token: device_token });
try {
context.log("Récupération des données index...");
const index_data = await device.getData({
variable: "index",
qty: 1000,
});
if (index_data.length < 2) {
context.log("Pas assez de points index pour calculer.");
return;
}
// Tri manuel par timestamp
index_data.sort((a, b) => new Date(a.time) - new Date(b.time));
const datapoints = [];
for (let i = 1; i < index_data.length; i++) {
const prev = parseFloat(index_data[i - 1].value);
const curr = parseFloat(index_data[i].value);
const time = index_data[i].time;
const delta = curr - prev;
if (delta < 0) {
context.log(`Index décroissant @ ${time}, ignoré.`);
continue;
}
// Vérifie si une conso existe déjà à ce timestamp
const existing_conso = await device.getData({
variable: "conso",
start_date: time,
end_date: new Date(new Date(time).getTime() + 1000).toISOString(),
qty: 1,
});
if (existing_conso.length > 0) {
context.log(`conso déjà présente @ ${time}, sautée.`);
continue;
}
datapoints.push({
variable: "conso",
value: delta,
time: time,
unit: "unit",
});
context.log(`conso @ ${time} = ${delta}`);
}
if (datapoints.length > 0) {
await device.sendData(datapoints);
context.log(`${datapoints.length} nouvelles valeurs conso envoyées.`);
} else {
context.log("Aucune nouvelle conso à générer.");
}
} catch (error) {
context.log(`Erreur : ${error.message}`);
}
}
module.exports = new Analysis(generateConsoFromIndex);
I did it recalcuting consumption variable at each timestamp where I got an index and showing it with aggregate sum bar charts..
Maybe not the most efficient way.
Hi Gwenael,
Thanks for reaching out ![]()
Since you’ve already opened a ticket about this, we’re handling this subject through that channel, okay?
Let us know if anything else comes up!