API: support page with two Claude API clients, support and analyst (D-133)

Self-contained sub-project API/: a local support page where Marc pastes a
client's mail; a support agent and an analyst agent stay alive for the session
and produce a slide PDF that answers the client's question. Tools, detectors,
knowledge and Typst brand are copied (API/PROVENANCE.md). First real case:
Crissier (LENZSPITZE), workflow validated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-05 12:58:39 +01:00
1 parent 874f6bf7ea
commit 8ba75b92fa
130 files changed
+42094

No files matched your search

+94
View File
@@ -0,0 +1,94 @@
"""Graphique PNG des séries d'un export « advanced », pour que l'agent de diagnostic les regarde.
Usage : .venv/bin/python agent-tools/graphique.py data/PS_DES_COUDRES/
[--capteurs CAPTEUR_A,CAPTEUR_B] [--colonnes error_value,corr_x,corr_y] [--debut ...] [--fin ...]
[--zone DEBUT/FIN ...] [--sortie DOSSIER]
Un panneau par colonne, une courbe par capteur, heures UTC ; chaque --zone est grisée. Colonnes : error_value, corr_x, corr_y,
relative_x, relative_y, x, y, sigma0, reproj_err, et les six métriques de qualité d'image (peak à snr, valeurs brutes ; face à une référence calme : qualite.py).
Imprime le chemin du PNG (out/diagnostic/, ou --sortie : le dossier du rapport, pour une figure de preuve).
"""
import argparse
import os
import sys
import matplotlib
matplotlib.use("Agg")
import matplotlib.dates as mdates # noqa: E402
import matplotlib.pyplot as plt # noqa: E402
from donnees import charger, est_reference, filtrer, instant # noqa: E402
from resume import QUALITE # noqa: E402
RACINE = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
COLONNES = ("error_value", "corr_x", "corr_y", "relative_x", "relative_y", "x", "y", "sigma0", "reproj_err")
def zone(texte):
"""'2026-10-13T01:00Z/2026-10-13T03:00Z' -> (début, fin)."""
debut, sep, fin = texte.partition("/")
if not sep:
raise argparse.ArgumentTypeError(f"zone invalide : {texte!r} (ex. 2026-10-13T01:00Z/2026-10-13T03:00Z)")
return instant(debut), instant(fin)
def borne(t, defaut):
return t.strftime("%Y%m%dT%H%MZ") if t else defaut
def main():
a = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
a.add_argument("dossier")
a.add_argument("--capteurs", help="liste séparée par des virgules (défaut : tous)")
a.add_argument("--colonnes", default="error_value,corr_x,corr_y")
a.add_argument("--debut", type=instant)
a.add_argument("--fin", type=instant)
a.add_argument("--zone", type=zone, action="append", default=[], help="fenêtre à griser, DEBUT/FIN (répétable)")
a.add_argument("--sortie", default=os.path.join(RACINE, "out", "diagnostic"), help="dossier du PNG")
o = a.parse_args()
par = charger(o.dossier)
if not par:
sys.exit(f"Aucun export « advanced » dans {o.dossier} (voir inventaire.py).")
noms = o.capteurs.split(",") if o.capteurs else sorted(par, key=lambda s: (not est_reference(par[s]), s))
colonnes = o.colonnes.split(",")
for demandes, connus, quoi in ((noms, par, "Capteurs"), (colonnes, COLONNES + QUALITE, "Colonnes")):
absents = [x for x in demandes if x not in connus]
if absents:
sys.exit(f"{quoi} inconnus : {', '.join(absents)}. Connus : {', '.join(sorted(connus))}.")
series = {s: filtrer(par[s], o.debut, o.fin) for s in noms}
if not any(series.values()):
sys.exit("Aucune mesure dans la fenêtre demandée.")
vides = [c for c in colonnes if all(m[c] is None for s in noms for m in series[s])]
if len(vides) == len(colonnes):
sys.exit(f"Rien à tracer : {', '.join(colonnes)} vide(s) pour ces capteurs dans la fenêtre.")
if vides:
print(f"Panneaux vides (aucune valeur pour ces capteurs) : {', '.join(vides)}")
fig, axes = plt.subplots(len(colonnes), 1, sharex=True, figsize=(14, 3.2 * len(colonnes)), squeeze=False)
tab20 = plt.get_cmap("tab20").colors
couleurs = tab20[::2] + tab20[1::2] # teintes foncées d'abord : deux capteurs voisins ne partagent pas une teinte
for ax, col in zip(axes[:, 0], colonnes):
for i, s in enumerate(noms):
ms = series[s] # une valeur vide devient NaN : la courbe s'interrompt au lieu de relier le trou
ax.plot([m["t"] for m in ms], [float("nan") if m[col] is None else m[col] for m in ms], ".-", ms=2, lw=0.7,
color=couleurs[i % len(couleurs)], label=s)
for debut, fin in o.zone:
ax.axvspan(debut, fin, color="0.85", zorder=0)
ax.set_ylabel(col)
ax.grid(alpha=0.3)
axes[0, 0].legend(loc="upper left", bbox_to_anchor=(1.0, 1.0), fontsize=8)
axes[-1, 0].xaxis.set_major_formatter(mdates.DateFormatter("%d/%m\n%H:%MZ"))
station = os.path.basename(os.path.normpath(o.dossier))
fig.suptitle(f"{station} : {', '.join(colonnes)} (heures UTC)")
os.makedirs(o.sortie, exist_ok=True)
qui = "-".join(noms) if o.capteurs else "tous"
sortie = os.path.join(o.sortie, f"{station}_{'-'.join(colonnes)}_{qui}_"
f"{borne(o.debut, 'debut')}_{borne(o.fin, 'fin')}.png")
fig.savefig(sortie, dpi=100, bbox_inches="tight")
print(sortie)
if __name__ == "__main__":
main()