-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
44 lines (40 loc) · 1.56 KB
/
predict.py
File metadata and controls
44 lines (40 loc) · 1.56 KB
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
40
41
42
43
44
from joblib import load
import requests as req
from pandas import DataFrame
from tqdm import tqdm
def predict(df, dewpt=False) -> list:
model = None
if dewpt:
model = load('models/dewpt_model.joblib')
else:
model = load('models/temp_model_2.joblib')
# print(df)
# df = read_csv('training_data/march24_test_temp.csv', index_col=['Date/Time', 'Year', 'Month', 'Day', 'Time'])
return model.predict(df)
def get_predictor_values(epoch_time, predictors, use_predicted, predictions):
values = dict()
values['date_value'] = epoch_time
for p in tqdm(predictors):
val = None
if 'temp' in p:
digits = int(p.split('_')[1])
resp = req.get(
f'http://sofe3720.ml/ec/past/{epoch_time}/{digits}').json()['message']['data']
if digits in use_predicted and len(resp) > 0:
val = predictions[len(predictions)-digits]['predicted']['temp']
elif len(resp) > 0:
val = resp[0]['temp']
else:
digits = int(p.split('_')[2])
resp = req.get(
f'http://sofe3720.ml/ec/past/{epoch_time}/{digits}').json()['message']['data']
if digits in use_predicted and len(resp) > 0:
val = predictions[len(predictions)-digits]['predicted']['dew_point']
elif len(resp) > 0:
val = resp[0]['dew_point']
val = val if val else 0.0
values[p] = val
df = DataFrame.from_dict(values, orient='index')
df = df.T.set_index('date_value')
# print(df)
return df