Keep code-shaped sensor names as their own code in anonymiser-cas
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
911fef43f5
commit
ec7ff2882a
1 file changed
+14
-5
@@ -39,10 +39,17 @@ def codes(dossier, cas_id):
|
||||
if not any(l["station"] == l["nom"] == station and l["code"] == cas_id for l in lignes):
|
||||
nouveaux.append((station, station, cas_id))
|
||||
for prefixe, reference in (("R", True), ("C", False)):
|
||||
n = max((int(c[1:]) for (s, _), c in capteurs.items() if s == station and c[0] == prefixe), default=0)
|
||||
for nom in sorted(x for x in par if est_reference(par[x]) == reference and (station, x) not in capteurs):
|
||||
n += 1
|
||||
nouveaux.append((station, nom, f"{prefixe}{n}"))
|
||||
pris = {c for (s, _), c in capteurs.items() if s == station and c[0] == prefixe}
|
||||
noms = sorted(x for x in par if est_reference(par[x]) == reference and (station, x) not in capteurs)
|
||||
# un nom qui a déjà la forme d'un code de son rôle (R1 pour une référence) le garde : le recoder ferait de
|
||||
# ce code un nom réel, recodé à chaque passage
|
||||
gardes = [x for x in noms if re.fullmatch(prefixe + r"\d+", x) and x not in pris]
|
||||
nouveaux += [(station, x, x) for x in gardes]
|
||||
n = max((int(c[1:]) for c in pris | set(gardes)), default=0)
|
||||
for nom in noms:
|
||||
if nom not in gardes:
|
||||
n += 1
|
||||
nouveaux.append((station, nom, f"{prefixe}{n}"))
|
||||
if nouveaux:
|
||||
with open(REGISTRE, "a", newline="") as f:
|
||||
w = csv.writer(f)
|
||||
@@ -108,7 +115,7 @@ def anonymiser(dossier, cas):
|
||||
if apres != avant:
|
||||
ecrire(p, apres)
|
||||
|
||||
reste = motif(table, station, casse=True)
|
||||
reste = motif({n: c for n, c in table.items() if n != c}, station, casse=True)
|
||||
residus = [f"{p} : {m.group(1)}" for p in textes() for m in reste.finditer(lire(p))]
|
||||
residus += [os.path.join(r, f) for r, ds, fs in os.walk(cas) for f in fs + ds if reste.search(f)]
|
||||
if residus:
|
||||
@@ -124,6 +131,8 @@ def _test():
|
||||
assert f("PS des Coudres_advanced_20261008.csv, REF_GX") == "C-001_advanced_20261008.csv, REF_GX"
|
||||
t["Carrière X (B)"] = "C-001"
|
||||
assert f("displacement/Carrière X (B)_20260728_to_20260731_1hour.csv") == "displacement/C-001_20260728_to_20260731_1hour.csv"
|
||||
t.update({"R1": "R1", "PA1_2": "R4"}) # un nom en forme de code le garde : un second passage ne change rien
|
||||
assert f(f("R1,PA1_2")) == "R1,R4"
|
||||
print("ok")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user