lca_carbon_api/app.py
2024-10-10 11:49:11 -04:00

50 lines
1.6 KiB
Python

"""
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)