diff --git a/dashboard/app.py b/dashboard/app.py index 59f343a..c37147c 100644 --- a/dashboard/app.py +++ b/dashboard/app.py @@ -1,12 +1,13 @@ """ VAULTCOM — Fallout: Venice of Wasteland Dashboard simulation. Schéma DB actuel (migration_003). +Onglets: Simulation (par session) | Paramètres (config + restart) """ -import os, json +import os, json, subprocess import psycopg2 import psycopg2.extras -from flask import Flask, render_template_string, jsonify +from flask import Flask, render_template_string, jsonify, request, redirect, url_for app = Flask(__name__) @@ -16,6 +17,8 @@ DB_NAME = os.getenv("DB_NAME", "fallout") DB_USER = os.getenv("DB_USER", "fallout") DB_PASS = os.getenv("DB_PASS", "VeniceOfWasteland2026!") +SIM_CONFIGS_DIR = os.getenv("SIM_CONFIGS_DIR", "/app/src/config") + def get_conn(): return psycopg2.connect( host=DB_HOST, port=DB_PORT, dbname=DB_NAME, @@ -35,8 +38,33 @@ def query_one(sql, params=None): rows = query(sql, params) return rows[0] if rows else None +def execute(sql, params=None): + conn = get_conn() + try: + with conn.cursor() as cur: + cur.execute(sql, params) + conn.commit() + finally: + conn.close() + +def load_sim_config(session_id: int) -> dict: + path = os.path.join(SIM_CONFIGS_DIR, f"sim_{session_id:03d}.json") + try: + with open(path) as f: + return json.load(f) + except Exception: + return {} + +def save_sim_config(session_id: int, cfg: dict): + path = os.path.join(SIM_CONFIGS_DIR, f"sim_{session_id:03d}.json") + with open(path, "w") as f: + json.dump(cfg, f, indent=2, ensure_ascii=False) + +def get_all_sessions(): + return query("SELECT * FROM sessions ORDER BY id") + # --------------------------------------------------------------------------- -# HTML template +# HTML Template # --------------------------------------------------------------------------- TEMPLATE = r""" @@ -44,33 +72,34 @@ TEMPLATE = r"""
-| J/T | TYPE | DESCRIPTION |
|---|
| {{ k }} | {{ v }} |
| TIER | LABEL | VIVANTS | MORTS | ||||
|---|---|---|---|---|---|---|---|
| {{ row.tier }} | -{{ row.label }} | -{{ row.alive }} | -{{ row.dead }} | +{{ row.tier }} | {{ row.label }} | +{{ row.alive }} | {{ row.dead }} |
+ Note: ne tue pas le process Python. Mettre "paused" ou "stopped" fait sortir run.py au prochain tick. +
+| MODE | DRAIN | ENCOUNTERS | CAPS |
|---|---|---|---|
| + {{ m_name }}{% if m_name == cfg.get('mode','') %} ◀{% endif %} | +×{{ m_vals.get('survival',{}).get('drain_speed','—') }} | +×{{ m_vals.get('encounter',{}).get('global_rate_multiplier','—') }} | +×{{ m_vals.get('economy',{}).get('caps_global_multiplier','—') }} | +
Copier-coller dans votre terminal SSH :
+# Lancer/relancer S{{ current_sid }} :
+cd /home/ubuntu/fallout-venice/src/engine
+nohup env SESSION_ID={{ current_sid }} SIM_CONFIG=../config/sim_{{ '%03d' % current_sid }}.json TICK_SLEEP_SEC=60 PYTHONUNBUFFERED=1 python3 -u run.py > ~/fallout_sim_s{{ current_sid }}.log 2>&1 &
+# Voir les logs :
+tail -f ~/fallout_sim_s{{ current_sid }}.log
+