Compare commits
2 Commits
main
...
anh/api-re
Author | SHA1 | Date | |
---|---|---|---|
|
e34fc520bd | ||
|
fde03662be |
46
bootstrap.py
46
bootstrap.py
|
@ -46,37 +46,39 @@ api.add_resource(IdfGenerator, '/v1.4/energy-plus/idf-generator')
|
||||||
# workflows
|
# workflows
|
||||||
api.add_resource(Costs, '/v1.4/workflow/costs')
|
api.add_resource(Costs, '/v1.4/workflow/costs')
|
||||||
api.add_resource(EnergyPlus, '/v1.4/workflow/energy-plus')
|
api.add_resource(EnergyPlus, '/v1.4/workflow/energy-plus')
|
||||||
api.add_resource(InselMonthlyEnergyBalance, '/v1.4/workflow/insel-monthly-energy-balance')
|
api.add_resource(InselMonthlyEnergyBalance,
|
||||||
|
'/v1.4/workflow/insel-monthly-energy-balance')
|
||||||
|
|
||||||
yml_path = Path('./docs/openapi-specs.yml').resolve()
|
yml_path = Path('./hub/docs/openapi-specs.yml').resolve()
|
||||||
|
|
||||||
with open(yml_path, "r") as stream:
|
with open(yml_path, "r") as stream:
|
||||||
swagger_config = {
|
swagger_config = {
|
||||||
"headers": [],
|
"headers": [],
|
||||||
"specs": [
|
"specs": [
|
||||||
{
|
{
|
||||||
"endpoint": '/api/apispec',
|
"endpoint": '/api/apispec',
|
||||||
"route": '/api/apispec/apispec.json',
|
"route": '/api/apispec/apispec.json',
|
||||||
"rule_filter": lambda rule: True, # all in
|
"rule_filter": lambda rule: True, # all in
|
||||||
"model_filter": lambda tag: True, # all in
|
"model_filter": lambda tag: True, # all in
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"static_url_path": "/api/static",
|
"static_url_path": "/api/static",
|
||||||
"specs_route": "/api/api-docs/",
|
"specs_route": "/api/api-docs/",
|
||||||
"openapi": "3.0.0"
|
"openapi": "3.0.0"
|
||||||
}
|
}
|
||||||
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(f'error: {exc}')
|
print(f'error: {exc}')
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
return Response(headers={'Access-Control-Allow-Origin': '*'})
|
return Response(headers={'Access-Control-Allow-Origin': '*'})
|
||||||
|
|
||||||
|
|
||||||
sh.debug_mode = True
|
sh.debug_mode = True
|
||||||
|
|
||||||
threading.Thread(target=sh.expired_sessions_collector, daemon=True, args="5").start()
|
threading.Thread(target=sh.expired_sessions_collector,
|
||||||
|
daemon=True, args="5").start()
|
||||||
app.run(port=15789, host="0.0.0.0", debug=sh.debug_mode)
|
app.run(port=15789, host="0.0.0.0", debug=sh.debug_mode)
|
||||||
|
|
BIN
hub_api/control/__pycache__/session.cpython-39.pyc
Normal file
BIN
hub_api/control/__pycache__/session.cpython-39.pyc
Normal file
Binary file not shown.
BIN
hub_api/control/__pycache__/uptime.cpython-39.pyc
Normal file
BIN
hub_api/control/__pycache__/uptime.cpython-39.pyc
Normal file
Binary file not shown.
BIN
hub_api/helpers/__pycache__/session_helper.cpython-39.pyc
Normal file
BIN
hub_api/helpers/__pycache__/session_helper.cpython-39.pyc
Normal file
Binary file not shown.
BIN
hub_api/persistence/__pycache__/retrofit_results.cpython-39.pyc
Normal file
BIN
hub_api/persistence/__pycache__/retrofit_results.cpython-39.pyc
Normal file
Binary file not shown.
|
@ -2,13 +2,22 @@ from flask_restful import Resource
|
||||||
|
|
||||||
from hub_api.config import Config
|
from hub_api.config import Config
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
config_json_path = "../configs/config.json"
|
||||||
|
|
||||||
|
with open(config_json_path, "r") as stream:
|
||||||
|
config = json.load(stream)
|
||||||
|
if config:
|
||||||
|
print(f'{json.dumps(config, indent=2)}')
|
||||||
|
|
||||||
|
|
||||||
class Costs(Resource, Config):
|
class Costs(Resource, Config):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
"""
|
"""
|
||||||
API call for performing the cost workflow
|
API call for performing the cost workflow
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
23
microservice.py
Normal file
23
microservice.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
import flask
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from flasgger import LazyJSONEncoder, Swagger
|
||||||
|
from flask import Response
|
||||||
|
from flask_restful import Api
|
||||||
|
import threading
|
||||||
|
|
||||||
|
app = flask.Flask('cerc_api')
|
||||||
|
app.json_provider_class = LazyJSONEncoder
|
||||||
|
api = Api(app)
|
||||||
|
|
||||||
|
# Parse and register services.json
|
||||||
|
|
||||||
|
services_json_path = "./configs/services.json"
|
||||||
|
|
||||||
|
for service in json.load(open(services_json_path)):
|
||||||
|
print(f"service: {service}")
|
||||||
|
api.add_resource(service["name"], service["endpoint"])
|
||||||
|
|
||||||
|
app.run(port=5000, debug=True, host="0.0.0.0")
|
0
microservice/__init__.py
Normal file
0
microservice/__init__.py
Normal file
9
microservice/services.json
Normal file
9
microservice/services.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"apiVersion": "v1.4.0",
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"name": "Costs",
|
||||||
|
"endpoint": "workflow/costs"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
16
microservice/workflow/costs.py
Normal file
16
microservice/workflow/costs.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
from flask_restful import Resource
|
||||||
|
|
||||||
|
# from hub_api.config import Config
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class Costs(Resource):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def post(self):
|
||||||
|
"""
|
||||||
|
API call for performing the cost workflow
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
|
@ -27,4 +27,5 @@ flasgger
|
||||||
cerc-hub
|
cerc-hub
|
||||||
python-dotenv
|
python-dotenv
|
||||||
mapbox_earcut
|
mapbox_earcut
|
||||||
cerc-costs
|
cerc-costs
|
||||||
|
cerc-co2-emission
|
Loading…
Reference in New Issue
Block a user