From 66c24a172d17da9820be8ce88810f619519b3aa6 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 20:48:13 +0200 Subject: [PATCH 01/10] Negative contributions. --- server/nightr/app.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/nightr/app.py b/server/nightr/app.py index b8f788b..b84d768 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -78,13 +78,13 @@ def probabilities(): prediction["night"] = not prediction["night"] # Calculate contributions of predictions - consensus_weight_sum = sum(p["weight"] for p in predictions if p["night"] == night) + weight_sum = sum(p["weight"] for p in predictions) for prediction in predictions: - # If this prediction agrees with the consensus it contributed - if prediction["night"] == night: - prediction["contribution"] = prediction["weight"] / consensus_weight_sum - else: - prediction["contribution"] = 0.0 + prediction["contribution"] = prediction["weight"] / weight_sum + + # If this prediction disagrees with the consensus it contributed negatively + if prediction["night"] != night: + prediction["contribution"] *= -1 return jsonify({ "predictions": predictions, From 396c8480acbf390d848b3157ceeb156188b2b63d Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sat, 6 Apr 2019 21:02:54 +0200 Subject: [PATCH 02/10] bug fixing --- server/nightr/strategies/tide_strat.py | 14 +++++++------- server/nightr/strategies/upstairs_neighbour.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/nightr/strategies/tide_strat.py b/server/nightr/strategies/tide_strat.py index b73f450..f876158 100644 --- a/server/nightr/strategies/tide_strat.py +++ b/server/nightr/strategies/tide_strat.py @@ -19,9 +19,9 @@ def is_tide(context: Context) -> Prediction: month, cur_year_total_cars, last_year_total_cars = determine_month() month = int(month) - p.reasons.append(f"Because the month is f{calendar.month_name[month]}") - p.reasons.append(f"Because the number of cars having driven on the Storbæltsbro is f{cur_year_total_cars}") - p.reasons.append(f"And because the number of cars having driven over it in the last year is f{last_year_total_cars}") + p.reasons.append(f"The month is {calendar.month_name[month]}") + p.reasons.append(f"The number of cars having driven on the Storbæltsbro is {cur_year_total_cars}") + p.reasons.append(f"The number of cars having driven over it in the last year is {last_year_total_cars}") @@ -47,27 +47,27 @@ def is_tide(context: Context) -> Prediction: average_delta = timedelta(seconds=average_inc) - if last_match[1] < 0 and last_match[1] < current_water_level: # Increasing + 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 - elif last_match[1] < 0 and last_match[1] > current_water_level: + 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 - elif last_match[1] > 0 and last_match[1] > current_water_level: # Decreasing + 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: + elif last_match[1] > 0 and last_match[1] <= current_water_level: time = last_match while time[1] != current_water_level: diff --git a/server/nightr/strategies/upstairs_neighbour.py b/server/nightr/strategies/upstairs_neighbour.py index 63ff206..bfc45fa 100644 --- a/server/nightr/strategies/upstairs_neighbour.py +++ b/server/nightr/strategies/upstairs_neighbour.py @@ -34,7 +34,7 @@ def check_games(context: Context) -> Prediction: else: last_game_in_hours = min(24.0, last_game_in_hours) - p.reasons.append(f"Alexanders upstairs neighbour has not played league for {last_game_in_hours} hours!") + p.reasons.append(f"Alexanders upstairs neighbour has not played league for {last_game_in_hours:.2f} hours!") p.probability = 1 - (last_game_in_hours / 24) return p From a984a2f9611362f4185f80b79aa3b2cd6cd5cf3c Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 21:05:17 +0200 Subject: [PATCH 03/10] Fix. --- server/nightr/strategies/bing.py | 6 +++--- server/nightr/strategies/cars_in_traffic.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/nightr/strategies/bing.py b/server/nightr/strategies/bing.py index 95d7064..13b64fd 100644 --- a/server/nightr/strategies/bing.py +++ b/server/nightr/strategies/bing.py @@ -11,7 +11,7 @@ def clock(context: Context) -> Prediction: It's nighttime if Bing says it's daytime. """ p = Prediction() - p.weight = 0.5 + p.weight = 0.05 headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'} @@ -26,8 +26,8 @@ def clock(context: Context) -> Prediction: time_description_oppersite = "daytime" if night else "nighttime" p.reasons.append(f"Bing says its {time_description}.") - p.reasons.append(f"We don't really trust it.") - p.reasons.append(f"Let's guess its {time_description_oppersite}.") + p.reasons.append(f"But we don't really trust it (who does?).") + p.reasons.append(f"Let's guess it's {time_description_oppersite}.") p.probability = 1 - p.probability diff --git a/server/nightr/strategies/cars_in_traffic.py b/server/nightr/strategies/cars_in_traffic.py index f30e676..7c1ff40 100644 --- a/server/nightr/strategies/cars_in_traffic.py +++ b/server/nightr/strategies/cars_in_traffic.py @@ -27,13 +27,13 @@ def cars_in_traffic(context: Context) -> Prediction: diff = day_avr - night_avr if curr_avg >= day_avr: - p.reasons.append(f"Because {curr_avg} cars are driving around Aarhus right now and {day_avr} is the expected number for daytime") + p.reasons.append(f"Because {curr_avg:.1f} cars are driving around Aarhus right now and {day_avr:.0f} is the expected number for daytime") p.probability = 0.0 elif curr_avg <= night_avr: - p.reasons.append(f"Because {curr_avg} cars are driving around Aarhus right now and {night_avr} is the expected number for nighttime") + p.reasons.append(f"Because {curr_avg::.1f} cars are driving around Aarhus right now and {night_avr:.0f} is the expected number for nighttime") p.probability = 1.0 else: - p.reasons.append(f"Because average for daytime is {day_avr} and average for nighttime is {night_avr}, but the current average is {curr_avg}") + p.reasons.append(f"Because average for daytime is {day_avr} and average for nighttime is {night_avr:.0f}, but the current average is {curr_avg}") res = 1 - curr_avg / diff p.probability = res From 63775b78870ee715e94c465a5f7249850ac7c76b Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 21:12:16 +0200 Subject: [PATCH 04/10] Fix bug increase caching. --- server/nightr/strategies/cars_in_traffic.py | 6 +++--- server/nightr/strategies/upstairs_neighbour.py | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/nightr/strategies/cars_in_traffic.py b/server/nightr/strategies/cars_in_traffic.py index 7c1ff40..dcb1deb 100644 --- a/server/nightr/strategies/cars_in_traffic.py +++ b/server/nightr/strategies/cars_in_traffic.py @@ -27,13 +27,13 @@ def cars_in_traffic(context: Context) -> Prediction: diff = day_avr - night_avr if curr_avg >= day_avr: - p.reasons.append(f"Because {curr_avg:.1f} cars are driving around Aarhus right now and {day_avr:.0f} is the expected number for daytime") + p.reasons.append(f"Because {curr_avg:.1f} cars are driving around Aarhus right now and {day_avr:.1f} is the expected number for daytime") p.probability = 0.0 elif curr_avg <= night_avr: - p.reasons.append(f"Because {curr_avg::.1f} cars are driving around Aarhus right now and {night_avr:.0f} is the expected number for nighttime") + p.reasons.append(f"Because {curr_avg:.1f} cars are driving around Aarhus right now and {night_avr:.1f} is the expected number for nighttime") p.probability = 1.0 else: - p.reasons.append(f"Because average for daytime is {day_avr} and average for nighttime is {night_avr:.0f}, but the current average is {curr_avg}") + p.reasons.append(f"Because average for daytime is {day_avr:.1f} and average for nighttime is {night_avr:.1f}, but the current average is {curr_avg:.1f}") res = 1 - curr_avg / diff p.probability = res diff --git a/server/nightr/strategies/upstairs_neighbour.py b/server/nightr/strategies/upstairs_neighbour.py index bfc45fa..25ce40f 100644 --- a/server/nightr/strategies/upstairs_neighbour.py +++ b/server/nightr/strategies/upstairs_neighbour.py @@ -1,12 +1,17 @@ import requests from bs4 import BeautifulSoup -from datetime import datetime +from datetime import datetime, timedelta from ..util import Prediction, Context +last_update = datetime.min def update(): - requests.post('https://euw.op.gg/summoner/ajax/renew.json/', data={'summonerId': 34009256}) + global last_update + now = datetime.utcnow() + if (now - timedelta(minutes=5)) > last_update: + requests.post('https://euw.op.gg/summoner/ajax/renew.json/', data={'summonerId': 34009256}) + last_update = now def check_games(context: Context) -> Prediction: From 64c22b3f087f8fa4fb36aa84225bd787caee86de Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 21:18:40 +0200 Subject: [PATCH 05/10] Lol --- server/nightr/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/nightr/app.py b/server/nightr/app.py index b84d768..972c36a 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -40,7 +40,7 @@ def probabilities(): context = Context() else: phone_data = request.get_json(force=True) - logger.debug("phone_data:\n%s", json.dumps(phone_data, indent=2)) + logger.debug("phone_data:\n%s", json.dumps({(k, v) for k, v in phone_data.items() if not k == "image"}, indent=2)) context = Context(**phone_data["data"]) #logger.debug("Context: %s", context) From 0113869d68f1ce7b82d626bfbb0603848dacdce5 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 21:22:22 +0200 Subject: [PATCH 06/10] Revert "Lol" This reverts commit 64c22b3f --- server/nightr/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/nightr/app.py b/server/nightr/app.py index 972c36a..b84d768 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -40,7 +40,7 @@ def probabilities(): context = Context() else: phone_data = request.get_json(force=True) - logger.debug("phone_data:\n%s", json.dumps({(k, v) for k, v in phone_data.items() if not k == "image"}, indent=2)) + logger.debug("phone_data:\n%s", json.dumps(phone_data, indent=2)) context = Context(**phone_data["data"]) #logger.debug("Context: %s", context) From 8cf08d67193e17a5bf6fd915796698a0bb50b8af Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sat, 6 Apr 2019 22:29:09 +0200 Subject: [PATCH 07/10] fixed messages --- server/nightr/strategies/tide_strat.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/nightr/strategies/tide_strat.py b/server/nightr/strategies/tide_strat.py index f876158..471ca2b 100644 --- a/server/nightr/strategies/tide_strat.py +++ b/server/nightr/strategies/tide_strat.py @@ -20,9 +20,8 @@ def is_tide(context: Context) -> Prediction: month, cur_year_total_cars, last_year_total_cars = determine_month() month = int(month) p.reasons.append(f"The month is {calendar.month_name[month]}") - p.reasons.append(f"The number of cars having driven on the Storbæltsbro is {cur_year_total_cars}") - p.reasons.append(f"The number of cars having driven over it in the last year is {last_year_total_cars}") - + p.reasons.append(f"The number of cars having driven on the Storbæltsbro is {cur_year_total_cars}, in the current year") + p.reasons.append(f"The number of cars having driven over it in the last year is {last_year_total_cars}, thus the frequency is: {last_year_total_cars / cur_year_total_cars}") tide_data = requests.get('https://www.dmi.dk/fileadmin/user_upload/Bruger_upload/Tidevand/2019/Aarhus.t.txt') @@ -78,9 +77,9 @@ def is_tide(context: Context) -> Prediction: moments.append(time[0]) night = sum([1 for x in moments if 6 >= x.hour or x.hour >= 22]) + p.reasons.append(f"The water level is currently at {current_water_level}") + p.reasons.append(f"The number of times the water is at the current level at nighttime is: {night}, compared to the total amount of times in {calendar.month_name[month]}, being {len(moments)}") - p.reasons.append(f"And because the number of times the water is at the current level at nighttime is: {night}, compared to the total amount of times in {calendar.month_name[month]}, being {len(moments)}") - - p.probability = night / len(moments) + p.probability = 1 - (night / len(moments)) return p From 98c154771a6c7c9934251834e9ed51f03ac676eb Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sat, 6 Apr 2019 22:39:19 +0200 Subject: [PATCH 08/10] Worst svm ever --- .../strategies/nightness_classifier.pkl | Bin 0 -> 1640 bytes server/nightr/strategies/svm_strat.py | 26 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 server/nightr/strategies/nightness_classifier.pkl diff --git a/server/nightr/strategies/nightness_classifier.pkl b/server/nightr/strategies/nightness_classifier.pkl new file mode 100644 index 0000000000000000000000000000000000000000..554fa03defdbfcf8ed4507e416c2bfd519a9298d GIT binary patch literal 1640 zcmZuyU2GIp6rSD6Pp4F?R#5~MExJ${%a2;1IJQMs7+G<#FbaB^nZ3I+barOW%WfCRK1ejthrY<0nD|mP_JQbw1PR$Rq?+)c;?KQjw)>;KnarJg?)}dB z&d)tF-ev@&Hr0Gb3d%*vu(cqdfw*_yun5B1$z66|huW|NkNbKamZCUE3qGaLuCyVd zpcRW6h-vxcv7ggtyI+abxHR7f9ciWo2dW5N8%dJ7aXS+Srf)f;mQ#SPNwtFsJm1wd-LkE43~ruOMJ6&d!=xmz zj#0Qp`C47ZMLb;O2(=1k2)AZbZlO$l-3=&opHY{xWl=jytdRO}+pd4uK$x#NIk!lH zPzx#C9>YlBX+DE3Kcja3M>Byt>PezUnJ!1O1L?4<+mWgqEOX7+M?n)t>prj*bSZN?obaEO$F2X8|bez(=mE;86g96vjG4A)8ow&+{ zV=UvVYgk-~aG%OUo$rVH6+uayhMp{}NwIYDj10g7nM?*f$Co06@Su+2)NI>5LRhvv zNKKY>c9@Mhd45K^wQ?k|*5rPyi=a1Ut~6Jf$nYVP@iJGNF#)R|*2e^-EIiBznEyB3 zr<)C1g1{N_frUuo(%aA|J)XXxL${?*y@SLI*+Sa;}f_a*uFE0;ca=S{ZGO6<8Nw|}$!jZc64US2O=J3jON zv^=kO`lCc~#q^B4t#V>(<-~=$-c5y$*^9r;$X{OUWluwI@1ak|zes*n*L$IBq}p?K zNEpABID$y*`zhY~A?tRi6W z@NyEq1ACPuuZZXIENSv;1numLV1JVxwZ%>x5LSD<&yl9EzJS;lBREjU@~|FU0A0VQ e=dglF?H@u|^W*;rcnN*)lQwLTHp0s#UHTU&;REXc literal 0 HcmV?d00001 diff --git a/server/nightr/strategies/svm_strat.py b/server/nightr/strategies/svm_strat.py index 78a760c..58a17f6 100644 --- a/server/nightr/strategies/svm_strat.py +++ b/server/nightr/strategies/svm_strat.py @@ -6,10 +6,11 @@ import json import numpy as np -from server.nightr.strategies.strat_utils import write_json +from .strat_utils import write_json +from ..util import Context, Prediction -def find_data(time): +def write_data(time): write_json("https://portal.opendata.dk/api/3/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c", "parking_aarhus", time) def load_data(): @@ -18,7 +19,7 @@ def load_data(): Y = [] for filename in glob.glob("parking_aarhus*"): - p_class = '2330' in filename + p_class = '2235' in filename with open(filename) as file: data = json.load(file) @@ -32,13 +33,26 @@ def load_data(): def train(): X, Y = load_data() - classifier = svm.SVC(C=10, gamma=0.01, probability=True) + classifier = svm.SVC(gamma=0.01, probability=True) classifier.fit(X, Y) joblib.dump(classifier, "nightness_classifier.pkl") def predict(X): classifier = joblib.load("nightness_classifier.pkl") - prob = classifier.predict_proba(X) + prob = classifier.predict_proba(np.array(X).reshape(1, -1)) return prob[0, 1] -train() + +def perform_svm_pred(context: Context) -> Prediction: + p = Prediction() + data = requests.get('https://portal.opendata.dk/api/3/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c') + + records = data.json()['result']['records'] + X = [house['vehicleCount'] / house['totalSpaces'] for house in records] + X = [min(x, 1) for x in X] + p.reasons.append("Since we only have two data points") + p.reasons.append("Since our only two data points have 11 dimensions") + p.reasons.append("Since we are using a SVM") + + p.probability = predict(X) + return p From 8dc3c9ac2c58eac24f1e0755d45f64c35864f71b Mon Sep 17 00:00:00 2001 From: Milo Date: Sat, 6 Apr 2019 22:45:01 +0200 Subject: [PATCH 09/10] fixed cam img strat again --- server/nightr/app.py | 1 - server/nightr/strategies/miloStrats.py | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/nightr/app.py b/server/nightr/app.py index b84d768..b7b4072 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -85,7 +85,6 @@ def probabilities(): # If this prediction disagrees with the consensus it contributed negatively if prediction["night"] != night: prediction["contribution"] *= -1 - return jsonify({ "predictions": predictions, "weighted_probabilities_mean": mean, diff --git a/server/nightr/strategies/miloStrats.py b/server/nightr/strategies/miloStrats.py index d0418f7..0b51e43 100644 --- a/server/nightr/strategies/miloStrats.py +++ b/server/nightr/strategies/miloStrats.py @@ -11,15 +11,18 @@ def camImgStrat(context : Context) -> Prediction: The contents of the camera image """ img = context.image - average = img.mean() + average = float(img.mean()) p = Prediction() - p.weight = 0.7 - if average < 100: - p.probability = 1.0 + p.weight = 1.0 + + p.probability = 1 - round((average/255),3) + if average < 128: + p.weight = round(1 - (average/255), 3) p.reasons.append('Image was dark') + else: + p.weight = round(average / 255, 3) p.reasons.append('Image was light') - p.probability = 0.0 return p @@ -45,7 +48,11 @@ def tv2newsStrat(context : Context) -> Prediction: """ The number of articles releases in the last few hours on TV2.dk """ + + print('before') r = requests.get('http://mpx.services.tv2.dk/api/latest') + print('after') + data = r.json() publish_dates = [(x['pubDate'])//1000 for x in data][:10] delta_times = [] From 319c03067f6212af02ebbf8ef253d4ba85480f0c Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 23:00:08 +0200 Subject: [PATCH 10/10] Reasons and battery. --- server/nightr/app.py | 3 ++- server/nightr/strategies/battery.py | 21 +++++++++++++++++++ server/nightr/strategies/bing.py | 4 ++-- server/nightr/strategies/iss.py | 3 +-- server/nightr/strategies/just_eat.py | 8 ++++--- server/nightr/strategies/miloStrats.py | 11 ++++------ server/nightr/strategies/svm_strat.py | 6 +++--- .../nightr/strategies/upstairs_neighbour.py | 2 +- server/nightr/util.py | 4 ++-- 9 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 server/nightr/strategies/battery.py diff --git a/server/nightr/app.py b/server/nightr/app.py index b7b4072..ad3ce8f 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -10,7 +10,7 @@ from typing import List import requests_cache from flask import Flask, jsonify, logging, request -from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour, bing +from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour, bing, battery from .util import Context app = Flask(__name__) @@ -30,6 +30,7 @@ strategies = { "tide": tide_strat.is_tide, "upstairs_neighbour": upstairs_neighbour.check_games, "bing": bing.clock, + "battery_level": battery.battery_level, } diff --git a/server/nightr/strategies/battery.py b/server/nightr/strategies/battery.py new file mode 100644 index 0000000..b301ee8 --- /dev/null +++ b/server/nightr/strategies/battery.py @@ -0,0 +1,21 @@ +from ..util import Context, Prediction + + +def battery_level(context: Context) -> Prediction: + """ + If the battery is low, it's probably bedtime soon. + """ + p = Prediction() + + if context.battery > 60: + p.reasons.append("Battery level's good, so it's probably still early in the day.") + elif context.battery > 30: + p.reasons.append("Battery level's getting low, so it's probably around dinnertime.") + elif context.battery > 10: + p.reasons.append("Your phone is dying, so it's bedtime soon?") + else: + p.reasons.append("Your phone's practically dead, so it's probably around four in the morning.") + + p.probability = 1 - (context.battery / 100) # night is inverse proportional to battery level + + return p diff --git a/server/nightr/strategies/bing.py b/server/nightr/strategies/bing.py index 13b64fd..6b61db5 100644 --- a/server/nightr/strategies/bing.py +++ b/server/nightr/strategies/bing.py @@ -11,7 +11,7 @@ def clock(context: Context) -> Prediction: It's nighttime if Bing says it's daytime. """ p = Prediction() - p.weight = 0.05 + p.weight = 0.02 headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'} @@ -22,7 +22,7 @@ def clock(context: Context) -> Prediction: time = datetime.strptime(time_str, "%H:%M") night = time.hour < 6 or time.hour >= 22 - time_description = "" if night else "daytime" + time_description = "nighttime" if night else "daytime" time_description_oppersite = "daytime" if night else "nighttime" p.reasons.append(f"Bing says its {time_description}.") diff --git a/server/nightr/strategies/iss.py b/server/nightr/strategies/iss.py index 64b308a..bd759bc 100644 --- a/server/nightr/strategies/iss.py +++ b/server/nightr/strategies/iss.py @@ -1,5 +1,4 @@ import itertools -import logging from datetime import datetime from math import pi, sqrt, sin, cos, atan2 @@ -14,7 +13,7 @@ tf = TimezoneFinder(in_memory=True) def night_on_iss(context: Context) -> Prediction: """ - It is night if it is night on the ISS and it is currently orbiting above us. + It is night if it is night on the ISS and it is currently orbiting above us. http://www.isstracker.com/ """ p = Prediction() diff --git a/server/nightr/strategies/just_eat.py b/server/nightr/strategies/just_eat.py index 4376958..3bf29e8 100644 --- a/server/nightr/strategies/just_eat.py +++ b/server/nightr/strategies/just_eat.py @@ -17,7 +17,7 @@ def is_restaurant_open(name, open, close) -> Prediction: soup = BeautifulSoup(r.content, features='html5lib') listing_groups = soup.find_all('div', {'class': 'listing-group'}) - p.reasons.append("Hopefully we are not banned from Just-eat ..") + #p.reasons.append("Hopefully we are not banned from Just-eat ..") nice_group = None for x in listing_groups: @@ -32,10 +32,12 @@ def is_restaurant_open(name, open, close) -> Prediction: all_listings = nice_group.find_all('a', {'class': 'mediaElement'}) if any(name in x['href'] for x in all_listings): - p.reasons.append(f"{name} is currently open. We conclude from this, that there is {1 / 11}% chance of it being night outside!") + p.reasons.append(f"Our favorite pizza place, {name}, is currently open.") + p.reasons.append(f"We conclude from this, that there is {1 / 11}% chance of it being night outside") p.probability = 1 / 11 else: - p.reasons.append(f"{name} is not open. We can conclude from this, that there is {1 - (1/11)}% chance of it currently being night outside! ") + p.reasons.append(f"Our favorite pizza place, {name}, is closed.") + p.reasons.append(f"We can conclude from this, that there is {1 - (1/11)}% chance of it currently being night outside!") p.probability = 1 - (1 / 11) return p diff --git a/server/nightr/strategies/miloStrats.py b/server/nightr/strategies/miloStrats.py index 0b51e43..d061c3d 100644 --- a/server/nightr/strategies/miloStrats.py +++ b/server/nightr/strategies/miloStrats.py @@ -18,11 +18,11 @@ def camImgStrat(context : Context) -> Prediction: p.probability = 1 - round((average/255),3) if average < 128: p.weight = round(1 - (average/255), 3) - p.reasons.append('Image was dark') + p.reasons.append('Camera image was dark, so the sun has probably set.') else: p.weight = round(average / 255, 3) - p.reasons.append('Image was light') + p.reasons.append('Camera image was light, so the sun is still shining.') return p @@ -37,10 +37,10 @@ def australiaStrat(context : Context) -> Prediction: if hour > 22 or hour < 6: p.probability = 0.0 - p.reasons.append('It\'s night-time in Australia') + p.reasons.append('It\'s night-time in Australia, so it must be day-time here.') else: p.probability = 1.0 - p.reasons.append('It\'s day-time in Australia') + p.reasons.append('It\'s day-time in Australia, so it must be night-time here.') return p @@ -48,10 +48,7 @@ def tv2newsStrat(context : Context) -> Prediction: """ The number of articles releases in the last few hours on TV2.dk """ - - print('before') r = requests.get('http://mpx.services.tv2.dk/api/latest') - print('after') data = r.json() publish_dates = [(x['pubDate'])//1000 for x in data][:10] diff --git a/server/nightr/strategies/svm_strat.py b/server/nightr/strategies/svm_strat.py index 58a17f6..0af7835 100644 --- a/server/nightr/strategies/svm_strat.py +++ b/server/nightr/strategies/svm_strat.py @@ -50,9 +50,9 @@ def perform_svm_pred(context: Context) -> Prediction: records = data.json()['result']['records'] X = [house['vehicleCount'] / house['totalSpaces'] for house in records] X = [min(x, 1) for x in X] - p.reasons.append("Since we only have two data points") - p.reasons.append("Since our only two data points have 11 dimensions") - p.reasons.append("Since we are using a SVM") + p.reasons.append("We only have two data points") + p.reasons.append("Our only two data points have 11 dimensions") + p.reasons.append("We are using a SVM") p.probability = predict(X) return p diff --git a/server/nightr/strategies/upstairs_neighbour.py b/server/nightr/strategies/upstairs_neighbour.py index 25ce40f..c0f5f70 100644 --- a/server/nightr/strategies/upstairs_neighbour.py +++ b/server/nightr/strategies/upstairs_neighbour.py @@ -34,7 +34,7 @@ def check_games(context: Context) -> Prediction: last_game_in_hours = (((datetime.now() - last_played_game).seconds)/60/60) if last_game_in_hours < 2: - p.reasons.append("Alexanders upstairs neighbour is currently playing league") + p.reasons.append("Alexander's upstairs neighbour is currently playing league") p.probability = 0.8 else: last_game_in_hours = min(24.0, last_game_in_hours) diff --git a/server/nightr/util.py b/server/nightr/util.py index 6c70643..82725a1 100644 --- a/server/nightr/util.py +++ b/server/nightr/util.py @@ -9,8 +9,8 @@ import numpy as np @dataclass class Context: - battery: int = 100 - position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) + battery: int = 55 + position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) # Denmark somewhere image: np.ndarray = None # App settings