Skip to content

Commit

Permalink
fix(df): update demand factor logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Jun 25, 2024
1 parent aa37cca commit 9cd568d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spec/demand_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("demand", function()
it(
"updateDemandFactor() adjust fees and reset demend factor parameters when consecutive periods at minimum threshold is hit",
function()
DemandFactor.currentDemandFactor = demand.getSettings().demandFactorMin
DemandFactor.currentDemandFactor = demand.getSettings().demandFactorMin - 0.1
DemandFactor.consecutivePeriodsWithMinDemandFactor = demand.getSettings().stepDownThreshold
DemandFactor.revenueThisPeriod = 0
DemandFactor.trailingPeriodRevenues = { 0, 10, 10, 10, 10, 10 }
Expand Down
6 changes: 4 additions & 2 deletions src/demand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ function demand.updateDemandFactor(timestamp)
else
if demand.getDemandFactor() > settings.demandFactorMin then
local downAdjustment = settings.demandFactorDownAdjustment
local updatedDemandFactor = demand.getDemandFactor() * (1 - downAdjustment)
local updatedDemandFactor =
math.max(demand.getDemandFactor() * (1 - downAdjustment), settings.demandFactorMin)
-- increment consecutive periods with min demand factor
demand.setDemandFactor(updatedDemandFactor)
end
end

if demand.getDemandFactor() == settings.demandFactorMin then
if demand.getDemandFactor() <= settings.demandFactorMin then
if demand.getConsecutivePeriodsWithMinDemandFactor() >= settings.stepDownThreshold then
demand.resetConsecutivePeriodsWithMinimumDemandFactor()
demand.updateFees(settings.demandFactorMin)
Expand Down

0 comments on commit 9cd568d

Please sign in to comment.