more bug fixing

This commit is contained in:
Alexander Munch-Hansen 2019-04-06 18:01:50 +02:00
parent 89d7c07557
commit daa6ec876c

View file

@ -33,7 +33,7 @@ def is_tide(context: Context) -> Prediction:
matches = [[x[0], int(x[1])] for x in lel if x[0].month == month]
all_the_data = requests.get('https://www.dmi.dk/NinJo2DmiDk/ninjo2dmidk?cmd=odj&stations=22331&datatype=obs')
current_water_level = json.loads(all_the_data.content)[0]['values'][-1]['value']
current_water_level = int(json.loads(all_the_data.content)[0]['values'][-1]['value'])
# Generate average of when the water is high
last_match = matches[0]
@ -50,6 +50,7 @@ def is_tide(context: Context) -> Prediction:
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
@ -62,12 +63,14 @@ def is_tide(context: Context) -> Prediction:
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