From 9fa81de6a2873054c48f8eacfbec08b778b9f7e4 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 7 Apr 2019 02:17:31 +0200 Subject: [PATCH 1/7] merge --- client/Nightr/src/app/home-page/home-page.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/Nightr/src/app/home-page/home-page.component.ts b/client/Nightr/src/app/home-page/home-page.component.ts index 0894901..3b29d40 100644 --- a/client/Nightr/src/app/home-page/home-page.component.ts +++ b/client/Nightr/src/app/home-page/home-page.component.ts @@ -4,7 +4,7 @@ import { RouterExtensions } from "nativescript-angular/router"; import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures' import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation"; -import { MyHttpPostService } from '../services/my-http-post-service'' +import { MyHttpPostService } from '../services/my-http-post-service' @Component({ From 5e512aba8e1a583f1f10017a56984530687198d7 Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sun, 7 Apr 2019 02:25:31 +0200 Subject: [PATCH 2/7] spelling mistake --- server/nightr/strategies/tide_strat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/nightr/strategies/tide_strat.py b/server/nightr/strategies/tide_strat.py index 471ca2b..ef13e8c 100644 --- a/server/nightr/strategies/tide_strat.py +++ b/server/nightr/strategies/tide_strat.py @@ -11,7 +11,7 @@ from ..util import Context, Prediction def is_tide(context: Context) -> Prediction: """ - Determine whether or not it is night in Aarhus based no the current water level and which month we are in, based + Determine whether or not it is night in Aarhus based on the current water level and which month we are in, based on number of cars driving across The Storbæltsbro. """ From fc6baa68edf139ededc03e4ff969970972187fa9 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sun, 7 Apr 2019 02:35:26 +0200 Subject: [PATCH 3/7] Fix ISS. --- server/nightr/strategies/iss.py | 48 +++++++++++++++------------- server/nightr/strategies/just_eat.py | 2 +- server/requirements.txt | 1 - 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/server/nightr/strategies/iss.py b/server/nightr/strategies/iss.py index 4972a43..4f1981c 100644 --- a/server/nightr/strategies/iss.py +++ b/server/nightr/strategies/iss.py @@ -1,15 +1,11 @@ -import itertools -from datetime import datetime +import operator +from datetime import datetime, timezone from math import pi, sqrt, sin, cos, atan2 -import pytz import requests -from timezonefinder import TimezoneFinder from ..util import Context, Prediction -tf = TimezoneFinder(in_memory=True) - def night_on_iss(context: Context) -> Prediction: """ @@ -20,34 +16,43 @@ def night_on_iss(context: Context) -> Prediction: if not context.flat_earth: iss_position = requests.get("http://api.open-notify.org/iss-now.json").json()["iss_position"] the_iss = "The ISS" + at_iss_location = "at the ISS's location" iss_position_description = "on board the ISS" else: - p.reasons.append("The ISS is (obviously) located in Hollywood") + p.reasons.append('The "ISS" is obviously a studio in Hollywood') the_iss = "Hollywood" iss_position = {'latitude': 34.092808, 'longitude': -118.328659} # Hollywood + at_iss_location = "in Hollywood" iss_position_description = "in the Hollywood studio" - phone_position = context.position + sun_times = requests.get(f"https://api.sunrise-sunset.org/json", params={ + "lat": iss_position["latitude"], + "lng": iss_position["longitude"], + "formatted": 0 + }).json()["results"] + + iss_position_sunrise = datetime.strptime(sun_times["sunrise"], "%Y-%m-%dT%H:%M:%S%z") + iss_position_sunset = datetime.strptime(sun_times["sunset"], "%Y-%m-%dT%H:%M:%S%z") + + p.reasons.append(f"The sun rises and sets at UTC {iss_position_sunrise.strftime('%H:%M')} and {iss_position_sunset.strftime('%H:%M')}, respectively, {at_iss_location}.") + + utcnow = datetime.now(timezone.utc) + p.reasons.append(f"It is currently {utcnow.strftime('%H:%M')} UTC") + + iss_night = utcnow < iss_position_sunrise or iss_position_sunset < utcnow + iss_time_description = "nighttime" if iss_night else "daytime" + p.reasons.append(f"Therefore, it is {iss_time_description} {iss_position_description}.") # Calculate ratio: a number between 0 and 1 saying how close we are to the ISS + phone_position = context.position distance = haversine(iss_position, phone_position) max_distance = 40075 / 2 # the furthest you can be from any position is half of the earth's circumference ratio = distance / max_distance # We're in the same "timezone" as the ISS if we're on the same half of the earth on_iss_time = ratio < 0.5 - side = "same" if on_iss_time else "other" p.reasons.append(f"{the_iss} is {int(distance)} km away, so we are on the {side} side of the earth.") - for i in itertools.count(1): - iss_tz = tf.closest_timezone_at(lng=float(iss_position["longitude"]), lat=float(iss_position["latitude"]), - delta_degree=i) - if iss_tz is not None: - break - - iss_time = datetime.now(pytz.timezone(iss_tz)) - - iss_night = iss_time.hour < 6 or iss_time.hour >= 22 # iss_night on_iss_time night # 0 0 1 @@ -56,11 +61,10 @@ def night_on_iss(context: Context) -> Prediction: # 1 1 1 night = iss_night == on_iss_time - iss_time_description = "nighttime" if iss_night else "daytime" time_description = "nighttime" if night else "daytime" - p.probability = float(night) - p.reasons.append(f"It is {iss_time_description} {iss_position_description}.") - p.reasons.append(f"Therefore, it must be {time_description} where we are.") + op = operator.add if night else operator.sub + p.probability = op(0.5, ratio * 0.5) + p.reasons.append(f"So it must be {time_description} where we are.") return p diff --git a/server/nightr/strategies/just_eat.py b/server/nightr/strategies/just_eat.py index 634c9a1..aa074e9 100644 --- a/server/nightr/strategies/just_eat.py +++ b/server/nightr/strategies/just_eat.py @@ -34,7 +34,7 @@ def is_restaurant_open(name, open, close) -> Prediction: else: 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) + p.probability = round(1 - (1 / 11), 2) return p diff --git a/server/requirements.txt b/server/requirements.txt index a900813..00f5205 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -5,7 +5,6 @@ pytz beautifulsoup4 pandas opencv-python -timezonefinder scikit-learn html5lib xlrd From d39ee7d25f6b482d95e070f4f3ecb6e823bb9ba1 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sun, 7 Apr 2019 02:37:52 +0200 Subject: [PATCH 4/7] Fuck Bing. --- server/nightr/strategies/bing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/nightr/strategies/bing.py b/server/nightr/strategies/bing.py index 6b61db5..fdae109 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.02 + p.weight = 0.01 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'} From d1e8593429d896e1924e22cdd84a0ca380d756da Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sun, 7 Apr 2019 02:38:07 +0200 Subject: [PATCH 5/7] pls --- server/nightr/strategies/svm_strat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/nightr/strategies/svm_strat.py b/server/nightr/strategies/svm_strat.py index 5d51759..2423258 100644 --- a/server/nightr/strategies/svm_strat.py +++ b/server/nightr/strategies/svm_strat.py @@ -55,7 +55,7 @@ def perform_svm_pred(context: Context) -> Prediction: X = [min(x, 1) for x in X] 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.reasons.append("We are using a SVM. Apparently that's a poor idea.") p.probability = float(predict(X)) return p From 7d1b4d4537773d57061f1c36d71f4563829f5976 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sun, 7 Apr 2019 03:04:26 +0200 Subject: [PATCH 6/7] Australia in Australia strat. --- server/nightr/strategies/miloStrats.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/server/nightr/strategies/miloStrats.py b/server/nightr/strategies/miloStrats.py index afe5af5..2b7903d 100644 --- a/server/nightr/strategies/miloStrats.py +++ b/server/nightr/strategies/miloStrats.py @@ -35,12 +35,20 @@ def australiaStrat(context : Context) -> Prediction: hour = t.hour p = Prediction() - if hour > 22 or hour < 6: - p.probability = 0.0 - p.reasons.append('It\'s night-time in Australia, so it must be day-time here.') + if context.in_australia: + if hour > 22 or hour < 6: + p.probability = 1.0 + p.reasons.append('It\'s night-time in Australia, and that\'s where we\'re at.') + else: + p.probability = 0.0 + p.reasons.append('It\'s day-time in Australia, and that\'s where we\'re at.') else: - p.probability = 1.0 - p.reasons.append('It\'s day-time in Australia, so it must be night-time here.') + if hour > 22 or hour < 6: + p.probability = 0.0 + 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, so it must be night-time here.') return p From 62e549015ec8aab235246fbc2c840aca4cb72dd8 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sun, 7 Apr 2019 03:39:16 +0200 Subject: [PATCH 7/7] Randomised battery. --- server/nightr/util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/nightr/util.py b/server/nightr/util.py index 82725a1..5985465 100644 --- a/server/nightr/util.py +++ b/server/nightr/util.py @@ -1,4 +1,5 @@ import base64 +import random from dataclasses import dataclass, field from pathlib import Path from typing import List, Dict @@ -9,7 +10,7 @@ import numpy as np @dataclass class Context: - battery: int = 55 + battery: int = field(default_factory=lambda: random.randint(0, 100)) position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) # Denmark somewhere image: np.ndarray = None