From 86642011143cdb1a1aa31a147a8d5c09bd0ba519 Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Thu, 10 Oct 2024 11:49:11 -0400 Subject: [PATCH] Run the api --- app.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/app.py b/app.py index e69de29..6eb9768 100644 --- a/app.py +++ b/app.py @@ -0,0 +1,49 @@ +""" +app module +Carries out the API +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2024 Concordia CERC group +Code contributors: Alireza Adli alireza.adli@mail.concordia.ca +""" +from flask import request, Flask +from flask_apispec import use_kwargs +from flask_restful import Resource, Api + +from schemas import LCAInputData +from lca_carbon_workflow import LCACarbonWorkflow + + +class AccessCityGeoJson(Resource): + @use_kwargs(LCAInputData) + def post(self, **kwargs): + json_data = request.get_json() + schema = LCAInputData() + errors = schema.validate(json_data) + if errors: + return errors, 400 + lca_carbon = LCACarbonWorkflow(kwargs, + 'nrcan_archetypes.json', + 'nrcan_constructions_cap_3.json') + lca_carbon.calculate_emission() + result = lca_carbon.building_opening_emission, \ + lca_carbon.building_envelope_emission, \ + lca_carbon.building_component_emission, \ + lca_carbon.building_opening_end_of_life_emission, \ + lca_carbon.building_envelope_end_of_life_emission, \ + lca_carbon.building_component_end_of_life_emission + + return {'Building Opening Emissions:': result[0], + 'Building Envelope Emissions:': result[1], + 'Building Component Emissions:': result[2], + 'Building Opening End of Life Emission:': result[3], + 'Building Envelope End of Life Emission:': result[4], + 'Building Component End of Life Emission:': result[5]}, 200 + + +app = Flask(__name__) +api = Api(app) + + +api.add_resource(AccessCityGeoJson, '/result') + +app.run(debug=False)