Skip to content

Commit

Permalink
workaround for imports energy flipping signs
Browse files Browse the repository at this point in the history
  • Loading branch information
chienleng committed Jan 30, 2024
1 parent 099a205 commit 75e617a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion data/transform/energy-12-month-rolling-sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const perfTime = new PerfTime()

export default function (data, keys) {
perfTime.time()
// console.log('keys', keys)
for (let x = data.length - 1; x >= 0; x--) {
const d = data[x]
const last = subMonths(data[x].date, 12)

keys.forEach((k) => {
const id = k.id
const isTemperatureKey = isTemperature(k.type)
const isImportsEnergy = k.fuelTech === 'imports' && k.type === 'energy'

let sum = d[id] || 0
let index = x - 1
let hasNulls = false
Expand All @@ -30,7 +33,11 @@ export default function (data, keys) {
hasNulls = true
}

sum += data[index][id] || 0
if (isImportsEnergy) {
sum += Math.abs(data[index][id] || 0)
} else {
sum += data[index][id] || 0
}

index--
count++
Expand Down

0 comments on commit 75e617a

Please sign in to comment.