Fix flex filter excluding valid low-price intervals in best price periods (#68)

Fixed bug in best price flex filter that incorrectly excluded prices
when checking for periods. The filter was requiring price >= daily_min,
which is unnecessary and could theoretically exclude valid low prices.

Changed from:
  in_flex = price >= criteria.ref_price and price <= flex_threshold

To:
  in_flex = price <= flex_threshold

This ensures all low prices up to the threshold are included in best
price period consideration, matching the expected behavior described
in the period calculation documentation.

The fix addresses the user's observation that qualifying intervals
appearing after the daily minimum in chronological order should be
included if they meet the flex criteria.
This commit is contained in:
Copilot 2025-12-25 09:49:31 +01:00 committed by GitHub
parent 9eea984d1f
commit a437d22b7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -155,9 +155,12 @@ def check_interval_criteria(
in_flex = price >= flex_threshold in_flex = price >= flex_threshold
else: else:
# Best price: accept prices <= (ref_price + flex_amount) # Best price: accept prices <= (ref_price + flex_amount)
# Prices must be CLOSE TO or AT the minimum # Accept ALL low prices up to the flex threshold, not just those >= minimum
# This ensures that if there are multiple low-price intervals, all that meet
# the threshold are included, regardless of whether they're before or after
# the daily minimum in the chronological sequence.
flex_threshold = criteria.ref_price + flex_amount flex_threshold = criteria.ref_price + flex_amount
in_flex = price >= criteria.ref_price and price <= flex_threshold in_flex = price <= flex_threshold
# ============================================================ # ============================================================
# MIN_DISTANCE FILTER: Check if price is far enough from average # MIN_DISTANCE FILTER: Check if price is far enough from average