// ======================================== // FICHIER: ErrorSelector.js // RESPONSABILITÉ: Sélection procédurale intelligente des erreurs // Orchestrateur qui décide quelles erreurs appliquer selon contexte // ======================================== const { logSh } = require('../../ErrorReporting'); const { determineSeverityLevel, analyzeTextCharacteristics, isErrorAllowed, getErrorProfile } = require('./ErrorProfiles'); const { applyErrorGrave } = require('./ErrorGrave'); const { applyErrorsMoyennes } = require('./ErrorMoyenne'); const { applyErrorsLegeres } = require('./ErrorLegere'); /** * SÉLECTION ET APPLICATION ERREURS PROCÉDURALES * Orchestrateur principal du système d'erreurs graduées * @param {string} content - Contenu à modifier * @param {object} options - Options { currentHour, tracker } * @returns {object} - { content, errorsApplied, errorDetails } */ function selectAndApplyErrors(content, options = {}) { const { currentHour, tracker } = options; logSh('🎲 SÉLECTION PROCÉDURALE ERREURS - Début', 'INFO'); // ======================================== // 1. ANALYSER CARACTÉRISTIQUES TEXTE // ======================================== const textCharacteristics = analyzeTextCharacteristics(content, currentHour); logSh(`📊 Analyse: ${textCharacteristics.wordCount} mots, ${textCharacteristics.lengthCategory}, ${textCharacteristics.technicalCategory}, mult=${textCharacteristics.globalMultiplier.toFixed(2)}`, 'DEBUG'); // ======================================== // 2. DÉTERMINER NIVEAU GRAVITÉ // ======================================== const severityLevel = determineSeverityLevel(); // Pas d'erreur pour cet article if (!severityLevel) { logSh('✅ Aucune erreur sélectionnée pour cet article (10% roll)', 'INFO'); return { content, errorsApplied: 0, errorDetails: { severity: null, types: [], characteristics: textCharacteristics } }; } // ======================================== // 3. VÉRIFIER SI ERREUR AUTORISÉE // ======================================== if (!isErrorAllowed(severityLevel, textCharacteristics)) { logSh(`🚫 Erreur ${severityLevel} bloquée par conditions`, 'INFO'); return { content, errorsApplied: 0, errorDetails: { severity: severityLevel, blocked: true, reason: 'conditions_not_met', characteristics: textCharacteristics } }; } // ======================================== // 4. APPLIQUER ERREURS SELON GRAVITÉ // ======================================== let modifiedContent = content; let totalErrorsApplied = 0; const errorTypes = []; const profile = getErrorProfile(severityLevel); logSh(`🎯 Application erreurs: ${profile.name} (max: ${profile.maxPerArticle})`, 'INFO'); switch (severityLevel) { case 'grave': // MAX 1 erreur grave const graveResult = applyErrorGrave(modifiedContent, tracker); if (graveResult.applied) { modifiedContent = graveResult.content; totalErrorsApplied++; errorTypes.push(graveResult.errorType); logSh(`✅ 1 erreur GRAVE appliquée: ${graveResult.errorType}`, 'INFO'); } break; case 'moyenne': // MAX 2 erreurs moyennes const moyenneResult = applyErrorsMoyennes(modifiedContent, 2, tracker); modifiedContent = moyenneResult.content; totalErrorsApplied = moyenneResult.errorsApplied; errorTypes.push(...moyenneResult.errorTypes); logSh(`✅ ${moyenneResult.errorsApplied} erreur(s) MOYENNE(s) appliquée(s)`, 'INFO'); break; case 'legere': // MAX 3 erreurs légères const legereResult = applyErrorsLegeres(modifiedContent, 3, tracker); modifiedContent = legereResult.content; totalErrorsApplied = legereResult.errorsApplied; errorTypes.push(...legereResult.errorTypes); logSh(`✅ ${legereResult.errorsApplied} erreur(s) LÉGÈRE(s) appliquée(s)`, 'INFO'); break; } // ======================================== // 5. RETOURNER RÉSULTATS // ======================================== logSh(`🎲 SÉLECTION PROCÉDURALE ERREURS - Terminé: ${totalErrorsApplied} erreur(s)`, 'INFO'); return { content: modifiedContent, errorsApplied: totalErrorsApplied, errorDetails: { severity: severityLevel, profile: profile.name, types: errorTypes, characteristics: textCharacteristics, blocked: false } }; } /** * STATISTIQUES SYSTÈME ERREURS * @returns {object} - Stats complètes */ function getErrorSystemStats() { return { severityLevels: { grave: { probability: '10%', maxPerArticle: 1 }, moyenne: { probability: '30%', maxPerArticle: 2 }, legere: { probability: '50%', maxPerArticle: 3 }, none: { probability: '10%' } }, characteristics: { length: ['short', 'medium', 'long'], technical: ['high', 'medium', 'low'], temporal: ['morning', 'afternoon', 'evening', 'night'] }, totalErrorTypes: { grave: 4, moyenne: 5, legere: 5 } }; } // ============= EXPORTS ============= module.exports = { selectAndApplyErrors, getErrorSystemStats };