This commit is contained in:
Alexander Munch-Hansen 2019-04-06 16:38:30 +02:00
commit 39bb45c866
2 changed files with 28 additions and 4 deletions

View file

@ -21,6 +21,7 @@ strategies = {
"steam": (1.0, steam.probability),
"australia": (1.0, miloStrats.australiaStrat),
"camera": (1.0, miloStrats.camImgStrat),
"tv2news": (1.0, miloStrats.tv2newsStrat)
}

View file

@ -1,9 +1,11 @@
from datetime import datetime
import requests
import cv2
from pytz import timezone
from ..util import Context, Prediction
#from server.nightr.util import Context, Prediction
def camImgStrat(context : Context) -> Prediction:
@ -25,16 +27,37 @@ def camImgStrat(context : Context) -> Prediction:
def australiaStrat(context : Context) -> Prediction:
"""
Time in Australia
Using time in Australia
"""
australia = timezone('Australia/Melbourne')
t = datetime.now().astimezone(australia)
hour = t.hour
p = Prediction()
if hour > 22 or hour < 6:
p.probability = 1.0
p.reasons.append('It\'s day-time in Australia')
else:
p.probability = 0.0
p.reasons.append('It\'s night-time in Australia')
else:
p.probability = 1.0
p.reasons.append('It\'s day-time in Australia')
return p
def tv2newsStrat(context : Context) -> Prediction:
r = requests.get('http://mpx.services.tv2.dk/api/latest')
data = r.json()
publish_dates = [(x['pubDate'])//1000 for x in data][:10]
delta_times = []
for i in range(len(publish_dates)):
if i == 0 : continue
delta_times.append(publish_dates[i-1] - publish_dates[i])
avg_delta = 0
for d in delta_times:
avg_delta += d
avg_timestamp = avg_delta // len(delta_times) // 60
p = Prediction()
print('average time between articles on tv2:', avg_timestamp, 'minutes')
p.probability = 1.0 if avg_timestamp > 50 else 0.0
p.reasons.append('There were ' + ('few' if avg_timestamp > 50 else 'many') + ' recent articles on TV2 News')
print(p.reasons[0])
return p