diff --git a/bootstrap.py b/bootstrap.py index 6f11f33..c66de77 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -17,7 +17,12 @@ import threading import hub_api.helpers.session_helper as sh from hub_api.control.session import SessionStart, SessionEnd, KeepSessionAlive from hub_api.control.uptime import Uptime -from hub_api.buildings.retrofit_results import RetrofitResults +from hub_api.monthly_energy_balance.retrofit_results import RetrofitResults +from hub_api.workflow.insel_montly_energy_balance import InselMonthlyEnergyBalance +from hub_api.workflow.costs import Costs +from hub_api.workflow.energy_plus import EnergyPlus +from hub_api.energy_plus.idf_generator import IdfGenerator + sh.begin_time = datetime.datetime.now() app = flask.Flask('cerc_api') @@ -31,8 +36,16 @@ api.add_resource(SessionStart, '/v1.4/session/start') api.add_resource(SessionEnd, '/v1.4/session/end') api.add_resource(KeepSessionAlive, '/v1.4/session/keep-alive') -# Buildings -api.add_resource(RetrofitResults, '/v1.4/buildings/retrofit-results') +# monthly_energy_balance +api.add_resource(RetrofitResults, '/v1.4/monthly-energy-balance/retrofit-results') + +# energy plus +api.add_resource(IdfGenerator, '/v1.4/energy-plus/idf-generator') + +# workflows +api.add_resource(Costs, '/v1.4/workflow/costs') +api.add_resource(EnergyPlus, '/v1.4/workflow/energy-plus') +api.add_resource(InselMonthlyEnergyBalance, '/v1.4/workflow/insel-monthly-energy-balance') with open("hub_api/docs/openapi-specs.yml", "r") as stream: @@ -60,6 +73,7 @@ with open("hub_api/docs/openapi-specs.yml", "r") as stream: def home(): return Response(headers={'Access-Control-Allow-Origin': '*'}) + sh.debug_mode = True threading.Thread(target=sh.expired_sessions_collector, daemon=True, args="5").start() diff --git a/hub_api/control/session.py b/hub_api/control/session.py index 6094c33..3fe5d67 100644 --- a/hub_api/control/session.py +++ b/hub_api/control/session.py @@ -52,6 +52,7 @@ class SessionStart(Resource, Config): return Response(json.dumps({'error': 'unauthorized'}), status=403) + class SessionEnd(Resource): def __init__(self): pass @@ -66,6 +67,7 @@ class SessionEnd(Resource): return Response(json.dumps({'result': 'succeed'}), status=200) return Response(json.dumps({'error': 'unauthorized'}), status=403) + class KeepSessionAlive(Resource): def __init__(self): pass diff --git a/hub_api/docs/openapi-specs.yml b/hub_api/docs/openapi-specs.yml index eee4996..fd37220 100644 --- a/hub_api/docs/openapi-specs.yml +++ b/hub_api/docs/openapi-specs.yml @@ -25,6 +25,7 @@ paths: application/json: schema: $ref: '#/components/schemas/uptime' + /v1.4/session/start: put: parameters: @@ -76,6 +77,7 @@ paths: application/json: schema: $ref: '#/components/schemas/unauthorized' + /v1.4/session/keep-alive: put: security: @@ -108,6 +110,7 @@ paths: application/json: schema: $ref: '#/components/schemas/unauthorized' + /v1.4/session/end: put: security: @@ -140,7 +143,8 @@ paths: application/json: schema: $ref: '#/components/schemas/unauthorized' - /v1.4/buildings/retrofit-results: + + /v1.4/monthly-energy-balance/retrofit-results: post: security: - session_id: [ ] @@ -158,10 +162,10 @@ paths: description: Cities list example: { "cities": [{ "Montreal current status": ["149_part_0_zone_0", "1_part_0_zone_0"]}]} tags: - - Buildings monthly energy balance meb - summary: Retrieve the monthly energy balance results for the given buildings in the given cities - operationId: building_monthly_energy_balance - description: Retrieve the monthly energy balance results for the given buildings in the given cities + - Buildings monthly energy balance monthly_energy_balance + summary: Retrieve the monthly energy balance results for the given monthly_energy_balance in the given cities + operationId: retrofit_results + description: Retrieve the monthly energy balance results for the given monthly_energy_balance in the given cities responses: '200': description: Succeed @@ -181,6 +185,69 @@ paths: application/json: schema: $ref: '#/components/schemas/unauthorized' + + /v1.4/workflow/costs: + post: + security: + - session_id: [ ] + - token: [ ] + - application_uuid: [ ] + parameters: + [ ] + tags: + - Costs workflow + summary: Perform the costs workflow for the given parameters + operationId: costs_workflow + description: Perform the costs workflow for the given parameters + responses: + '500': + description: 'Error: INTERNAL SERVER ERROR' + content: + application/json: + schema: + $ref: '#/components/schemas/not-implemented-error' + + /v1.4/workflow/energy-plus: + post: + security: + - session_id: [ ] + - token: [ ] + - application_uuid: [ ] + parameters: + [ ] + tags: + - Energy+ workflow + summary: Perform the Energy+ workflow for the given parameters + operationId: energy_plus_workflow + description: Perform the Energy+ workflow for the given parameters + responses: + '500': + description: 'Error: INTERNAL SERVER ERROR' + content: + application/json: + schema: + $ref: '#/components/schemas/not-implemented-error' + + /v1.4/workflow/insel-monthly-energy-balance: + post: + security: + - session_id: [ ] + - token: [ ] + - application_uuid: [ ] + parameters: + [ ] + tags: + - INSEL monthly energy balance workflow + summary: Perform the INSEL monthly energy balance for the given parameters + operationId: insel_monthly_energy_balance_workflow + description: Perform the INSEL monthly energy balance for the given parameters + responses: + '500': + description: 'Error: INTERNAL SERVER ERROR' + content: + application/json: + schema: + $ref: '#/components/schemas/not-implemented-error' components: securitySchemes: session_id: @@ -332,4 +399,10 @@ components: } ] } - } \ No newline at end of file + } + not-implemented-error: + type: object + properties: + error: + type: string + example: 'NotImplementedError' \ No newline at end of file diff --git a/hub_api/energy_plus/idf_generator.py b/hub_api/energy_plus/idf_generator.py new file mode 100644 index 0000000..182fcf1 --- /dev/null +++ b/hub_api/energy_plus/idf_generator.py @@ -0,0 +1,14 @@ +from flask_restful import Resource + +from hub_api.config import Config + + +class IdfGenerator(Resource, Config): + def __init__(self): + super().__init__() + + def post(self): + """ + API call generate the IDF file for the input data + """ + raise NotImplementedError() diff --git a/hub_api/buildings/retrofit_results.py b/hub_api/monthly_energy_balance/retrofit_results.py similarity index 86% rename from hub_api/buildings/retrofit_results.py rename to hub_api/monthly_energy_balance/retrofit_results.py index 913d326..9939db3 100644 --- a/hub_api/buildings/retrofit_results.py +++ b/hub_api/monthly_energy_balance/retrofit_results.py @@ -13,7 +13,7 @@ class RetrofitResults(Resource, Config): def post(self): """ - API call for requesting a specified list of enriched buildings + API call for requesting a specified list of enriched monthly_energy_balance """ session_id = request.headers.get('session_id', None) token = request.headers.get('token', None) @@ -34,8 +34,8 @@ class RetrofitResults(Resource, Config): city_name = next(iter(results)) for building_results in results[city_name]: values = [] - for value in building_results['insel meb']: + for value in building_results['insel monthly_energy_balance']: key = next(iter(value)) values.append({key: json.loads(value[key])}) - building_results['insel meb'] = values + building_results['insel monthly_energy_balance'] = values return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token) diff --git a/hub_api/workflow/costs.py b/hub_api/workflow/costs.py new file mode 100644 index 0000000..35b1607 --- /dev/null +++ b/hub_api/workflow/costs.py @@ -0,0 +1,14 @@ +from flask_restful import Resource + +from hub_api.config import Config + + +class Costs(Resource, Config): + def __init__(self): + super().__init__() + + def post(self): + """ + API call for performing the cost workflow + """ + raise NotImplementedError() diff --git a/hub_api/workflow/energy_plus.py b/hub_api/workflow/energy_plus.py new file mode 100644 index 0000000..cdb9b8c --- /dev/null +++ b/hub_api/workflow/energy_plus.py @@ -0,0 +1,14 @@ +from flask_restful import Resource + +from hub_api.config import Config + + +class EnergyPlus(Resource, Config): + def __init__(self): + super().__init__() + + def post(self): + """ + API call for performing the energy plus workflow + """ + raise NotImplementedError() diff --git a/hub_api/workflow/insel_montly_energy_balance.py b/hub_api/workflow/insel_montly_energy_balance.py new file mode 100644 index 0000000..c7564c4 --- /dev/null +++ b/hub_api/workflow/insel_montly_energy_balance.py @@ -0,0 +1,14 @@ +from flask_restful import Resource + +from hub_api.config import Config + + +class InselMonthlyEnergyBalance(Resource, Config): + def __init__(self): + super().__init__() + + def post(self): + """ + API call for performing the monthly energy balance workflow + """ + raise NotImplementedError()