Files
Support-Agent/labeling/auto/revue-croisee/2026-11-04/outils/appliquer.py
T
maximeandClaude Opus 5.5 c6e9df0e46 Stable ids for auto labels, a summary for the label map, reading tools improved (D-131)
- Every auto label carries an id (<STATION>-<n>, labeling/ids.py), kept on edit, given to
  new labels by labeling.py and by the reviews; controle.py requires it, unique. The
  cross-review matches labels by id, and an applied review is locked (applique.md).
- The label map starts with a summary (labels-map/sommaire.py): readers take the summary and
  sections 2-4 in full, then only the cards of the phenomena they meet.
- Tool-builder session on the reviewers' difficulties: jours.py --lissage/--fraction,
  ensemble.py --suivre and rejected measures left out of --rigide, --residus non, zero noise
  after a lost reference, new agent-tools/stations.py (several stations on one timeline),
  long outputs convention in lire-les-donnees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 08:49:54 +01:00

42 lines
2.4 KiB
Python

"""Applique les modifications.jsonl des relecteurs (<dossier>/<famille>/) aux étiquettes de labeling/auto/.
Les ids sont les ids stables des étiquettes (D-131) ; une ajoutée en reçoit un.
Une étiquette touchée par deux relecteurs n'est pas appliquée : listée, à trancher (--choix id=famille)."""
import json, glob, os, sys, collections
ici = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
date = '2026-11-04'
choix = dict(a.split('=', 1) for a in sys.argv[1:] if '=' in a)
verrou = f'{ici}/applique.md' # une revue ne s'applique qu'une fois : ses « ajouter » se doubleraient
if os.path.exists(verrou):
sys.exit(f'déjà appliquée ({open(verrou).read().strip()}) : rien fait')
mods = []
for p in sorted(glob.glob(f'{ici}/*/modifications.jsonl')):
rel = os.path.basename(os.path.dirname(p))
mods += [dict(json.loads(l), relecteur=rel) for l in open(p) if l.strip()]
par_id = collections.defaultdict(list)
for m in mods:
if 'id' in m: par_id[m['id']].append(m)
conflits = {i: l for i, l in par_id.items() if len({json.dumps(m.get('etiquette'), sort_keys=True) + m['action'] for m in l}) > 1}
for i, l in conflits.items():
if i in choix: par_id[i] = [m for m in l if m['relecteur'] == choix[i]]
else: print('CONFLIT', i, [(m['relecteur'], m['action']) for m in l])
compte = collections.Counter()
for p in sorted(glob.glob('labeling/auto/*.jsonl')):
st = os.path.basename(p)[:-6]
out = []
for n, l in enumerate(open(p), 1):
if not l.strip(): continue
e = json.loads(l); i = e.get('id', f'{st}#{n}') # l'id stable (D-131), sinon le numéro de ligne
if i in conflits and i not in choix: out.append(e); continue
m = par_id.get(i, [None])[0]
if m is None: out.append(e)
elif m['action'] == 'modifier': out.append(dict(m['etiquette'], revue=date)); compte['modifiées'] += 1
elif m['action'] == 'retirer': compte['retirées'] += 1
for m in mods:
if m['action'] == 'ajouter' and m['station'] == st:
out.append(dict(m['etiquette'], revue=date)); compte['ajoutées'] += 1
out.sort(key=lambda e: (e['debut'], e['fin']))
sys.path.insert(0, 'labeling'); import ids; ids.attribuer(st, out) # un id aux ajoutées (D-131)
open(p, 'w').writelines(json.dumps(e, ensure_ascii=False) + '\n' for e in out)
print(dict(compte), len(conflits), 'conflits')
open(verrou, 'w').write(f'appliquée le {__import__("datetime").date.today()} : {dict(compte)}\n')