partial implementation meb workflow in the api
This commit is contained in:
parent
7753d69a54
commit
3f35ce1c2c
|
@ -1,7 +1,11 @@
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
from flask import Response, request
|
from flask import Response, request
|
||||||
|
from hub.helpers.data.montreal_function_to_hub_function import MontrealFunctionToHubFunction
|
||||||
|
from hub.imports.geometry_factory import GeometryFactory
|
||||||
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
from hub_api.config import Config
|
from hub_api.config import Config
|
||||||
from hub_api.helpers.session_helper import refresh_session
|
from hub_api.helpers.session_helper import refresh_session
|
||||||
|
@ -11,12 +15,23 @@ class InselMonthlyEnergyBalance(Resource, Config):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._extensions = ['geojson', 'citygml']
|
self._extensions = ['geojson', 'citygml']
|
||||||
|
self._tmp_path = (Path(__file__).parent / 'tmp').resolve()
|
||||||
|
|
||||||
def _allowed_extensions(self, filename):
|
def _allowed_extensions(self, filename):
|
||||||
self._file_extension = Path(filename).suffix
|
self._file_extension = Path(filename).suffix
|
||||||
return self._file_extension in self._extensions
|
return self._file_extension in self._extensions
|
||||||
|
|
||||||
def _geojson(self, geojson_file):
|
def _geojson(self, file_path):
|
||||||
|
height_field = request.args.get('height_field')
|
||||||
|
year_of_construction_field = request.args.get('year_of_construction_field')
|
||||||
|
function_field = request.args.get('function_field')
|
||||||
|
function_dictionary_name = request.args.get('function_dictionary_name')
|
||||||
|
city = GeometryFactory('geojson',
|
||||||
|
path=file_path,
|
||||||
|
height_field=height_field,
|
||||||
|
year_of_construction_field=year_of_construction_field,
|
||||||
|
function_field=function_field,
|
||||||
|
function_to_hub=MontrealFunctionToHubFunction().dictionary).city
|
||||||
return
|
return
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
|
@ -33,4 +48,9 @@ class InselMonthlyEnergyBalance(Resource, Config):
|
||||||
geometry_file = request.files['geometry_file']
|
geometry_file = request.files['geometry_file']
|
||||||
if not self._allowed_extensions(geometry_file):
|
if not self._allowed_extensions(geometry_file):
|
||||||
return Response(json.dumps({'error': 'Unsupported media type'}), status=415, headers=token)
|
return Response(json.dumps({'error': 'Unsupported media type'}), status=415, headers=token)
|
||||||
|
filename = secure_filename(geometry_file.filename)
|
||||||
|
file_path = os.path.join(self._tmp_path, filename)
|
||||||
|
geometry_file.save(file_path)
|
||||||
|
if self._file_extension == 'geojson':
|
||||||
|
self._geojson(file_path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user