diff --git a/StreamServer/src/query/prediction.py b/StreamServer/src/query/prediction.py index 9f13d2b..1b1a283 100644 --- a/StreamServer/src/query/prediction.py +++ b/StreamServer/src/query/prediction.py @@ -12,11 +12,11 @@ def get_temp_prediction_data(session: Session): limit_day = current_time + timedelta(days=5) return session.query( - PredictionData.timestamp, PredictionData.indoor_temp + PredictionData.timestamp, PredictionData.indoor_temp, PredictionData.outdoor_temp ).filter( PredictionData.timestamp >= current_time, PredictionData.timestamp < limit_day - ).order_by(PredictionData.timestamp.desc()).all() + ).order_by(PredictionData.timestamp.asc()).limit(12) def get_feature_prediction_data(session: Session): @@ -30,4 +30,4 @@ def get_feature_prediction_data(session: Session): ).filter( PredictionData.timestamp >= current_time, PredictionData.timestamp < limit_day - ).order_by(PredictionData.timestamp.desc()).all() \ No newline at end of file + ).order_by(PredictionData.timestamp.asc()).limit(12) \ No newline at end of file diff --git a/StreamServer/src/routers/prediction.py b/StreamServer/src/routers/prediction.py index 382a330..01b6df9 100644 --- a/StreamServer/src/routers/prediction.py +++ b/StreamServer/src/routers/prediction.py @@ -10,7 +10,7 @@ from fastapi import APIRouter, Depends, HTTPException, status from analytic.health.indoor_model import XgboostIndoorModel from config import WEATHER_API_KEY, LAT, LON from database import SessionLocal -from scheme import IndoorTemperature +from scheme import PredictonTemperature from models import PredictionData from query.prediction import get_temp_prediction_data, get_feature_prediction_data @@ -38,7 +38,7 @@ def _fetch_data_from_api() -> dict: return response.json() -@router.get("/indoor/predict/", response_model=list[IndoorTemperature]) +@router.get("/indoor/predict/", response_model=list[PredictonTemperature]) async def get_tomorrow_indoor_temp(db: Session = Depends(get_db)): result = get_temp_prediction_data(db) if not result: @@ -54,7 +54,7 @@ async def get_tomorrow_indoor_temp(db: Session = Depends(get_db)): data = data['main'] features = [data['temp'], data['feels_like'], data['pressure'], data['humidity']] result = xgboost.predict(features) - results.append(IndoorTemperature(indoor_temp=result, timestamp=ts)) + results.append(PredictonTemperature(indoor_temp=result, timestamp=ts, outdoor_temp=data['temp'])) new_data_entry = PredictionData( timestamp=ts, indoor_temp=result, @@ -74,5 +74,5 @@ async def get_tomorrow_indoor_temp(db: Session = Depends(get_db)): else: for i in features: indoor = xgboost.predict([i.outdoor_temp, i.outdoor_feels_like, i.outdoor_pressure, i.outdoor_humidity]) - result.append(IndoorTemperature(timestamp=i.timestamp, indoor_temp=indoor)) + result.append(PredictonTemperature(timestamp=i.timestamp, indoor_temp=indoor, outdoor_temp=i.outdoor_temp)) return result diff --git a/StreamServer/src/scheme.py b/StreamServer/src/scheme.py index 663ee08..8b1ec62 100644 --- a/StreamServer/src/scheme.py +++ b/StreamServer/src/scheme.py @@ -68,9 +68,11 @@ class Camera(BaseModel): status: bool = False -class IndoorTemperature(BaseModel): +class PredictonTemperature(BaseModel): timestamp: Optional[datetime] indoor_temp: Optional[float] + outdoor_temp: Optional[float] + # class Action(BaseModel):