Spaces:
Sleeping
Sleeping
Jompatron
commited on
Commit
·
6f5a567
1
Parent(s):
41859c4
stuff
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import tempfile
|
|
| 5 |
import hopsworks
|
| 6 |
from xgboost import XGBRegressor
|
| 7 |
from datetime import datetime, timedelta
|
|
|
|
| 8 |
|
| 9 |
from airquality.util import plot_air_quality_forecast
|
| 10 |
|
|
@@ -49,13 +50,16 @@ def load_resources_v2():
|
|
| 49 |
|
| 50 |
return model, fv, weather_fg, project
|
| 51 |
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
# -------------------------
|
| 55 |
# FORECAST LOGIC (NEXT 7 DAYS)
|
| 56 |
# -------------------------
|
| 57 |
def generate_forecast_v1(days):
|
| 58 |
-
model, fv, weather_fg, project =
|
| 59 |
|
| 60 |
today = datetime.utcnow().date()
|
| 61 |
df_future = weather_fg.read()
|
|
@@ -81,9 +85,11 @@ def generate_forecast_v1(days):
|
|
| 81 |
tmp_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
|
| 82 |
plot_air_quality_forecast("linkoping", "hamngatan-10", df_preds, tmp_path)
|
| 83 |
|
|
|
|
|
|
|
| 84 |
|
| 85 |
def generate_forecast_v2(days):
|
| 86 |
-
model, fv, weather_fg, project =
|
| 87 |
|
| 88 |
today = datetime.utcnow().date()
|
| 89 |
df_future = weather_fg.read().sort_values("date")
|
|
@@ -134,7 +140,7 @@ def generate_forecast_v2(days):
|
|
| 134 |
# HINDCAST LOGIC (LAST 7 DAYS)
|
| 135 |
# -------------------------
|
| 136 |
def generate_hindcast_v1(days):
|
| 137 |
-
model, fv, weather_fg, project =
|
| 138 |
|
| 139 |
features_df, labels_df = fv.training_data(
|
| 140 |
start_time=datetime.utcnow().date() - timedelta(days=days),
|
|
@@ -156,7 +162,7 @@ def generate_hindcast_v1(days):
|
|
| 156 |
|
| 157 |
|
| 158 |
def generate_hindcast_v2(days):
|
| 159 |
-
model, fv, weather_fg, project =
|
| 160 |
|
| 161 |
features_df, labels_df = fv.training_data(
|
| 162 |
start_time=datetime.utcnow().date() - timedelta(days=days),
|
|
|
|
| 5 |
import hopsworks
|
| 6 |
from xgboost import XGBRegressor
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
+
import numpy as np
|
| 9 |
|
| 10 |
from airquality.util import plot_air_quality_forecast
|
| 11 |
|
|
|
|
| 50 |
|
| 51 |
return model, fv, weather_fg, project
|
| 52 |
|
| 53 |
+
resources_v1 = load_resources_v1()
|
| 54 |
+
resources_v2 = load_resources_v2()
|
| 55 |
+
|
| 56 |
|
| 57 |
|
| 58 |
# -------------------------
|
| 59 |
# FORECAST LOGIC (NEXT 7 DAYS)
|
| 60 |
# -------------------------
|
| 61 |
def generate_forecast_v1(days):
|
| 62 |
+
model, fv, weather_fg, project = resources_v1
|
| 63 |
|
| 64 |
today = datetime.utcnow().date()
|
| 65 |
df_future = weather_fg.read()
|
|
|
|
| 85 |
tmp_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
|
| 86 |
plot_air_quality_forecast("linkoping", "hamngatan-10", df_preds, tmp_path)
|
| 87 |
|
| 88 |
+
return tmp_path
|
| 89 |
+
|
| 90 |
|
| 91 |
def generate_forecast_v2(days):
|
| 92 |
+
model, fv, weather_fg, project = resources_v2
|
| 93 |
|
| 94 |
today = datetime.utcnow().date()
|
| 95 |
df_future = weather_fg.read().sort_values("date")
|
|
|
|
| 140 |
# HINDCAST LOGIC (LAST 7 DAYS)
|
| 141 |
# -------------------------
|
| 142 |
def generate_hindcast_v1(days):
|
| 143 |
+
model, fv, weather_fg, project = resources_v1
|
| 144 |
|
| 145 |
features_df, labels_df = fv.training_data(
|
| 146 |
start_time=datetime.utcnow().date() - timedelta(days=days),
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
def generate_hindcast_v2(days):
|
| 165 |
+
model, fv, weather_fg, project = resources_v2
|
| 166 |
|
| 167 |
features_df, labels_df = fv.training_data(
|
| 168 |
start_time=datetime.utcnow().date() - timedelta(days=days),
|