Files
Support-Agent/src/analyse_01.py
T

33 lines
1.2 KiB
Python
Raw Normal View History

"""Analyse 01 : MOVING_AVERAGE_7_DAYS_DROP (tendance de BusVoltage en moyenne glissante), graphiques HTML ouverts dans le navigateur.
La page montre aussi, juste dessous, l'analyse 02 (MOVING_AVERAGE_7_DAYS_MIDNIGHT_UTC_DROP), pour comparer les deux méthodes.
Usage : python3 src/analyse_01.py [CSV ou dossiers...] (défaut : data/, sortie dans out/)
Documentation : docs/analyses/analyse_01.md
"""
import importlib.util
import os
import shutil
import subprocess
import sys
import webbrowser
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
VENV = ROOT / ".venv" / "bin" / "python"
if importlib.util.find_spec("plotly") is None and VENV.exists():
os.execv(VENV, [str(VENV), *sys.argv]) # plotly n'est installé que dans .venv
import energy_plot # noqa: E402
def open_html(path):
if shutil.which("explorer.exe") and shutil.which("wslpath"): # WSL : navigateur Windows
subprocess.run(["explorer.exe", subprocess.check_output(["wslpath", "-w", path], text=True).strip()])
else:
webbrowser.open(Path(path).resolve().as_uri())
if __name__ == "__main__":
args = sys.argv[1:] or [str(ROOT / "data")]
for p in energy_plot.main([*args, "--out", str(ROOT / "out")]):
open_html(p)