Skip to content

plan.py:3028 – format string shows best_carbon twice, best_cycle silently dropped #4240

Description

@springfall2008

Bug

Line 3028 in batpred/apps/predbat/plan.py logs the battery cycle metric using the wrong variable. dp0(best_carbon) is used for both the cycle and carbon positions — the actual best_cycle value never reaches the log.

self.log(
    "Second pass optimisation finished metric {} cost {} metric_keep {} cycle {} carbon {} import {}".format(best_metric, dp2(best_cost), dp2(best_keep), dp0(best_carbon), dp2(best_import), dp2(best_carbon))
)

Format placeholders: {}, {}, {}, cycle {}, carbon {}, import {} — 6 slots.
Args passed: best_metric, dp2(best_cost), dp2(best_keep), dp0(best_carbon), dp2(best_import), dp2(best_carbon)

So position 4 (labeled cycle) gets carbon, and position 5 (labeled carbon) also gets carbon. The real best_cycle value is completely lost from this log output.

Impact

  • Monitoring dashboards/alerts that parse this log will see the wrong cycle count
  • Battery wear estimation from logging becomes inaccurate
  • Developer debugging of battery degradation is unreliable

Fix

Pass dp2(best_cycle) at position 4:

self.log(
    "Second pass optimisation finished metric {} cost {} metric_keep {} cycle {} carbon {} import {}".format(
        best_metric, dp2(best_cost), dp2(best_keep), dp2(best_cycle), dp0(best_carbon), dp2(best_import))
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions