Update names, update ISS.

This commit is contained in:
Casper 2019-04-07 01:29:09 +02:00
parent 7b2ea7ea8d
commit 561b022121
No known key found for this signature in database
GPG Key ID: 289CA03790535054
3 changed files with 21 additions and 18 deletions

View File

@ -10,28 +10,29 @@ 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, svm_strat, battery
from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour, bing, svm_strat, battery, just_eat
from .util import Context
app = Flask(__name__)
logger = logging.create_logger(app)
logger.setLevel(DEBUG)
requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10))
requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=2))
strategies = {
# name: (weight, probability function)
"tv2news": miloStrats.tv2newsStrat,
"australia": miloStrats.australiaStrat,
"camera": miloStrats.camImgStrat,
"iss": iss.night_on_iss,
"cars_in_traffic": cars_in_traffic.cars_in_traffic,
"tide": tide_strat.is_tide,
"upstairs_neighbour": upstairs_neighbour.check_games,
"bing": bing.clock,
"svm_parking": svm_strat.perform_svm_pred,
"battery_level": battery.battery_level,
"TV2 News": miloStrats.tv2newsStrat,
"Australia": miloStrats.australiaStrat,
"Camera Image": miloStrats.camImgStrat,
"The International Space Station": iss.night_on_iss,
"Nearby Traffic situation": cars_in_traffic.cars_in_traffic,
"Tidal Measurements": tide_strat.is_tide,
"Legends of Nighttime": upstairs_neighbour.check_games,
"Bing AI": bing.clock,
"ML Parking": svm_strat.perform_svm_pred,
"Phone Battery Level": battery.battery_level,
"Pizza Availability": just_eat.do_just_eat_strat,
}
@ -87,6 +88,9 @@ def probabilities():
# If this prediction disagrees with the consensus it contributed negatively
if prediction["night"] != night:
prediction["contribution"] *= -1
predictions.sort(key=lambda p: (p["contribution"], p["probability"]), reverse=True)
return jsonify({
"predictions": predictions,
"weighted_probabilities_mean": mean,

View File

@ -40,11 +40,11 @@ def night_on_iss(context: Context) -> Prediction:
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"]),
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
@ -75,6 +75,9 @@ def haversine(pos1, pos2):
lat2 = float(pos2["latitude"])
long2 = float(pos2["longitude"])
lat1 = 0 # we're only interested in the distance in the longitude for the timezone calculation
lat2 = 0
degree_to_rad = float(pi / 180.0)
d_lat = (lat2 - lat1) * degree_to_rad

View File

@ -1,12 +1,8 @@
import requests
from bs4 import BeautifulSoup
from datetime import datetime, timedelta
import requests_cache
from ..util import Context, Prediction
requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10))
def is_restaurant_open(name, open, close) -> Prediction:
p = Prediction()