Work on API call for accessing MEB buildings
This commit is contained in:
parent
999699c402
commit
e2cb78842f
|
@ -17,7 +17,7 @@ import threading
|
|||
import hub_api.helpers.session_helper as sh
|
||||
from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive
|
||||
from hub_api.uptime import Uptime
|
||||
from hub_api.buildings import GetBuildings
|
||||
from hub_api.buildings import GetMEB
|
||||
|
||||
|
||||
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')
|
||||
|
||||
# Buildings
|
||||
api.add_resource(GetBuildings, '/v1.4/buildings')
|
||||
api.add_resource(GetMEB, '/v1.4/buildings/meb')
|
||||
|
||||
with open("hub_api/docs/openapi-specs.yml", "r") as stream:
|
||||
swagger_config = {
|
||||
|
|
|
@ -5,11 +5,11 @@ from flask_restful import Resource
|
|||
from hub_api.helpers.session_helper import active_session, refresh_session
|
||||
from hub_api.config import Config
|
||||
|
||||
class GetBuildings(Resource, Config):
|
||||
class GetMEB(Resource, Config):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def get(self):
|
||||
def post(self):
|
||||
'''
|
||||
API call for requesting a specified list of enriched buildings
|
||||
'''
|
||||
|
@ -18,14 +18,18 @@ class GetBuildings(Resource, Config):
|
|||
application_uuid = request.headers.get('application_uuid', None)
|
||||
|
||||
if(active_session(session_id, token, application_uuid)):
|
||||
refresh_session(session_id)
|
||||
refresh_session(session_id, token, application_uuid)
|
||||
payload = request.get_json()
|
||||
buildings = {}
|
||||
|
||||
building_ids = request.get_json()
|
||||
buildings = self.export_db_factory.get_buildings_by_id(building_ids)
|
||||
for city in payload['cities']:
|
||||
buildings[city] = {}
|
||||
for building in payload['cities'][city]:
|
||||
buildings[city][building] = self.export_db_factory.building_info(building, city)
|
||||
|
||||
if(bool(buildings)):
|
||||
return(Response(json.dumps(buildings), status=200))
|
||||
|
||||
return Response(json.dumps({'result': 'buildings not found'}), status=204)
|
||||
#TODO: finish formating buildings to match swagger documentation
|
||||
# and change export_db_factory.building_info to use MEB database
|
||||
# call when ready
|
||||
|
||||
return Response(json.dumps({'result': 'succeed', 'results': buildings}), status=200)
|
||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
|
@ -140,19 +140,28 @@ paths:
|
|||
schema:
|
||||
$ref: '#/components/schemas/unauthorized'
|
||||
/v1.4/buildings/meb:
|
||||
get:
|
||||
post:
|
||||
security:
|
||||
- session_id: [ ]
|
||||
- token: [ ]
|
||||
- application_uuid: [ ]
|
||||
parameters:
|
||||
- in: body
|
||||
name: data
|
||||
schema:
|
||||
type: string
|
||||
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.
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
cities:
|
||||
type: object
|
||||
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:
|
||||
- Buildings monthly energy balance meb
|
||||
summary: Retrieve the monthly energy balance results for the given buildings in the given cities
|
||||
|
@ -220,6 +229,19 @@ components:
|
|||
cities:
|
||||
type: array
|
||||
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:
|
||||
type: object
|
||||
properties:
|
||||
|
|
Loading…
Reference in New Issue
Block a user