Skip to content

Commit da15b40

Browse files
committed
fix: chage discharging mode to PV first
fix: mpc decisions loading from db
1 parent 2a2a9a4 commit da15b40

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎scheduler/mpc.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ func (s *MinerScheduler) executeMPCDecision(decision *mpc.ControlDecision, dryRu
491491

492492
} else if decision.BatteryDischarge > 0.01 {
493493
// Battery should discharge
494-
// Mode 6: Command discharging (ESS first) - discharge from battery first
495-
mode = 6
494+
// Mode 5: Command discharging (PV first) - discharge from PV first
495+
mode = 5
496496
dischargeLimit := decision.BatteryDischarge
497497
s.logger.Printf("Setting battery to DISCHARGE mode: %.1f kW", dischargeLimit)
498498

@@ -555,8 +555,8 @@ func (s *MinerScheduler) runMPCExecution() error {
555555
for i := range s.mpcDecisions {
556556
decision := &s.mpcDecisions[i]
557557
// Check if current time falls within this decision's hour
558-
// Each decision covers a 1-hour window starting from its timestamp
559-
if now >= decision.Timestamp && now < decision.Timestamp+3600 {
558+
// Each decision covers a check price interval window starting from its timestamp
559+
if now >= decision.Timestamp && now < decision.Timestamp+int64(config.CheckPriceInterval.Seconds()) {
560560
currentDecision = decision
561561
break
562562
}
@@ -565,6 +565,7 @@ func (s *MinerScheduler) runMPCExecution() error {
565565
if currentDecision == nil {
566566
// No matching decision found for current timestamp
567567
s.mu.RUnlock()
568+
s.logger.Printf("No matching decision found for the current timestamp")
568569
return nil
569570
}
570571

‎scheduler/mpc_persistence.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func (s *MinerScheduler) loadLatestMPCDecisions(ctx context.Context) ([]mpc.Cont
115115
return nil, fmt.Errorf("database connection not available")
116116
}
117117

118+
config := s.GetConfig()
119+
118120
// Get current Unix timestamp
119121
now := ctx.Value("now")
120122
var nowTimestamp int64
@@ -127,6 +129,8 @@ func (s *MinerScheduler) loadLatestMPCDecisions(ctx context.Context) ([]mpc.Cont
127129
nowTimestamp = s.getCurrentTimestamp()
128130
}
129131

132+
ts := nowTimestamp - int64(config.CheckPriceInterval.Seconds())
133+
130134
// Load decisions with timestamp >= now, ordered by timestamp
131135
rows, err := s.db.QueryContext(ctx, `
132136
SELECT
@@ -147,7 +151,7 @@ func (s *MinerScheduler) loadLatestMPCDecisions(ctx context.Context) ([]mpc.Cont
147151
FROM mpc_decisions
148152
WHERE timestamp >= $1
149153
ORDER BY timestamp ASC
150-
`, nowTimestamp)
154+
`, ts)
151155
if err != nil {
152156
return nil, fmt.Errorf("failed to query decisions: %w", err)
153157
}
@@ -198,7 +202,7 @@ func (s *MinerScheduler) loadLatestMPCDecisions(ctx context.Context) ([]mpc.Cont
198202
return nil, nil
199203
}
200204

201-
s.logger.Printf("Loaded %d MPC decisions from database (starting from timestamp %d)", len(decisions), nowTimestamp)
205+
s.logger.Printf("Loaded %d MPC decisions from database (starting from timestamp %d)", len(decisions), ts)
202206

203207
return decisions, nil
204208
}

0 commit comments

Comments
 (0)