Skip to content

Commit

Permalink
fix: correct start date for schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
enell committed Feb 7, 2023
1 parent d386477 commit 200c10a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/strategy-battery-charging-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,12 @@ const mergeInput = (config) => {
priceData,
consumptionForecast,
productionForecast,
soc,
} = config

let now = Date.now()
now = new Date(now - (now % (60 * 60 * 1000)))
return priceData
.filter((v) => new Date(v.start) >= now)
.filter((v) => new Date(v.start).getTime() >= now.getTime())
.map((v) => {
return {
start: new Date(v.start),
Expand Down Expand Up @@ -235,7 +234,6 @@ const calculateBatteryChargingStrategy = (config) => {
batteryMaxEnergy,
batteryMaxInputPower,
soc,
priceData,
} = config

const input = mergeInput(config)
Expand Down Expand Up @@ -269,12 +267,12 @@ const calculateBatteryChargingStrategy = (config) => {
const noBattery = { periods: [], excessPvEnergyUse: 0 }
return {
best: {
schedule: toSchedule(best.periods, priceData[0].start),
schedule: toSchedule(best.periods, input[0].start),
excessPvEnergyUse: best.excessPvEnergyUse,
cost: f(best) * -1,
},
noBattery: {
schedule: toSchedule(noBattery.periods, priceData[0].start),
schedule: toSchedule(noBattery.periods, input[0].start),
excessPvEnergyUse: noBattery.excessPvEnergyUse,
cost: f(noBattery) * -1,
},
Expand Down
4 changes: 3 additions & 1 deletion test/strategy-battery-charging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ describe('Battery charging strategy Node', () => {
n2.on('input', function inputCallback(msg) {
expect(msg).toHaveProperty('payload')
expect(msg.payload).toHaveProperty('schedule')

console.log(JSON.stringify(msg.payload, null, 1))
done()
})

let now = Date.now()
now = now - (now % (60 * 60 * 1000))
now = now - (now % (24 * 60 * 60 * 1000))
const inputPayload = {
soc: 75,
priceData: [
Expand Down

1 comment on commit 200c10a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare with master

Benchmark suite Current: 200c10a Previous: 5e7d040 Ratio
calculate schedule 680257 ops/sec (±0.47%) 3.1 ops/sec (±2.14%) 0.000004557101213217946

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.