Checkpoint: Suppression des 6 lignes parasites en BDD (Infogérance, Sécurité, Applicatifs HEP, Applicatifs SMR, Téléphonie, TOTAL) + filtre PARASITE_PATTERNS dans handleFileImport pour empêcher leur réinsertion lors d'un import Excel.
This commit is contained in:
51
scripts/clean-bases-parasites.mjs
Normal file
51
scripts/clean-bases-parasites.mjs
Normal file
@@ -0,0 +1,51 @@
|
||||
import { createConnection } from 'mysql2/promise';
|
||||
import { config } from 'dotenv';
|
||||
config();
|
||||
|
||||
const conn = await createConnection(process.env.DATABASE_URL);
|
||||
|
||||
// Libellés parasites connus (noms de catégories ou lignes de synthèse)
|
||||
const PARASITES_KEYWORDS = [
|
||||
'Infogérance', 'Infogerance', 'Sécurité', 'Securite',
|
||||
'Téléphonie', 'Telephonie',
|
||||
'App global', 'App HEP', 'App SMR',
|
||||
'Applicatifs', // commence par
|
||||
'TOTAL', 'Total',
|
||||
'Ventilation', 'Répartition', 'Repartition',
|
||||
'Nouveautés', 'Nouveautes',
|
||||
];
|
||||
|
||||
// 1. Lister les lignes parasites
|
||||
const [rows] = await conn.execute(
|
||||
`SELECT id, annee, etablissementCode, etablissementNom FROM opex_bases_repartition ORDER BY annee, etablissementCode`
|
||||
);
|
||||
|
||||
console.log('=== Toutes les lignes opex_bases_repartition ===');
|
||||
for (const r of rows) {
|
||||
const code = r.etablissementCode ?? '';
|
||||
const nom = r.etablissementNom ?? '';
|
||||
const isParasite = PARASITES_KEYWORDS.some(k =>
|
||||
code.toLowerCase().includes(k.toLowerCase()) ||
|
||||
nom.toLowerCase().includes(k.toLowerCase())
|
||||
) || /^(total|ventilation|répartition|applicatifs)/i.test(code.trim());
|
||||
if (isParasite) {
|
||||
console.log(` PARASITE id=${r.id} annee=${r.annee} code="${code}" nom="${nom}"`);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Supprimer les parasites
|
||||
const [delResult] = await conn.execute(
|
||||
`DELETE FROM opex_bases_repartition
|
||||
WHERE etablissementCode REGEXP '^(Infog|S.curit|T.l.phonie|App global|App HEP|App SMR|Applicatifs|TOTAL|Total|Ventilation|R.partition|Nouveaut)'
|
||||
OR etablissementNom REGEXP '^(Infog|S.curit|T.l.phonie|App global|App HEP|App SMR|Applicatifs|TOTAL|Total|Ventilation|R.partition|Nouveaut)'`
|
||||
);
|
||||
console.log(`\nSupprimé ${delResult.affectedRows} lignes parasites.`);
|
||||
|
||||
// 3. Vérification finale
|
||||
const [remaining] = await conn.execute(
|
||||
`SELECT annee, COUNT(*) as cnt FROM opex_bases_repartition GROUP BY annee ORDER BY annee`
|
||||
);
|
||||
console.log('=== Lignes restantes par année ===');
|
||||
console.table(remaining);
|
||||
|
||||
await conn.end();
|
||||
33
scripts/dedup-opex-postes.mjs
Normal file
33
scripts/dedup-opex-postes.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createConnection } from 'mysql2/promise';
|
||||
import { config } from 'dotenv';
|
||||
config();
|
||||
|
||||
const conn = await createConnection(process.env.DATABASE_URL);
|
||||
|
||||
// 1. Voir les doublons
|
||||
const [doublons] = await conn.execute(
|
||||
'SELECT annee, libelle, COUNT(*) as cnt FROM opex_postes GROUP BY annee, libelle HAVING cnt > 1 ORDER BY cnt DESC LIMIT 30'
|
||||
);
|
||||
console.log('=== Doublons (annee, libelle) ===');
|
||||
console.table(doublons);
|
||||
|
||||
// 2. Total par année
|
||||
const [totaux] = await conn.execute(
|
||||
'SELECT annee, COUNT(*) as cnt FROM opex_postes GROUP BY annee ORDER BY annee'
|
||||
);
|
||||
console.log('=== Total postes par année ===');
|
||||
console.table(totaux);
|
||||
|
||||
// 3. Libellés qui ressemblent à des catégories (parasites)
|
||||
const [parasites] = await conn.execute(
|
||||
`SELECT id, annee, libelle, categorie FROM opex_postes
|
||||
WHERE libelle IN ('Infogérance','Sécurité','Téléphonie','App global','App HEP','App SMR',
|
||||
'Applicatifs communs','Applicatifs PA','Applicatifs HEP','Applicatifs SMR','Nouveautés','TOTAL',
|
||||
'Ventilation cout','Ventilation coût')
|
||||
OR libelle REGEXP '^(total|ventilation|répartition)'
|
||||
ORDER BY annee, libelle`
|
||||
);
|
||||
console.log('=== Libellés parasites en BDD ===');
|
||||
console.table(parasites);
|
||||
|
||||
await conn.end();
|
||||
Reference in New Issue
Block a user