2023-01-10 17:24:26 -05:00
|
|
|
"""
|
|
|
|
Main
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2021 Project Author name guillermo.gutierrezmorote@concordia.ca
|
|
|
|
Project Collaborator name peteryefi@gmail.com
|
|
|
|
"""
|
|
|
|
|
2023-01-23 12:29:41 -05:00
|
|
|
import datetime
|
|
|
|
|
2023-01-10 17:24:26 -05:00
|
|
|
import flask
|
2023-01-16 15:31:02 -05:00
|
|
|
import yaml
|
2023-08-03 09:53:26 -04:00
|
|
|
from pathlib import Path
|
2023-01-25 04:54:49 -05:00
|
|
|
from flasgger import LazyJSONEncoder, Swagger
|
|
|
|
from flask import Response
|
2023-01-10 17:24:26 -05:00
|
|
|
from flask_restful import Api
|
2023-02-22 23:14:41 -05:00
|
|
|
import threading
|
2023-01-23 12:29:41 -05:00
|
|
|
|
|
|
|
import hub_api.helpers.session_helper as sh
|
2023-03-10 10:18:27 -05:00
|
|
|
from hub_api.control.session import SessionStart, SessionEnd, KeepSessionAlive
|
|
|
|
from hub_api.control.uptime import Uptime
|
2023-07-21 11:48:00 -04:00
|
|
|
from hub_api.persistence.retrofit_results import RetrofitResults
|
2023-07-21 11:43:52 -04:00
|
|
|
from hub_api.workflow.insel_montly_energy_balance import InselMonthlyEnergyBalance
|
|
|
|
from hub_api.workflow.costs import Costs
|
|
|
|
from hub_api.workflow.energy_plus import EnergyPlus
|
|
|
|
from hub_api.energy_plus.idf_generator import IdfGenerator
|
|
|
|
|
2023-01-10 17:24:26 -05:00
|
|
|
|
2023-01-23 12:29:41 -05:00
|
|
|
sh.begin_time = datetime.datetime.now()
|
|
|
|
app = flask.Flask('cerc_api')
|
|
|
|
app.json_provider_class = LazyJSONEncoder
|
2023-01-10 17:24:26 -05:00
|
|
|
api = Api(app)
|
|
|
|
|
|
|
|
api.add_resource(Uptime, '/v1.4/uptime')
|
2023-01-23 12:29:41 -05:00
|
|
|
|
|
|
|
# Session
|
2023-01-10 17:24:26 -05:00
|
|
|
api.add_resource(SessionStart, '/v1.4/session/start')
|
|
|
|
api.add_resource(SessionEnd, '/v1.4/session/end')
|
2023-07-20 20:15:24 -04:00
|
|
|
api.add_resource(KeepSessionAlive, '/v1.4/session/keep-alive')
|
2023-01-30 05:49:02 -05:00
|
|
|
|
2023-07-21 11:48:00 -04:00
|
|
|
# persistence
|
|
|
|
api.add_resource(RetrofitResults, '/v1.4/persistence/retrofit-results')
|
2023-07-21 11:43:52 -04:00
|
|
|
|
|
|
|
# energy plus
|
|
|
|
api.add_resource(IdfGenerator, '/v1.4/energy-plus/idf-generator')
|
|
|
|
|
|
|
|
# workflows
|
|
|
|
api.add_resource(Costs, '/v1.4/workflow/costs')
|
|
|
|
api.add_resource(EnergyPlus, '/v1.4/workflow/energy-plus')
|
2023-09-26 16:44:42 -04:00
|
|
|
api.add_resource(InselMonthlyEnergyBalance,
|
|
|
|
'/v1.4/workflow/insel-monthly-energy-balance')
|
2023-02-27 17:50:53 -05:00
|
|
|
|
2023-09-26 16:44:42 -04:00
|
|
|
yml_path = Path('./hub/docs/openapi-specs.yml').resolve()
|
2023-04-12 15:26:56 -04:00
|
|
|
|
2023-08-03 09:53:26 -04:00
|
|
|
with open(yml_path, "r") as stream:
|
2023-09-26 16:44:42 -04:00
|
|
|
swagger_config = {
|
|
|
|
"headers": [],
|
|
|
|
"specs": [
|
|
|
|
{
|
|
|
|
"endpoint": '/api/apispec',
|
|
|
|
"route": '/api/apispec/apispec.json',
|
|
|
|
"rule_filter": lambda rule: True, # all in
|
|
|
|
"model_filter": lambda tag: True, # all in
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"static_url_path": "/api/static",
|
|
|
|
"specs_route": "/api/api-docs/",
|
|
|
|
"openapi": "3.0.0"
|
|
|
|
}
|
|
|
|
try:
|
|
|
|
Swagger(app, template=yaml.safe_load(stream), config=swagger_config)
|
|
|
|
except yaml.YAMLError as exc:
|
|
|
|
print(f'error: {exc}')
|
2023-01-30 05:49:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def home():
|
2023-09-26 16:44:42 -04:00
|
|
|
return Response(headers={'Access-Control-Allow-Origin': '*'})
|
2023-01-30 05:49:02 -05:00
|
|
|
|
2023-07-21 11:43:52 -04:00
|
|
|
|
2023-02-27 17:50:53 -05:00
|
|
|
sh.debug_mode = True
|
|
|
|
|
2023-09-26 16:44:42 -04:00
|
|
|
threading.Thread(target=sh.expired_sessions_collector,
|
|
|
|
daemon=True, args="5").start()
|
2023-02-27 17:50:53 -05:00
|
|
|
app.run(port=15789, host="0.0.0.0", debug=sh.debug_mode)
|