From 1a38c83deeeeb0e94e2e2c7358cf715befa6850a Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 28 Jul 2023 14:54:30 -0400 Subject: [PATCH] Redefine api structure Add future methods Update documentation --- hub_api/docs/openapi-specs.yml | 364 +++++++++++++++++------- hub_api/persistence/retrofit_results.py | 21 +- 2 files changed, 286 insertions(+), 99 deletions(-) diff --git a/hub_api/docs/openapi-specs.yml b/hub_api/docs/openapi-specs.yml index 692c55a..40e1929 100644 --- a/hub_api/docs/openapi-specs.yml +++ b/hub_api/docs/openapi-specs.yml @@ -157,10 +157,10 @@ paths: required: - cities properties: - cities: + scenarios: type: object - description: Cities list - example: { "cities": [{ "Montreal current status": ["149_part_0_zone_0", "1_part_0_zone_0"]}]} + description: List of scenarios and buildings + example: { "scenarios": [{ "current status": ["01002777"]}]} tags: - Persistence retrofit results summary: Retrieve the monthly energy balance results for the given persistence in the given cities @@ -179,6 +179,12 @@ paths: format: uuid description: Token expected in next operation header example: '77e1c83b-7bb0-437b-bc50-a7a58e5660ac' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/bad-request' '403': description: Unauthorized content: @@ -276,6 +282,12 @@ components: error: type: string example: 'unauthorized' + bad-request: + type: object + properties: + error: + type: string + example: 'Bad request' succeed: type: object properties: @@ -300,106 +312,268 @@ components: results: type: object example: { - "result":"succeed", - "results":{ - "Montreal current status":[ - { - "insel meb":[ + "current status": + [ + { + "insel meb": [ { - "monthly_cooling":{ - "0":381853.821, - "1":484038.818, - "2":944923.8890000001, - "3":1465614.62, - "4":2816751.71, - "5":4673754.880000001, - "6":5804651.86, - "7":5113784.18, - "8":2464006.1, - "9":1113856.5699999998, - "10":588973.45, - "11":384227.386 - } + "monthly_cooling_peak_load": [ + 0, + 0, + 0, + 6584.458113320823, + 62924.37128642762, + 57887.14012015144, + 70751.92355485224, + 62984.101439783015, + 48250.59450887724, + 0, + 0, + 0 + ] }, { - "yearly_cooling":{ - "0":26236437.283999998 - } + "yearly_cooling_peak_load": [ + 70751.92355485224 + ] }, { - "monthly_heating":{ - "0":23752326.2, - "1":20536490.2, - "2":16533607.4, - "3":8818033.2, - "4":4036963.87, - "5":915646.973, - "6":247277.222, - "7":393324.463, - "8":3161278.32, - "9":8418375.98, - "10":13028175.8, - "11":21456785.2 - } + "monthly_heating_peak_load": [ + 262098.65318553636, + 265821.7159266224, + 217944.00326807727, + 155252.5244818504, + 109483.75948860023, + 84631.2513243329, + 71629.71397081681, + 77627.25028728181, + 112508.45055758546, + 143365.05468737005, + 178295.01091663004, + 226377.81783654366 + ] }, { - "yearly_heating":{ - "0":121298284.828 - } + "yearly_heating_peak_load": [ + 265821.7159266224 + ] + }, + { + "monthly_cooling_demand": [ + 295005.341, + 404348.816, + 809382.8119999999, + 1423909.9100000001, + 3407862.3, + 7343880.86, + 10326290.0, + 9243987.3, + 3481350.34, + 1266403.6900000002, + 563368.2250000001, + 299075.714 + ] + }, + { + "yearly_cooling_demand": [ + 38864865.308000006 + ] + }, + { + "monthly_heating_demand": [ + 53757554.7, + 46479308.599999994, + 37117226.6, + 18778937.5, + 7274898.4399999995, + 758257.8119999999, + 22337.890600000002, + 94370.8496, + 5050939.94, + 17157021.5, + 28129459.0, + 48168429.7 + ] + }, + { + "yearly_heating_demand": [ + 262788742.53219998 + ] + }, + { + "monthly_lighting_electrical_demand": [ + 5833171.347707521, + 5262061.78651678, + 5833171.347707521, + 5625727.964494741, + 5833171.347707521, + 5642801.493977274, + 5816097.818224987, + 5833171.347707521, + 5625727.964494741, + 5833171.347707521, + 5642801.493977274, + 5816097.818224987 + ] + }, + { + "yearly_lighting_electrical_demand": [ + 68597173.07844839 + ] + }, + { + "monthly_appliances_electrical_demand": [ + 1080216.9162421336, + 974455.8863919963, + 1080216.9162421334, + 1041801.4749064334, + 1080216.9162421334, + 1044963.239625421, + 1077055.1515231456, + 1080216.9162421334, + 1041801.4749064333, + 1080216.9162421336, + 1044963.239625421, + 1077055.1515231456 + ] + }, + { + "yearly_appliances_electrical_demand": [ + 12703180.199712664 + ] + }, + { + "monthly_domestic_hot_water_heat_demand": [ + 456825.0843755854, + 414141.3604753232, + 468484.2621310478, + 459801.92885964504, + 473764.6342500718, + 458315.9343261062, + 471613.41847213014, + 470564.79267605464, + 461648.6669837665, + 474210.31698864425, + 456916.48282534967, + 464726.15139262035 + ] + }, + { + "yearly_domestic_hot_water_heat_demand": [ + 5531013.0337563455 + ] + }, + { + "monthly_heating_consumption": [ + 63244182.00000001, + 54681539.529411756, + 43667325.41176471, + 22092867.647058826, + 8558704.047058823, + 892068.014117647, + 26279.87129411765, + 111024.52894117647, + 5942282.282352942, + 20184731.17647059, + 33093481.17647059, + 56668740.823529415 + ] + }, + { + "yearly_heating_consumption": [ + 309163226.5084706 + ] + }, + { + "monthly_cooling_consumption": [ + 91332.92291021673, + 125185.3919504644, + 250582.91393188853, + 440838.98142414866, + 1055065.7275541795, + 2273647.3250773996, + 3196993.808049536, + 2861915.5727554183, + 1077817.4427244582, + 392075.4458204335, + 174417.40712074307, + 92593.10030959752 + ] + }, + { + "yearly_cooling_consumption": [ + 12032466.039628485 + ] + }, + { + "monthly_domestic_hot_water_consumption": [ + 537441.2757359828, + 487225.1299709685, + 551157.9554482915, + 540943.4457172295, + 557370.157941261, + 539195.2168542426, + 554839.3158495649, + 553605.6384424173, + 543116.0788044311, + 557894.4905748756, + 537548.8033239408, + 546736.6486972005 + ] + }, + { + "yearly_domestic_hot_water_consumption": [ + 6507074.157360407 + ] + }, + { + "monthly_distribution_systems_electrical_consumption": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ] + }, + { + "yearly_distribution_systems_electrical_consumption": [ + 0.0 + ] + }, + { + "monthly_on_site_electrical_production": [ + 1877568.0052112115, + 2407257.798870815, + 3166036.3496084926, + 2775127.9773544166, + 3179310.676411243, + 3229758.071462234, + 3323472.052358032, + 3331301.907608147, + 3009020.446469887, + 2133712.041565227, + 1511572.9397916023, + 1439817.2575820587 + ] + }, + { + "yearly_on_site_electrical_production": [ + 31185356.31301905 + ] } - ], - "building":"149_part_0_zone_0" - }, - { - "insel meb":[ - { - "monthly_cooling":{ - "0":783396.606, - "1":1044300.2899999999, - "2":1839283.69, - "3":2594479.49, - "4":4809622.07, - "5":7720497.56, - "6":9451286.13, - "7":8666059.57, - "8":4576645.510000001, - "9":2222742.19, - "10":1180251.0999999999, - "11":759023.5599999999 - } - }, - { - "yearly_cooling":{ - "0":45647587.766 - } - }, - { - "monthly_heating":{ - "0":33584593.800000004, - "1":28801277.3, - "2":23248582.0, - "3":12622207.0, - "4":5935129.39, - "5":1533334.23, - "6":541973.145, - "7":763742.676, - "8":4608120.61, - "9":11964252.9, - "10":18499837.9, - "11":30418062.5 - } - }, - { - "yearly_heating":{ - "0":172521113.451 - } - } - ], - "building":"1_part_0_zone_0" - } - ] - } - } + ], + "building": "01002777" + } + ] + } + not-implemented-error: type: object properties: diff --git a/hub_api/persistence/retrofit_results.py b/hub_api/persistence/retrofit_results.py index 2c5521b..d00bb47 100644 --- a/hub_api/persistence/retrofit_results.py +++ b/hub_api/persistence/retrofit_results.py @@ -24,17 +24,30 @@ class RetrofitResults(Resource, Config): token = {'token': _session['token']} application_id = session(session_id)['application_id'] user_id = session(session_id)['user_id'] - payload = request.get_json() + if 'scenarios' not in payload: + return Response(json.dumps({'error': 'Bad request'}), status=400, headers=token) + + # retrieve the buildings info + buildings = [] + buildings_info = [] + for scenario in payload['scenarios']: + key = next(iter(scenario)) + for name in scenario[key]: + if name not in buildings: + buildings.append(name) + for building in buildings: + buildings_info.append(self.database.building_info(building, user_id, application_id, scenario)) + + print(buildings_info) results = self.database.results(user_id, application_id, payload) if results == {}: # no data found for the given parameters return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token) # deserialize the response to return pure json - city_name = next(iter(results)) - for building_results in results[city_name]: + scenario = next(iter(results)) + for building_results in results[scenario]: values = [] - print(building_results) for value in building_results['insel meb']: key = next(iter(value)) values.append({key: json.loads(str(value[key]))})