Small adjustments for meb

This commit is contained in:
Guille Gutierrez 2023-03-10 10:15:20 -05:00
parent e2cb78842f
commit fa06b571f8
3 changed files with 19 additions and 41 deletions

View File

@ -17,7 +17,7 @@ import threading
import hub_api.helpers.session_helper as sh import hub_api.helpers.session_helper as sh
from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive
from hub_api.uptime import Uptime from hub_api.uptime import Uptime
from hub_api.buildings import GetMEB from hub_api.buildings.meb import Meb
sh.begin_time = datetime.datetime.now() sh.begin_time = datetime.datetime.now()
@ -33,7 +33,7 @@ api.add_resource(SessionEnd, '/v1.4/session/end')
api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive') api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive')
# Buildings # Buildings
api.add_resource(GetMEB, '/v1.4/buildings/meb') api.add_resource(Meb, '/v1.4/buildings/meb')
with open("hub_api/docs/openapi-specs.yml", "r") as stream: with open("hub_api/docs/openapi-specs.yml", "r") as stream:
swagger_config = { swagger_config = {
@ -53,7 +53,7 @@ with open("hub_api/docs/openapi-specs.yml", "r") as stream:
try: try:
Swagger(app, template=yaml.safe_load(stream), config=swagger_config) Swagger(app, template=yaml.safe_load(stream), config=swagger_config)
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(f'error: {exc}')
@app.route("/") @app.route("/")

View File

@ -5,19 +5,19 @@ from flask_restful import Resource
from hub_api.helpers.session_helper import active_session, refresh_session from hub_api.helpers.session_helper import active_session, refresh_session
from hub_api.config import Config from hub_api.config import Config
class GetMEB(Resource, Config): class Meb(Resource, Config):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
def post(self): def get(self):
''' """
API call for requesting a specified list of enriched buildings API call for requesting a specified list of enriched buildings
''' """
session_id = request.headers.get('session_id', None) session_id = request.headers.get('session_id', None)
token = request.headers.get('token', None) token = request.headers.get('token', None)
application_uuid = request.headers.get('application_uuid', None) application_uuid = request.headers.get('application_uuid', None)
if(active_session(session_id, token, application_uuid)): if active_session(session_id, token, application_uuid):
refresh_session(session_id, token, application_uuid) refresh_session(session_id, token, application_uuid)
payload = request.get_json() payload = request.get_json()
buildings = {} buildings = {}
@ -27,7 +27,7 @@ class GetMEB(Resource, Config):
for building in payload['cities'][city]: for building in payload['cities'][city]:
buildings[city][building] = self.export_db_factory.building_info(building, city) buildings[city][building] = self.export_db_factory.building_info(building, city)
#TODO: finish formating buildings to match swagger documentation # TODO: finish formatting buildings to match swagger documentation
# and change export_db_factory.building_info to use MEB database # and change export_db_factory.building_info to use MEB database
# call when ready # call when ready

View File

@ -140,28 +140,19 @@ paths:
schema: schema:
$ref: '#/components/schemas/unauthorized' $ref: '#/components/schemas/unauthorized'
/v1.4/buildings/meb: /v1.4/buildings/meb:
post: get:
security: security:
- session_id: [ ] - session_id: [ ]
- token: [ ] - token: [ ]
- application_uuid: [ ] - application_uuid: [ ]
requestBody: parameters:
content: - in: body
application/json: name: data
schema: schema:
type: object type: string
properties: example: [{"city_1" :["building_1", "building_2"]}, {"city_2" :["building_3", "building_8"]}]
cities: required: true
type: object description: Json containing the city name and the buildings whose monthly energy balance is requested.
example: {"city_1" :["building_1", "building_2"], "city_2" :["building_3", "building_8"]}
# schema:
# ref: '#components/schemas/buildingsArray'
# payload:
# type: object
# example: {"city_1" :["building_1", "building_2"], "city_2" :["building_3", "building_8"]}
# required: true
# description: Json containing the city name and the buildings whose monthly energy balance is requested.
tags: tags:
- Buildings monthly energy balance meb - Buildings monthly energy balance meb
summary: Retrieve the monthly energy balance results for the given buildings in the given cities summary: Retrieve the monthly energy balance results for the given buildings in the given cities
@ -229,19 +220,6 @@ components:
cities: cities:
type: array type: array
example: [{'name': 'city 1', 'geometric_level_of_detail': '1'}, {'name': 'city 2', 'geometric_level_of_detail': '1'}] example: [{'name': 'city 1', 'geometric_level_of_detail': '1'}, {'name': 'city 2', 'geometric_level_of_detail': '1'}]
buildingsArray:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/buildings'
buildings:
type: object
properties:
city_id:
type: string
example: 'city_id1'
meb: meb:
type: object type: object
properties: properties: