Update names, update ISS.
This commit is contained in:
parent
7b2ea7ea8d
commit
561b022121
|
@ -10,28 +10,29 @@ from typing import List
|
||||||
import requests_cache
|
import requests_cache
|
||||||
from flask import Flask, jsonify, logging, request
|
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
|
from .util import Context
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
logger = logging.create_logger(app)
|
logger = logging.create_logger(app)
|
||||||
logger.setLevel(DEBUG)
|
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 = {
|
strategies = {
|
||||||
# name: (weight, probability function)
|
# name: (weight, probability function)
|
||||||
"tv2news": miloStrats.tv2newsStrat,
|
"TV2 News": miloStrats.tv2newsStrat,
|
||||||
"australia": miloStrats.australiaStrat,
|
"Australia": miloStrats.australiaStrat,
|
||||||
"camera": miloStrats.camImgStrat,
|
"Camera Image": miloStrats.camImgStrat,
|
||||||
"iss": iss.night_on_iss,
|
"The International Space Station": iss.night_on_iss,
|
||||||
"cars_in_traffic": cars_in_traffic.cars_in_traffic,
|
"Nearby Traffic situation": cars_in_traffic.cars_in_traffic,
|
||||||
"tide": tide_strat.is_tide,
|
"Tidal Measurements": tide_strat.is_tide,
|
||||||
"upstairs_neighbour": upstairs_neighbour.check_games,
|
"Legends of Nighttime": upstairs_neighbour.check_games,
|
||||||
"bing": bing.clock,
|
"Bing AI": bing.clock,
|
||||||
"svm_parking": svm_strat.perform_svm_pred,
|
"ML Parking": svm_strat.perform_svm_pred,
|
||||||
"battery_level": battery.battery_level,
|
"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 this prediction disagrees with the consensus it contributed negatively
|
||||||
if prediction["night"] != night:
|
if prediction["night"] != night:
|
||||||
prediction["contribution"] *= -1
|
prediction["contribution"] *= -1
|
||||||
|
|
||||||
|
predictions.sort(key=lambda p: (p["contribution"], p["probability"]), reverse=True)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"predictions": predictions,
|
"predictions": predictions,
|
||||||
"weighted_probabilities_mean": mean,
|
"weighted_probabilities_mean": mean,
|
||||||
|
|
|
@ -40,11 +40,11 @@ def night_on_iss(context: Context) -> Prediction:
|
||||||
side = "same" if on_iss_time else "other"
|
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.")
|
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):
|
for i in itertools.count(1):
|
||||||
iss_tz = tf.closest_timezone_at(lng=float(iss_position["longitude"]),
|
iss_tz = tf.closest_timezone_at(lng=float(iss_position["longitude"]), lat=float(iss_position["latitude"]),
|
||||||
lat=float(iss_position["latitude"]),
|
|
||||||
delta_degree=i)
|
delta_degree=i)
|
||||||
if iss_tz is not None:
|
if iss_tz is not None:
|
||||||
break
|
break
|
||||||
|
|
||||||
iss_time = datetime.now(pytz.timezone(iss_tz))
|
iss_time = datetime.now(pytz.timezone(iss_tz))
|
||||||
|
|
||||||
iss_night = iss_time.hour < 6 or iss_time.hour >= 22
|
iss_night = iss_time.hour < 6 or iss_time.hour >= 22
|
||||||
|
@ -75,6 +75,9 @@ def haversine(pos1, pos2):
|
||||||
lat2 = float(pos2["latitude"])
|
lat2 = float(pos2["latitude"])
|
||||||
long2 = float(pos2["longitude"])
|
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)
|
degree_to_rad = float(pi / 180.0)
|
||||||
|
|
||||||
d_lat = (lat2 - lat1) * degree_to_rad
|
d_lat = (lat2 - lat1) * degree_to_rad
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from datetime import datetime, timedelta
|
|
||||||
import requests_cache
|
|
||||||
|
|
||||||
from ..util import Context, Prediction
|
from ..util import Context, Prediction
|
||||||
|
|
||||||
requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10))
|
|
||||||
|
|
||||||
|
|
||||||
def is_restaurant_open(name, open, close) -> Prediction:
|
def is_restaurant_open(name, open, close) -> Prediction:
|
||||||
p = Prediction()
|
p = Prediction()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user