-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
95 lines (68 loc) · 2.13 KB
/
main.py
File metadata and controls
95 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 28 18:48:33 2021
@author: rottschaefer
backend app for capacity provider
"""
from __future__ import annotations
import json
import logging
import os
from flask import Flask, redirect
from oscp import createBlueprint
from oscp.RegistrationManager import RegistrationDictMan
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger("oscp")
class FlexibilityManager(object):
def __init__(self):
self.endpoints = []
class CapacityProviderManager:
def __init__(self):
self.stuff = []
class FlexibilityProviderManager:
def __init__(self):
self.stuff = []
class CapacityOptimizerManager:
def __init__(self):
self.stuff = []
class EnergyProviderManager:
def __init__(self):
pass
app = Flask(__name__)
@app.route("/", methods=["POST", "GET"])
def home():
return redirect("/oscp/ui")
# inject dependencies here
cpm = CapacityProviderManager()
com = CapacityOptimizerManager()
fpm = FlexibilityProviderManager()
epm = EnergyProviderManager()
HOST_URL = os.getenv("HOST_URL", "http://localhost:5000")
version_urls = [{"version": "2.0", "base_url": HOST_URL + "/oscp/fp/2.0"}]
regman = RegistrationDictMan(version_urls)
injected_objects = {
"energyprovider": epm,
"capacityprovider": cpm,
"capacityoptimizer": com,
"flexibilityprovider": fpm,
"registrationmanager": regman,
}
config = "oscp.json"
if os.path.exists(config):
log.info(f"reading config file {config}")
with open(config, "r") as f:
conf = json.load(f)
regman._updateService(conf["token"], None, None)
else:
log.info(f"config file {config} does not exist")
# the injected_objects are used to route requests from the namespace to the
# logic containing classes like ForecastManager
blueprint = createBlueprint(injected_objects, actor="cp")
# using a blueprint allows us to initialize everything without an app context
# this is cleaner, as the oscp module never needs access to the actual Flask server
app.register_blueprint(blueprint)
if __name__ == "__main__":
regman.start()
app.run()
regman.stop()