From 98fc6443f806b2fcacaeed1b76edbb637c1107b1 Mon Sep 17 00:00:00 2001 From: Adrian D'Alessandro Date: Wed, 14 Feb 2024 14:20:50 +0000 Subject: [PATCH] Disentangle develop mode from live_model mode --- README.md | 2 +- app/__init__.py | 1 + app/data.py | 8 ++++---- configure.py | 15 +++++++++++++-- run_live.sh | 2 ++ 5 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 run_live.sh diff --git a/README.md b/README.md index a1e6162..aa59181 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ There is also a requirements to have the OpenVidu server running - see [Deployin 1. Make sure nothing's running 2. Run `bash run_develop.sh` for vis system to run config script and `docker-compose.yml` - - For production, use `run.sh` + - For production, use `run.sh` when using pre-set data, or `run_live.sh` when using the live model. 3. Go to OVE Core at the IP address defined in the `API_URL` environment variable you will now find in `docker-compose.yml` 4. Go to OpenVidu IP address and manually trust website (OPENVIDU_HOST in the `docker-compose.yml`) 5. Log in with username: admin, password: (OPENVIDU_SECRET from docker-compose.yml) diff --git a/app/__init__.py b/app/__init__.py index afa9e4c..4f908ef 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -11,5 +11,6 @@ log = logging.getLogger("api_logger") log.debug("Logging is configured.") +DEVELOP = os.environ.get("DEVELOP", False) LIVE_MODEL = os.environ.get("LIVE_MODEL", False) log.debug("Using Live Model" if LIVE_MODEL else "Using Pre-Set Data") diff --git a/app/data.py b/app/data.py index 6dd3485..6962f63 100644 --- a/app/data.py +++ b/app/data.py @@ -4,7 +4,7 @@ from dash import Input, Output, callback, dcc # type: ignore from dash.exceptions import PreventUpdate # type: ignore -from . import LIVE_MODEL, log +from . import DEVELOP, LIVE_MODEL, log from .datahub_api import get_opal_data, get_wesim_data # , get_dsr_data N_INTERVALS_DATA = 0 @@ -13,15 +13,15 @@ WESIM_START_DATE = "2035-01-22 00:00" # corresponding to hour 0 TODO: check -if LIVE_MODEL: +if DEVELOP: + WESIM = {"df": pd.DataFrame({"Col": [0]})} +else: WESIM = {key: pd.DataFrame(**item) for key, item in get_wesim_data().items()} for df in WESIM.values(): if "Hour" in df.columns: df["Time"] = ( pd.Timestamp(WESIM_START_DATE) + pd.to_timedelta(df["Hour"], unit="h") ).astype(str) -else: - WESIM = {"df": pd.DataFrame({"Col": [0]})} data_interval = dcc.Interval(id="data_interval") diff --git a/configure.py b/configure.py index aa351f7..c71564e 100755 --- a/configure.py +++ b/configure.py @@ -26,7 +26,12 @@ def get_ip_address() -> str: return ip -def generate_docker_compose(template_file: str, ip: str, develop: bool = False) -> None: +def generate_docker_compose( + template_file: str, + ip: str, + develop: bool = False, + live_model: bool = False, +) -> None: """Generate the docker-compose.yml file. Uses a template file and the IP address of the machine. @@ -34,7 +39,9 @@ def generate_docker_compose(template_file: str, ip: str, develop: bool = False) Args: template_file: Path to the template file. ip: IP address of the machine. - develop: Flag for when running in develop mode. + develop: Flag for when running in develop mode (localhost for datahub). + live_model: Flag for when running with a live model. This requires an available + connection to a datahub, either in production or local for develop. Returns: None @@ -81,10 +88,13 @@ def generate_docker_compose(template_file: str, ip: str, develop: bool = False) docker_compose["services"]["dash"]["volumes"] += ["./app:/app"] docker_compose["services"]["dash"]["environment"]["DH_URL"] = "http://127.0.0.1" docker_compose["services"]["dash"]["environment"]["LOG_LEVEL"] = "DEBUG" + docker_compose["services"]["dash"]["environment"]["DEVELOP"] = "true" else: docker_compose["services"]["dash"][ "image" ] = "ghcr.io/imperialcollegelondon/gridlington-vis:latest" + + if live_model: docker_compose["services"]["dash"]["environment"]["LIVE_MODEL"] = "true" # Configure logging for nginx @@ -105,4 +115,5 @@ def generate_docker_compose(template_file: str, ip: str, develop: bool = False) "docker-compose.setup.ove.yml", ip, develop="develop" in sys.argv, + live_model="live_model" in sys.argv, ) diff --git a/run_live.sh b/run_live.sh new file mode 100644 index 0000000..d9f0ec0 --- /dev/null +++ b/run_live.sh @@ -0,0 +1,2 @@ +python3 configure.py live_model +docker-compose up -d