From 2e0ebe7012a675e6c0d1557331da48ac63054def Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Thu, 16 May 2024 16:14:55 +0100 Subject: [PATCH] Update infrastructure to python3.11 --- Dockerfile | 16 +++++++++++++- client_code/Main/FiguresPanel/__init__.py | 2 +- client_code/Plots.py | 27 +++++++++++++---------- scripts/convert_spreadsheet.ps1 | 2 +- scripts/convert_spreadsheet.sh | 2 +- 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 69b11e2..0ab357a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,18 @@ -FROM ghcr.io/imperialcollegelondon/anvil-app-server:latest +FROM python:3.11 + +RUN wget -O - https://apt.corretto.aws/corretto.key | gpg --dearmor -o /usr/share/keyrings/corretto-keyring.gpg && \ + echo "deb [signed-by=/usr/share/keyrings/corretto-keyring.gpg] https://apt.corretto.aws stable main" | tee /etc/apt/sources.list.d/corretto.list + +RUN apt-get update && apt-get install -y java-11-amazon-corretto-jdk && rm -rf /var/lib/apt/lists/* + +WORKDIR /apps + +RUN mkdir /anvil-data + +RUN useradd anvil +RUN chown -R anvil:anvil /anvil-data +USER anvil + ENTRYPOINT [] USER root diff --git a/client_code/Main/FiguresPanel/__init__.py b/client_code/Main/FiguresPanel/__init__.py index 9880a56..9acc44a 100644 --- a/client_code/Main/FiguresPanel/__init__.py +++ b/client_code/Main/FiguresPanel/__init__.py @@ -61,7 +61,7 @@ def calculate(self, inputs, start_year, end_year, expert_mode=False): def build_warnings(self): self.warnings_panel.clear() - warnings = init_vals["layout"]["Warnings"]["Not required"] + warnings = init_vals["layout"].get("Warnings", {}).get("Not required", []) for key in warnings: name, output, plot_type, _ = warnings[key] diff --git a/client_code/Plots.py b/client_code/Plots.py index ffdd45a..36918b1 100644 --- a/client_code/Plots.py +++ b/client_code/Plots.py @@ -53,18 +53,21 @@ def plot_stacked_area(plot, model_solution, output, title, axis_unit): data = [] total = None for name, y in _prepare_rows(model_output, x): - if "total" in name.lower(): - total = _partial_scatter( - x, y, name, mode="lines", line=dict(width=4, color="black") - ) - elif all(val <= 0 for val in y): - data.append( - _partial_scatter(x, y, name=name, mode="lines", stackgroup="two") - ) - else: - data.append( - _partial_scatter(x, y, name=name, mode="lines", stackgroup="one") - ) + try: + if "total" in name.lower(): + total = _partial_scatter( + x, y, name, mode="lines", line=dict(width=4, color="black") + ) + elif all(val <= 0 for val in y): + data.append( + _partial_scatter(x, y, name=name, mode="lines", stackgroup="two") + ) + else: + data.append( + _partial_scatter(x, y, name=name, mode="lines", stackgroup="one") + ) + except TypeError: + pass if total: data.append(total) plot.data = data diff --git a/scripts/convert_spreadsheet.ps1 b/scripts/convert_spreadsheet.ps1 index 73133d7..03d11b5 100755 --- a/scripts/convert_spreadsheet.ps1 +++ b/scripts/convert_spreadsheet.ps1 @@ -1,6 +1,6 @@ $ErrorActionPreference = "Stop" $path = Resolve-Path $args[0] -docker run --pull always --rm -it -v ${path}:/opt/excel_to_code/input.xlsx:ro -v ${pwd}:/opt/excel_to_code/work/ ghcr.io/imperialcollegelondon/calc2050_excel_to_code:main bash ./run.sh +docker run --pull always --rm -it -v ${path}:/opt/excel_to_code/input.xlsx:ro -v ${pwd}:/opt/excel_to_code/work/ ghcr.io/imperialcollegelondon/calc2050_excel_to_code:icl bash ./run.sh Copy-Item -Path .\model\_interface2050.cpython-39-x86_64-linux-gnu.so -Destination .\server_code\ Copy-Item -Path .\model\interface2050.py -Destination .\server_code\ diff --git a/scripts/convert_spreadsheet.sh b/scripts/convert_spreadsheet.sh index 6bf8370..7e4f6ef 100644 --- a/scripts/convert_spreadsheet.sh +++ b/scripts/convert_spreadsheet.sh @@ -22,7 +22,7 @@ spreadsheet=$(realpath "$1") docker run --pull always --rm -it -u "$(id -u)":"$(id -g)" \ -v "${spreadsheet}":/opt/excel_to_code/input.xlsx:ro \ -v "$(pwd)":/opt/excel_to_code/work/ \ - ghcr.io/imperialcollegelondon/calc2050_excel_to_code:main \ + ghcr.io/imperialcollegelondon/calc2050_excel_to_code:icl \ bash ./run.sh cp model/_interface2050.cpython-39-x86_64-linux-gnu.so model/interface2050.py server_code/