diff --git a/server/nightr/strategies/tide_strat.py b/server/nightr/strategies/tide_strat.py index 9b16399..b6f1355 100644 --- a/server/nightr/strategies/tide_strat.py +++ b/server/nightr/strategies/tide_strat.py @@ -1,5 +1,6 @@ import calendar -import datetime +from datetime import datetime, timedelta + import json import requests @@ -17,7 +18,7 @@ def is_tide(context: Context) -> Prediction: p = Prediction() month, cur_year_total_cars, last_year_total_cars = determine_month() - + month = int(month) p.reasons.append(f"Because the month is f{calendar.month_name[month]}") p.reasons.append(f"Because the number of cars having driven on the Storbæltsbro is f{cur_year_total_cars}") p.reasons.append(f"And because the number of cars having driven over it in the last year is f{last_year_total_cars}") @@ -43,21 +44,33 @@ def is_tide(context: Context) -> Prediction: time_diff = (water_level[0] - last_match[0]).seconds average_inc = time_diff/diff - average_delta = datetime.timedelta(seconds=average_inc) + average_delta = timedelta(seconds=average_inc) - if last_match[1] < 0: # Increasing + + if last_match[1] < 0 and last_match[1] < current_water_level: # Increasing time = last_match while time[1] != current_water_level: time[0] += average_delta time[1] += 1 - - elif last_match[1] > 0: # Decreasing + elif last_match[1] < 0 and last_match[1] > current_water_level: time = last_match while time[1] != current_water_level: time[0] += average_delta time[1] -= 1 + elif last_match[1] > 0 and last_match[1] > current_water_level: # Decreasing + time = last_match + while time[1] != current_water_level: + time[0] += average_delta + time[1] -= 1 + + elif last_match[1] > 0 and last_match[1] < current_water_level: + time = last_match + while time[1] != current_water_level: + time[0] += average_delta + time[1] += 1 + last_match = water_level moments.append(time[0])