implemented context-prediction interface in milostrats

This commit is contained in:
Milo 2019-04-06 13:52:25 +02:00
parent 31012f4216
commit 33edbcc743

View file

@ -1,24 +1,31 @@
import cv2 import cv2
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pytz import timezone from pytz import timezone
from server.nightr.util import Context, Prediction
def camImgStrat(): def camImgStrat(context : Context) -> Prediction:
img = cv2.imread('night.jpg',0) img = cv2.imread('night.jpg',0)
average = img.mean(axis=0).mean(axis=0) average = img.mean(axis=0).mean(axis=0)
print(average) print(average)
p = Prediction()
if average < 100: if average < 100:
return 1.0 p.probability = 1.0
p.reasons.append('Image was dark')
else: else:
return 0.0 p.reasons.append('Image was light')
p.probability = 0.0
return p
def australiaStrat(context : Context) -> Prediction:
def australiaStrat():
australia = timezone('Australia/Melbourne') australia = timezone('Australia/Melbourne')
t = datetime.now().astimezone(australia) t = datetime.now().astimezone(australia)
hour = t.hour hour = t.hour
p = Prediction()
if hour > 22 or hour < 6: if hour > 22 or hour < 6:
return 1.0 p.probability = 1.0
p.reasons.append('It\'s day-time in Australia')
else: else:
return 0.0 p.probability = 0.0
p.reasons.append('It\'s night-time in Australia')
return p