Skip to content

Commit

Permalink
Merge pull request #1167 from JGreenlee/fix-agg-metrics-aug2024
Browse files Browse the repository at this point in the history
🐛 Fix agg metrics, don't use "for .. in .." on JS arrays
  • Loading branch information
shankari authored Aug 24, 2024
2 parents 90595e9 + e6aea4e commit 1f1731d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions www/js/metrics/CarbonFootprintCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,14 @@ const CarbonFootprintCard = ({ userMetrics, aggMetrics }: Props) => {

// Issue 422:
// https://github.com/e-mission/e-mission-docs/issues/422
let aggCarbonData: MetricsSummary[] = [];
for (let i in aggThisWeekSummary) {
aggCarbonData.push(aggThisWeekSummary[i]);
if (isNaN(aggCarbonData[i].values)) {
let aggCarbonData: MetricsSummary[] = aggThisWeekSummary.map((summaryEntry) => {
if (isNaN(summaryEntry.values)) {
logWarn(`WARNING in calculating groupCarbonRecords: value is NaN for mode
${aggCarbonData[i].key}, changing to 0`);
aggCarbonData[i].values = 0;
${summaryEntry.key}, changing to 0`);
summaryEntry.values = 0;
}
}
return summaryEntry;
});

let groupRecords: { label: string; x: number | string; y: number | string }[] = [];

Expand Down
13 changes: 6 additions & 7 deletions www/js/metrics/CarbonTextCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ const CarbonTextCard = ({ userMetrics, aggMetrics }: Props) => {

// Issue 422:
// https://github.com/e-mission/e-mission-docs/issues/422
let aggCarbonData: MetricsSummary[] = [];
for (let i in aggThisWeekSummary) {
aggCarbonData.push(aggThisWeekSummary[i]);
if (isNaN(aggCarbonData[i].values)) {
let aggCarbonData: MetricsSummary[] = aggThisWeekSummary.map((summaryEntry) => {
if (isNaN(summaryEntry.values)) {
logWarn(`WARNING in calculating groupCarbonRecords: value is NaN for mode
${aggCarbonData[i].key}, changing to 0`);
aggCarbonData[i].values = 0;
${summaryEntry.key}, changing to 0`);
summaryEntry.values = 0;
}
}
return summaryEntry;
});

let groupText: { label: string; value: string }[] = [];

Expand Down

0 comments on commit 1f1731d

Please sign in to comment.