31 lines
1.8 KiB
Python
31 lines
1.8 KiB
Python
"""Détail heure par heure des métriques autour de chaque trou de trous.py : BusVoltage, BatteryPercent,
|
|||
|
|
nombre de synchronisations (last_sync) tombées dans le trou, DB_not_uploaded.
|
||
|
|
Usage : python3 detail.py STATION [STATION...] (lancé depuis la racine)"""
|
||
|
|
import ast, sys, os
|
||
|
|
from datetime import timedelta
|
||
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
||
|
|
import importlib.util
|
||
|
|
spec = importlib.util.spec_from_file_location('t', os.path.join(os.path.dirname(__file__), 'trous.py'))
|
||
|
|
src = open(spec.origin).read().split('tous = {}')[0] # fonctions et lots seulement
|
||
|
|
exec(src)
|
||
|
|
for st in sys.argv[1:]:
|
||
|
|
for a, b in LOTS[st]:
|
||
|
|
a, b = d(a), d(b)
|
||
|
|
ts = instants(st, a, b)
|
||
|
|
pas = statistics.median([(y - x).total_seconds() for x, y in zip(ts, ts[1:])])
|
||
|
|
M = {n: metrique(st, n, a, b) for n in ('BusVoltage', 'BatteryPercent', 'last_sync', 'DB_not_uploaded')}
|
||
|
|
syncs = set()
|
||
|
|
for v in M['last_sync'].values():
|
||
|
|
try: syncs |= {UTC(s) for s in ast.literal_eval(v)}
|
||
|
|
except Exception: pass
|
||
|
|
for x, y in zip(ts, ts[1:]):
|
||
|
|
if (y - x).total_seconds() <= 1.5 * pas or y <= a or x >= b: continue
|
||
|
|
ns = sorted(s for s in syncs if x < s < y)
|
||
|
|
print(f'\n{st} {h(x)} -> {h(y)} syncs dans le trou : {len(ns)} {",".join(f"{s:%H:%M}" for s in ns[:6])}')
|
||
|
|
t = x.replace(minute=0) - timedelta(hours=1)
|
||
|
|
while t <= y.replace(minute=0) + timedelta(hours=1):
|
||
|
|
print(f' {h(t)} BV {str(M["BusVoltage"].get(t, "-"))[:5]:>5} Bat {str(M["BatteryPercent"].get(t, "-"))[:4]:>4} '
|
||
|
|
f'notupl {str(M["DB_not_uploaded"].get(t, "-"))[:5]:>5}')
|
||
|
|
t += timedelta(hours=1)
|
||
|
|
if (y - x) > timedelta(hours=30) and x + timedelta(hours=3) < t < y - timedelta(hours=3):
|
||
|
|
t = y.replace(minute=0) - timedelta(hours=2)
|