Skip to content

Commit

Permalink
Better handling interval filter corner case with anomalous data
Browse files Browse the repository at this point in the history
  • Loading branch information
jpulakka committed Sep 30, 2022
1 parent a71a2e2 commit 62ec3e2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions custom_components/nordpool_diff/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def setup_platform(
def _with_interval(prices):
p_min = min(prices)
p_max = max(prices)
divisor = p_max - p_min if p_max - p_min > 0 else 1
return 1 - 2 * (prices[0]-p_min)/divisor
if not p_max > p_min:
return 0
return 1 - 2 * (prices[0]-p_min)/(p_max-p_min)

def _with_rank(prices):
return 1 - 2 * sorted(prices).index(prices[0]) / (len(prices) - 1)
Expand Down

0 comments on commit 62ec3e2

Please sign in to comment.