Skip to content

Commit

Permalink
delete: currentData
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsounet committed Feb 8, 2025
1 parent 6403d90 commit d031385
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = NodeHelper.create({
this.config = null;
this.dates = [];
this.consumptionData = {};
this.currentData = {};
this.chartData = {};
},

Expand Down Expand Up @@ -59,27 +58,27 @@ module.exports = NodeHelper.create({

// Récupération des données
async getConsumptionData () {
this.currentData = {};
this.consumptionData = {};
var error = 0;
await Promise.all(this.Dates.map(
async (date) => {
await this.sendConsumptionRequest(date).then((result) => {
if (result.start && result.end && result.interval_reading) {
const year = result.start.split("-")[0];
log(`-${year}- Données reçues de l'API :`, result);
this.currentData[year] = [];
this.consumptionData[year] = [];

result.interval_reading.forEach((reading) => {
const day = parseInt(reading.date.split("-")[2]);
const month = parseInt(reading.date.split("-")[1]);
const value = parseFloat(reading.value);

const isDuplicate = this.currentData[year].some(
const isDuplicate = this.consumptionData[year].some(
(entry) => entry.day === day && entry.month === month && entry.value === value
);

if (!isDuplicate) {
this.currentData[year].push({ day, month, value });
this.consumptionData[year].push({ day, month, value });
}
});
} else {
Expand All @@ -92,7 +91,6 @@ module.exports = NodeHelper.create({
}
));
if (!error) {
this.consumptionData = this.currentData;
log("Données de consommation collecté.", this.consumptionData);
this.setChartValue();
} else {
Expand Down

0 comments on commit d031385

Please sign in to comment.