-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprediction_manager.py
39 lines (30 loc) · 1.4 KB
/
prediction_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from datetime import datetime, timedelta
import requests
from file_saver import FileSaver
BASE_URL = "http://predict.cusf.co.uk/api/v1/"
HOURS_AHEAD_TO_PREDICT = 120 # hours
class PredictionManager:
def __init__(self):
self.filesaver = FileSaver()
def predict_and_save(self, ts, alt, long, lat, file_name):
# request prediction of flight
prediction = self.make_request(ts, HOURS_AHEAD_TO_PREDICT, alt, long, lat)
# save prediction to file.
self.filesaver.save_file(file_name, prediction.content)
@staticmethod
def gen_filename(file_str_prefix):
file_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
file_name = '{0}_{1}.json'.format(file_str_prefix, file_time)
return file_name
def make_request(self, start_time: datetime, hours_ahead: int, current_alt, current_long, current_lat):
params = {
"launch_latitude": current_lat,
"launch_longitude": current_long % 360, # convert from [-180,180] to [0,360]
"launch_altitude": current_alt - 1,
"launch_datetime": start_time.astimezone().isoformat() + "Z",
"ascent_rate": 0.8,
"float_altitude": current_alt,
"stop_datetime": (start_time + timedelta(hours=hours_ahead)).astimezone().isoformat(),
"profile": "float_profile"
}
return requests.get(BASE_URL, params=params)