Streamline Dockerfile, remove unused deps

* Dockerfile: Use non-root user, buildx cache, setup for readonly
   container, remove unused apt deps.
   For now don't install pip package and keep development flask server
   as this will be replaced in the future (fastapi). Then a proper
   webserver (e.g. nginx) should be used and the pip package can be
   created and deployed just to the run-stage (with the webserver).
 * docker-compose: Set to readonly (anonymous volumes declared in
   Dockerfile should maintain all writable data).
   Mount config.py for easier development. Should be replaced by
   environment support for all config file variables.
 * Remove unused runtime dependencies: mariadb, joblib, pytest,
   pytest-cov.
 * Move pytest-cov to dev dependencies.
 * Add output_dir to config.py.
 * Fix visualization_results.pdf endpoint.
 * Update docs.
This commit is contained in:
Dominique Lasserre
2024-10-07 20:56:10 +02:00
committed by Andreas
parent 86639b9437
commit a71eab3bd0
12 changed files with 65 additions and 51 deletions

View File

@@ -1,5 +1,7 @@
from datetime import datetime, timedelta
output_dir = "output"
prediction_hours = 48
optimization_hours = 24
strafe = 10

View File

@@ -1,4 +1,5 @@
import datetime
import os
# Set the backend for matplotlib to Agg
import matplotlib
@@ -7,6 +8,7 @@ import numpy as np
from matplotlib.backends.backend_pdf import PdfPages
from akkudoktoreos.class_sommerzeit import ist_dst_wechsel
from akkudoktoreos.config import output_dir
matplotlib.use("Agg")
@@ -28,7 +30,10 @@ def visualisiere_ergebnisse(
#####################
# 24-hour visualization
#####################
with PdfPages(filename) as pdf:
if not os.path.exists(output_dir):
os.makedirs(output_dir)
output_file = os.path.join(output_dir, filename)
with PdfPages(output_file) as pdf:
# Load and PV generation
plt.figure(figsize=(14, 14))
plt.subplot(3, 3, 1)

View File

@@ -18,7 +18,12 @@ from akkudoktoreos.class_load_corrector import LoadPredictionAdjuster
from akkudoktoreos.class_optimize import optimization_problem
from akkudoktoreos.class_pv_forecast import PVForecast
from akkudoktoreos.class_strompreis import HourlyElectricityPriceForecast
from akkudoktoreos.config import get_start_enddate, optimization_hours, prediction_hours
from akkudoktoreos.config import (
get_start_enddate,
optimization_hours,
output_dir,
prediction_hours,
)
app = Flask(__name__)
@@ -262,11 +267,11 @@ def flask_optimize():
return jsonify(result)
@app.route("/visualisierungsergebnisse.pdf")
@app.route("/visualization_results.pdf")
def get_pdf():
# Endpoint to serve the generated PDF with visualization results
return send_from_directory(
"", "visualisierungsergebnisse.pdf"
os.path.abspath(output_dir), "visualization_results.pdf"
) # Adjust the directory if needed