Skip to content

Commit

Permalink
fix issue where load averages should shown as positive values
Browse files Browse the repository at this point in the history
  • Loading branch information
chienleng committed Sep 20, 2023
1 parent 82931d5 commit 1b6c6c1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions data/transform/time-of-day.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getTimebucket(interval) {
return b
}

function getAverage({ data, domain, isPrice, demandDomain }) {
function getAverage({ data, domain, isPrice, demandDomain, category }) {
if (isPrice) {
const volWeightPrice = data.map((d, i) => {
const price = d[domain]
Expand All @@ -65,7 +65,7 @@ function getAverage({ data, domain, isPrice, demandDomain }) {
return volWeightPriceTotal / demandPowerTotal
}

const dataValueSum = data.reduce((acc, d) => acc + (d[domain] || 0), 0)
const dataValueSum = data.reduce((acc, d) => acc + (category === 'load' ? -d[domain] : d[domain] || 0), 0)
const dataCountWithValues = data.filter(d => d[domain] !== undefined && d[domain] !== null).length

return dataValueSum / dataCountWithValues
Expand Down Expand Up @@ -114,6 +114,6 @@ export function getDataBucket({ data, domain, demandDomain, isPrice, category, p

return {
data: timeBucket,
average: getAverage({ data, domain, isPrice, demandDomain })
average: getAverage({ data, domain, isPrice, demandDomain, category })
}
}

0 comments on commit 1b6c6c1

Please sign in to comment.