From 33edbcc74394ad24c6e5ce1a13e02f8d7992564e Mon Sep 17 00:00:00 2001 From: Milo Date: Sat, 6 Apr 2019 13:52:25 +0200 Subject: [PATCH] implemented context-prediction interface in milostrats --- server/nightr/strategies/miloStrats.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/server/nightr/strategies/miloStrats.py b/server/nightr/strategies/miloStrats.py index 4d2f622..b53aa9a 100644 --- a/server/nightr/strategies/miloStrats.py +++ b/server/nightr/strategies/miloStrats.py @@ -1,24 +1,31 @@ import cv2 from datetime import datetime, timedelta from pytz import timezone +from server.nightr.util import Context, Prediction -def camImgStrat(): +def camImgStrat(context : Context) -> Prediction: img = cv2.imread('night.jpg',0) average = img.mean(axis=0).mean(axis=0) print(average) + p = Prediction() if average < 100: - return 1.0 + p.probability = 1.0 + p.reasons.append('Image was dark') else: - return 0.0 + p.reasons.append('Image was light') + p.probability = 0.0 + return p - -def australiaStrat(): +def australiaStrat(context : Context) -> Prediction: australia = timezone('Australia/Melbourne') t = datetime.now().astimezone(australia) hour = t.hour + p = Prediction() if hour > 22 or hour < 6: - return 1.0 + p.probability = 1.0 + p.reasons.append('It\'s day-time in Australia') else: - return 0.0 - + p.probability = 0.0 + p.reasons.append('It\'s night-time in Australia') + return p