R2: git = source de vérité — src/nodes/ + build/extract intégrés au push
- src/nodes/*.js (6 nodes + template snapshot) = source de vérité unique. - n8n-push.mjs reconstruit le JSON depuis src/ avant syntaxe+golden+PUT (src gagne toujours; n8n-extract.mjs pour resynchroniser si édition UI). - n8n-build.mjs --check pour vérifier la synchro. - Copies historiques déplacées dans archive/ (mortes, dérivées de la prod). - .gitignore: backups locaux de rollback. - AGENTS.md: règle R2 pour toutes les futures sessions (dont Qwen local). - Validé: idempotence, mutation/restauration, pipeline push complet en réel.
This commit is contained in:
159
archive/decoupesurplus/V2/DEC3.js
Normal file
159
archive/decoupesurplus/V2/DEC3.js
Normal file
@@ -0,0 +1,159 @@
|
||||
// =====================================================
|
||||
// START BRANCH
|
||||
// =====================================================
|
||||
else {
|
||||
const startConditionsOk =
|
||||
(context.sourceMode === 'grid_hc_allowed' || context.sourceMode === 'grid_forced')
|
||||
? conditions.gridStartOk
|
||||
: (context.sourceMode === 'solar_only' || context.sourceMode === 'solar_potential')
|
||||
? conditions.solarStartOk
|
||||
: context.sourceMode === 'hybrid_probe'
|
||||
? conditions.probeStartOk
|
||||
: false;
|
||||
|
||||
if (!derived.canRunAtMinCurrent) {
|
||||
setOff({
|
||||
stateName: 'blocked_by_capacity_min_current',
|
||||
decisionName: 'hold',
|
||||
reasonText: 'Capacité insuffisante pour courant mini',
|
||||
dynamic: false,
|
||||
mustStopFlag: false,
|
||||
blockReason: 'system_capacity_stop',
|
||||
blockedUntilStamp: formatParisStampFromMs(nowMs + 10 * 60000),
|
||||
});
|
||||
}
|
||||
|
||||
else if (context.sourceMode === 'blocked') {
|
||||
setOff({
|
||||
stateName:
|
||||
context.profile === 'outside_window'
|
||||
? 'blocked_outside_window'
|
||||
: (context.profile === 'night_hc'
|
||||
? 'night_no_grid_hc_lock'
|
||||
: 'idle_wait_source'),
|
||||
decisionName: 'hold',
|
||||
reasonText:
|
||||
context.profile === 'outside_window'
|
||||
? 'Hors fenêtre préférée sans source suffisante'
|
||||
: context.profile === 'night_hc'
|
||||
? 'Nuit sans autorisation HC réseau'
|
||||
: 'Source non autorisée ou insuffisante',
|
||||
dynamic: false,
|
||||
mustStopFlag: false,
|
||||
blockReason:
|
||||
context.profile === 'outside_window'
|
||||
? 'outside_window'
|
||||
: context.profile === 'night_hc'
|
||||
? 'grid_hc_unavailable'
|
||||
: 'source_unavailable',
|
||||
blockedUntilStamp:
|
||||
Number.isFinite(locks.nextAllowedWindowStartMs)
|
||||
? formatParisStampFromMs(locks.nextAllowedWindowStartMs)
|
||||
: formatParisStampFromMs(nowMs + 15 * 60000),
|
||||
});
|
||||
}
|
||||
|
||||
else if (locks.startBlockedByReason) {
|
||||
setOff({
|
||||
stateName: 'wait_reason_lock',
|
||||
decisionName: 'hold',
|
||||
reasonText: `Blocage anti-cliquetis: ${history.lastBlockReason}`,
|
||||
dynamic: false,
|
||||
mustStopFlag: false,
|
||||
blockReason: history.lastBlockReason,
|
||||
blockedUntilStamp: history.blockedUntilAt || now.stamp,
|
||||
});
|
||||
}
|
||||
|
||||
else if (!startConditionsOk) {
|
||||
setOff({
|
||||
stateName: 'idle_wait_conditions',
|
||||
decisionName: 'hold',
|
||||
reasonText: 'Conditions de démarrage non réunies',
|
||||
dynamic: false,
|
||||
mustStopFlag: false,
|
||||
blockReason: 'none',
|
||||
blockedUntilStamp: now.stamp,
|
||||
});
|
||||
}
|
||||
|
||||
else if (!lifecycle.minStopElapsed) {
|
||||
setOff({
|
||||
stateName: 'wait_min_stop',
|
||||
decisionName: 'hold',
|
||||
reasonText: 'Temps mini OFF non écoulé',
|
||||
dynamic: false,
|
||||
mustStopFlag: false,
|
||||
blockReason: 'none',
|
||||
blockedUntilStamp: now.stamp,
|
||||
});
|
||||
}
|
||||
|
||||
else {
|
||||
const startCurrentA =
|
||||
context.sourceMode === 'hybrid_probe'
|
||||
? clamp(params.probeCurrentA, params.currentMinA, derived.physicalCapA)
|
||||
: params.currentMinA;
|
||||
|
||||
setOn({
|
||||
stateName:
|
||||
context.sourceMode === 'grid_forced' ? 'start_grid_forced_min_current' :
|
||||
context.sourceMode === 'grid_hc_allowed' ? 'start_grid_hc_min_current' :
|
||||
context.sourceMode === 'hybrid_probe' ? 'probe_start_6a' :
|
||||
context.sourceMode === 'solar_potential' ? 'start_forecast_solar_potential' :
|
||||
modes.batteryFullHarvestMode ? 'start_min_current_battery_full_harvest' :
|
||||
modes.forecastCommitMode ? 'start_min_current_forecast_commit' :
|
||||
'start_min_current',
|
||||
decisionName: 'start',
|
||||
currentA: startCurrentA,
|
||||
reasonText:
|
||||
context.sourceMode === 'grid_forced'
|
||||
? 'Démarrage en charge réseau forcée'
|
||||
: context.sourceMode === 'grid_hc_allowed'
|
||||
? 'Démarrage en fenêtre HC réseau'
|
||||
: context.sourceMode === 'hybrid_probe'
|
||||
? 'Démarrage en mode sonde'
|
||||
: context.sourceMode === 'solar_potential'
|
||||
? 'Démarrage par potentiel solaire confirmé'
|
||||
: modes.batteryFullHarvestMode
|
||||
? 'Démarrage harvest solaire'
|
||||
: modes.forecastCommitMode
|
||||
? 'Démarrage forecast commit'
|
||||
: 'Démarrage prudent à courant mini',
|
||||
dynamic: true,
|
||||
mustStopFlag: false,
|
||||
});
|
||||
|
||||
nextBlockReason = 'none';
|
||||
nextBlockedUntilStamp = now.stamp;
|
||||
setProbeStartedAt = context.sourceMode === 'hybrid_probe';
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// OUTPUT
|
||||
// =====================================================
|
||||
return [{
|
||||
json: {
|
||||
...prev,
|
||||
decision: {
|
||||
desiredCharging,
|
||||
desiredPermission,
|
||||
desiredLatch,
|
||||
desiredCurrentA,
|
||||
state,
|
||||
currentDecision,
|
||||
dynamicOk,
|
||||
mustStop,
|
||||
reason,
|
||||
nextBlockReason,
|
||||
nextBlockedUntilStamp,
|
||||
setCloudDebtStartedAt,
|
||||
setProbeStartedAt,
|
||||
notifyWanted,
|
||||
notifyTitle,
|
||||
notifyMessage,
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user