24 lines
1.5 KiB
Python
24 lines
1.5 KiB
Python
"""Trous courts (1 à 2 pas) sur toutes les données de chaque station, hors lots compris : leur nombre par heure UTC,
|
|||
|
|
et les nuits où un trou tombe entre 01:00 et 03:00, avec les stations touchées (lancé depuis la racine)."""
|
||
|
|
import csv, glob, os, statistics, collections
|
||
|
|
from datetime import datetime
|
||
|
|
def UTC(s): return datetime.fromisoformat(s.replace(' ', 'T')[:16] + '+00:00')
|
||
|
|
par_h = collections.defaultdict(collections.Counter); nuits = collections.defaultdict(set)
|
||
|
|
for st in ['BREITHORN', 'CLARIDEN', 'FLORIDA', 'JUNGFRAU', 'LENZSPITZE', 'MICHIGAN', 'NEBRASKA', 'NIEDERHORN', 'NORDEND', 'SNCF01', 'WILDSTRUBEL']:
|
||
|
|
ts = set()
|
||
|
|
for p in glob.glob(f'data/{st}/displacement/{st}_advanced_*.csv'):
|
||
|
|
with open(p) as f:
|
||
|
|
next(f)
|
||
|
|
for l in f:
|
||
|
|
if l[:2] == '20': ts.add(l[:16])
|
||
|
|
ts = sorted(UTC(t) for t in ts)
|
||
|
|
pas = statistics.median([(y - x).total_seconds() for x, y in zip(ts, ts[1:])])
|
||
|
|
for x, y in zip(ts, ts[1:]):
|
||
|
|
n = round((y - x).total_seconds() / pas) - 1
|
||
|
|
if 1 <= n <= 2 and pas <= 3600:
|
||
|
|
par_h[st][x.hour] += 1
|
||
|
|
if 1 <= x.hour <= 2: nuits[f'{x:%m-%d}'].add(f'{st}@{x:%H:%M}')
|
||
|
|
print(f'{st:<12} pas {pas/60:3.0f} min, {ts[0]:%m-%d} -> {ts[-1]:%m-%d}, trous courts par heure : '
|
||
|
|
+ ' '.join(f'{h}:{par_h[st][h]}' for h in range(24) if par_h[st][h]))
|
||
|
|
print('\nnuits avec un trou court entre 01:00 et 03:00 (instant de la mesure d\'avant)')
|
||
|
|
for n in sorted(nuits): print(n, ' '.join(sorted(nuits[n])))
|