mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Setting up energy assessments extraction process
This commit is contained in:
parent
6c8beed5e5
commit
a46c0eed39
3 changed files with 75 additions and 0 deletions
|
|
@ -33,6 +33,9 @@ class Settings(BaseSettings):
|
|||
HEATING_KWH_PREDICTIONS_BUCKET: str
|
||||
HOTWATER_KWH_PREDICTIONS_BUCKET: str
|
||||
|
||||
# Other S3 buckts
|
||||
ENERGY_ASSESSMENTS_BUCKET: str
|
||||
|
||||
class Config:
|
||||
env_file = "backend/.env"
|
||||
|
||||
|
|
|
|||
65
backend/app/energy_assessments/router.py
Normal file
65
backend/app/energy_assessments/router.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
from fastapi import APIRouter, Depends
|
||||
from starlette.responses import Response
|
||||
|
||||
from backend.app.db.connection import db_engine
|
||||
|
||||
from backend.app.config import get_settings
|
||||
from backend.app.dependencies import validate_token
|
||||
from backend.app.energy_assessments.schemas import EnergyAssessmentUploadPayload
|
||||
|
||||
from sqlalchemy.exc import IntegrityError, OperationalError
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from utils.logger import setup_logger
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/energy-assessments",
|
||||
tags=["energy-assessments"],
|
||||
dependencies=[Depends(validate_token)],
|
||||
responses={404: {"description": "Not found"}}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/upload")
|
||||
async def upload(body: EnergyAssessmentUploadPayload):
|
||||
"""
|
||||
Given a location in S3, this service will retrieve the data in s3 and perform the following:
|
||||
1) Extract the data and store it to the data
|
||||
2) Extract the links to other artefacts collected during the energy assessment, such as EPRs, floor plans and
|
||||
condition reports
|
||||
|
||||
This will allow us to do the following:
|
||||
1) Present the findings of the energy assessment to the client
|
||||
2) Allow the end use to download the artefacts collected during the energy assessment
|
||||
|
||||
Eventually, we will this service to collect the key documents from the service where they're uploaded
|
||||
(e.g. Onedrive) and store them to S3, but for the moment, this is sufficient
|
||||
"""
|
||||
|
||||
logger.info("Connecting to db")
|
||||
session = sessionmaker(bind=db_engine)()
|
||||
|
||||
try:
|
||||
logger.info("Uploading energy assessment data")
|
||||
except IntegrityError:
|
||||
logger.error("Database integrity error occurred", exc_info=True)
|
||||
session.rollback()
|
||||
return Response(status_code=500, content="Database integrity error.")
|
||||
except OperationalError:
|
||||
logger.error("Database operational error occurred", exc_info=True)
|
||||
session.rollback()
|
||||
return Response(status_code=500, content="Database operational error.")
|
||||
except ValueError:
|
||||
logger.error("Value error - possibly due to malformed data", exc_info=True)
|
||||
session.rollback()
|
||||
return Response(status_code=400, content="Bad request: malformed data.")
|
||||
except Exception as e: # General exception handling
|
||||
logger.error(f"An error occurred: {e}")
|
||||
session.rollback()
|
||||
return Response(status_code=500, content="An unexpected error occurred.")
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
return Response(status_code=200)
|
||||
7
backend/app/energy_assessments/schemas.py
Normal file
7
backend/app/energy_assessments/schemas.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class EnergyAssessmentUploadPayload(BaseModel):
|
||||
portfolio_id: int
|
||||
# This is the s3 location, where the informaton collected during the energy assessment is stored
|
||||
s3_filepath: str
|
||||
Loading…
Add table
Reference in a new issue