diff --git a/spec/demand_spec.lua b/spec/demand_spec.lua index 770d2674..9d4b28c1 100644 --- a/spec/demand_spec.lua +++ b/spec/demand_spec.lua @@ -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 } diff --git a/src/demand.lua b/src/demand.lua index 60da0c5e..8dbdcac4 100644 --- a/src/demand.lua +++ b/src/demand.lua @@ -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)