Compare commits

...

2 Commits

Author SHA1 Message Date
Anh H Nguyen
e34fc520bd
WIP poc 2023-09-26 18:55:46 -04:00
Anh H Nguyen
fde03662be
Add pip package, fix docs path 2023-09-26 16:44:42 -04:00
11 changed files with 90 additions and 30 deletions

View File

@ -46,9 +46,10 @@ 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')
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:
swagger_config = {
@ -78,5 +79,6 @@ def home():
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)

Binary file not shown.

Binary file not shown.

View File

@ -2,6 +2,15 @@ from flask_restful import Resource
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):
def __init__(self):

23
microservice.py Normal file
View 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
View File

View File

@ -0,0 +1,9 @@
{
"apiVersion": "v1.4.0",
"services": [
{
"name": "Costs",
"endpoint": "workflow/costs"
}
]
}

View 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()

View File

@ -28,3 +28,4 @@ cerc-hub
python-dotenv
mapbox_earcut
cerc-costs
cerc-co2-emission