First commit for ep and meb workflows

This commit is contained in:
Guille Gutierrez 2024-04-25 07:19:21 +02:00
parent 8cfd6ebe82
commit 7753d69a54
3 changed files with 30 additions and 1 deletions

View File

@ -23,11 +23,13 @@ from hub_api.workflow.insel_montly_energy_balance import InselMonthlyEnergyBalan
from hub_api.workflow.costs import Costs
from hub_api.workflow.energy_plus import EnergyPlus
from hub_api.energy_plus.idf_generator import IdfGenerator
from hub_api.config import Config
sh.begin_time = datetime.datetime.now()
app = flask.Flask('cerc_api')
app.json_provider_class = LazyJSONEncoder
app.config['MAX_CONTENT_LENGTH'] = Config.max_file_size
api = Api(app)
api.add_resource(Uptime, '/v1.4/uptime')

View File

@ -21,6 +21,7 @@ class Config:
environment = 'PROD'
database_name = 'montreal_retrofit'
self._max_file_size = 10 * 1024 * 1024 # 10 MB
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
self._repository = Repository(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
@ -37,3 +38,7 @@ class Config:
@property
def energy_systems_catalog(self):
return self._energy_systems_catalog
@property
def max_file_size(self):
return self._max_file_size

View File

@ -1,14 +1,36 @@
import json
from pathlib import Path
from flask_restful import Resource
from flask import Response, request
from hub_api.config import Config
from hub_api.helpers.session_helper import refresh_session
class InselMonthlyEnergyBalance(Resource, Config):
def __init__(self):
super().__init__()
self._extensions = ['geojson', 'citygml']
def _allowed_extensions(self, filename):
self._file_extension = Path(filename).suffix
return self._file_extension in self._extensions
def _geojson(self, geojson_file):
return
def post(self):
"""
API call for performing the monthly energy balance workflow
"""
raise NotImplementedError()
session_id = request.headers.get('session-id', None)
token = request.headers.get('token', None)
application_uuid = request.headers.get('application-uuid', None)
_session = refresh_session(session_id, token, application_uuid)
if _session is None:
return Response(json.dumps({'error': 'unauthorized'}), status=403)
else:
geometry_file = request.files['geometry_file']
if not self._allowed_extensions(geometry_file):
return Response(json.dumps({'error': 'Unsupported media type'}), status=415, headers=token)