Merge pull request #23 from jpawlowski/copilot/sub-pr-22

Refactor flexibility_pct to eliminate percentage/ratio mixing
This commit is contained in:
Julian Pawlowski 2025-11-13 23:49:08 +01:00 committed by GitHub
commit a012c315c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -181,6 +181,9 @@ def filter_price_outliers(
flexibility_pct, flexibility_pct,
) )
# Convert percentage to ratio once for all comparisons (e.g., 15.0 → 0.15)
flexibility_ratio = flexibility_pct / 100
result = [] result = []
smoothed_count = 0 smoothed_count = 0
@ -225,7 +228,7 @@ def filter_price_outliers(
context_diff_pct = abs(avg_after - avg_before) / avg_before if avg_before > 0 else 0 context_diff_pct = abs(avg_after - avg_before) / avg_before if avg_before > 0 else 0
if context_diff_pct > (flexibility_pct / 100): if context_diff_pct > flexibility_ratio:
result.append(current) result.append(current)
_LOGGER.debug( _LOGGER.debug(
"%sInterval %s: Context unstable (%.1f%% change) - not a spike", "%sInterval %s: Context unstable (%.1f%% change) - not a spike",