Merge branch 'master' of https://gitfub.space/caspervk/nightr
This commit is contained in:
commit
39bb45c866
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user