PlatSim_Genova/ANALISI_DIFFERENZE_TARGET2.md

541 lines
16 KiB
Markdown

# Analisi Comparativa: Versione Corrente vs Target2 (Versione Funzionante)
**Data Analisi:** 2 Febbraio 2026
**Obiettivo:** Identificare le modifiche necessarie per portare la versione corrente alla stessa funzionalità della versione target2, senza perdere le nuove features.
---
## EXECUTIVE SUMMARY
La versione target2 è una versione **più semplice e snella** rispetto alla nostra versione corrente. Essa ha 379 righe contro le nostre 1250 righe. La nostra versione ha introdotto numerose funzionalità avanzate:
- Statistiche aggregate con export CSV
- Sistema di known failures
- Report PDF avanzato con grafici
- Tracking dettagliato seriale con contatori
- Sistema lazy-proxy per simulation mode
**Differenze critiche da riportare nella nostra versione:**
1. **Parametro wait_before nelle funzioni power** (target2 lo ha, noi no)
2. **Logica "force check" nel B8 drill-down** (target2 forza sempre il check B8 per statistiche)
3. **Numero di ripetizioni più basso** (target2: 2, noi: 10)
4. **Timeout PBIT** (target2: 182s, noi: 180s)
---
## 1. DIFFERENZE NEL FILE PRINCIPALE: GRIFO_M_PBIT.py
### 1.1 Struttura e Complessità
| Aspetto | Target2 (Funzionante) | Versione Corrente | Azione Richiesta |
|---------|----------------------|-------------------|------------------|
| **Linee di codice** | 379 | 1250 | ✅ Mantenere versione estesa |
| **Imports** | Base (no csv, json) | +csv, +json | ✅ Mantenere imports estesi |
| **Documentazione** | Minima | Docstring completa | ✅ Mantenere docstring |
| **Known failures** | ❌ Non presente | ✅ Presente | ✅ Mantenere sistema known failures |
| **Statistiche** | ❌ Non presente | ✅ Presente (test_statistics) | ✅ Mantenere tracking statistiche |
### 1.2 Configurazione Costanti
```python
# TARGET2 (Funzionante):
NUMBER_OF_REPETITIONS = 2
PBIT_SEC_TIME = 182
# VERSIONE CORRENTE:
NUMBER_OF_REPETITIONS = 10
PBIT_SEC_TIME = 180
EXPORT_STATISTICS_CSV = True
```
**⚠️ AZIONE 1.2.1:** Considerare se target2 usa 182 secondi per motivi specifici (timeout hardware più lungo). Testare entrambi i valori.
**⚠️ AZIONE 1.2.2:** Il numero di ripetizioni più basso (2) può essere dovuto a testing manuale. Mantenere configurabile (default 10).
---
### 1.3 Logica di Power Cycling - **DIFFERENZA CRITICA**
**TARGET2 (Funzionante):**
```python
def power_grifo_off(wait_after=0, wait_before=0):
time.sleep(wait_before)
setValue(theBrainBox,False,'MAIN_POWER')
ret,err = check(theBrainBox,0,'MAIN_POWER',timeout=0.1)
time.sleep(wait_after)
return ret
def power_grifo_on(wait_after=0, wait_before=0):
time.sleep(wait_before)
setValue(theBrainBox,True,'MAIN_POWER')
ret,err = check(theBrainBox,1,'MAIN_POWER')
time.sleep(wait_after)
return ret
# Nel test loop:
power_grifo_off(4, 1) # wait_after=4s, wait_before=1s
power_grifo_on(0.100) # wait_after=100ms
```
**VERSIONE CORRENTE:**
```python
def power_grifo_off(wait_after=0):
setValue(theBrainBox,False,'MAIN_POWER')
ret,err = check(theBrainBox,0,'MAIN_POWER',timeout=0.1)
time.sleep(wait_after)
return ret
def power_grifo_on(wait_after=0):
setValue(theBrainBox,True,'MAIN_POWER')
ret,err = check(theBrainBox,1,'MAIN_POWER')
time.sleep(wait_after)
return ret
# Nel test loop (quando chiamate):
power_grifo_off() # Nessun parametro
power_grifo_on(0.100)
```
**🔴 AZIONE 1.3.1 - CRITICA:** Aggiungere parametro `wait_before` a entrambe le funzioni `power_grifo_on()` e `power_grifo_off()` in `test_common_function.py`.
**🔴 AZIONE 1.3.2 - CRITICA:** Modificare le chiamate in GRIFO_M_PBIT.py per usare `power_grifo_off(4, 1)` come in target2.
**Motivazione:** Il `wait_before` potrebbe essere necessario per stabilizzare l'hardware prima di cambiare lo stato di alimentazione. Questa è una differenza comportamentale significativa.
---
### 1.4 Logica "Force Check" B8 Drill-Down - **DIFFERENZA FUNZIONALE**
**TARGET2 (Funzionante):**
```python
no_fail=True
for lru in lru_fields:
ret_proc_sts, err= check(theGrifo1553,"false",
"B6_MsgRdrSettingsAndParametersTellback",
lru)
if ret_proc_sts is False: no_fail=False
# ATTENZIONE: Forza sempre il check B8
no_fail=False # force check (to verify SW req.) and to obtain a valid step fail statistic
if no_fail is False:
logging.info("Check BIT Report...")
for f in bit_fields:
ret_error_field, err = check(theGrifo1553,"false","B8_MsgBitReport",f)
test_return = (test_return and ret_error_field)
```
**VERSIONE CORRENTE:**
```python
# Logica più complessa con known_failures, drill-down condizionale
# B8 viene eseguito SOLO se ci sono REAL failures (non known)
b6_pass_count = 0
b6_fail_count = 0
b6_known_fail_count = 0
b6_failures = []
b6_known_failures = []
for lru_field in lru_fields:
ret, value, err = check(theGrifo1553, "false",
"B6_MsgRdrSettingsAndParametersTellback", lru_field)
if not ret:
if lru_field in KNOWN_FAILURES:
b6_known_fail_count += 1
b6_known_failures.append((lru_field, value))
else:
b6_fail_count += 1
b6_failures.append((lru_field, value))
else:
b6_pass_count += 1
# B8 drill-down SOLO se ci sono REAL failures
if b6_fail_count > 0:
logging.info("Real B6 failures detected, performing B8 drill-down...")
# ... logica B8 ...
```
**⚠️ AZIONE 1.4.1:** Valutare se target2 forza **sempre** il check B8 per requisiti software specifici (statistiche, tracciabilità). Il commento dice "to verify SW req. and to obtain a valid step fail statistic".
**⚠️ AZIONE 1.4.2:** Se necessario, aggiungere un flag di configurazione `FORCE_B8_DRILL_DOWN` che permetta di forzare il check B8 anche quando ci sono solo known failures. Esempio:
```python
FORCE_B8_DRILL_DOWN = True # Force B8 check for all runs (as in target2)
# Nel codice:
if b6_fail_count > 0 or (FORCE_B8_DRILL_DOWN and b6_known_fail_count > 0):
logging.info("Performing B8 drill-down...")
# ... logica B8 ...
```
**Motivazione:** La versione target2 raccoglie **sempre** le statistiche B8, il che può essere un requisito di test per avere tracciabilità completa anche quando non ci sono failure reali.
---
### 1.5 BIT Fields Commentati
**TARGET2:**
- Molti campi di `bit_fields` sono commentati
- `pedestal_status` è commentato in `lru_fields`
**VERSIONE CORRENTE:**
- Usa sistema `KNOWN_FAILURES` invece di commentare
- Tutti i campi sono attivi
**✅ AZIONE 1.5.1:** Mantenere il sistema KNOWN_FAILURES - è più pulito e tracciabile rispetto ai commenti.
---
### 1.6 Funzioni tgt_gen() e tgt_gen_alone()
**TARGET2:**
```python
def tgt_gen(interface):
return # Funzione disabilitata con return immediato
# ... codice commentato per target generation test ...
def tgt_gen_alone(interface):
return # Funzione disabilitata
# ... codice commentato ...
```
**VERSIONE CORRENTE:**
- Queste funzioni non esistono più
**✅ AZIONE 1.6.1:** Non riportare queste funzioni - erano legacy code disabilitato. La nostra versione è più pulita.
---
## 2. DIFFERENZE IN test_common_function.py
### 2.1 Parametro wait_before - **CRITICA**
**File:** `TestEnvironment/env/test_common_function.py`
**TARGET2:**
```python
def power_grifo_on(wait_after=0, wait_before=0):
time.sleep(wait_before)
setValue(theBrainBox,True,'MAIN_POWER')
ret,err = check(theBrainBox,1,'MAIN_POWER')
time.sleep(wait_after)
return ret
def power_grifo_off(wait_after=0, wait_before=0):
time.sleep(wait_before)
setValue(theBrainBox,False,'MAIN_POWER')
ret,err = check(theBrainBox,0,'MAIN_POWER',timeout=0.1)
time.sleep(wait_after)
return ret
```
**VERSIONE CORRENTE:**
```python
def power_grifo_on(wait_after=0):
setValue(theBrainBox,True,'MAIN_POWER')
ret,err = check(theBrainBox,1,'MAIN_POWER')
time.sleep(wait_after)
return ret
def power_grifo_off(wait_after=0):
setValue(theBrainBox,False,'MAIN_POWER')
ret,err = check(theBrainBox,0,'MAIN_POWER',timeout=0.1)
time.sleep(wait_after)
return ret
```
**🔴 AZIONE 2.1.1 - PRIORITÀ ALTA:**
Modificare entrambe le funzioni in `test_common_function.py`:
```python
def power_grifo_on(wait_after=0, wait_before=0):
time.sleep(wait_before) # ← AGGIUNGERE QUESTA RIGA
setValue(theBrainBox,True,'MAIN_POWER')
ret,err = check(theBrainBox,1,'MAIN_POWER')
time.sleep(wait_after)
return ret
def power_grifo_off(wait_after=0, wait_before=0):
time.sleep(wait_before) # ← AGGIUNGERE QUESTA RIGA
setValue(theBrainBox,False,'MAIN_POWER')
ret,err = check(theBrainBox,0,'MAIN_POWER',timeout=0.1)
time.sleep(wait_after)
return ret
```
**Compatibilità:** Mantenere `wait_before=0` come default preserva la retrocompatibilità con tutti i chiamanti esistenti.
---
## 3. DIFFERENZE IN leo_grifo_terminal.py
### 3.1 Statistiche Seriale
**TARGET2:**
- NON ha statistiche seriale
- Semplice callback con logging
**VERSIONE CORRENTE:**
- ✅ Sistema completo di statistiche (`_serial_stats`)
- ✅ Tracking di %%E, %%F, RECYCLE
- ✅ Metodi `get_serial_statistics()` e `reset_serial_statistics()`
**✅ AZIONE 3.1.1:** Mantenere le statistiche seriale - sono un valore aggiunto della nostra versione.
---
## 4. DIFFERENZE IN leo_grifo_1553.py
### 4.1 Lazy Proxy Pattern
**TARGET2:**
- Singleton diretto: `theGrifo1553 = GrifoInstrumentInterface(0.2)`
- Nessun sistema di lazy initialization
**VERSIONE CORRENTE:**
- ✅ Sistema `_LazyGrifoProxy` per simulation mode
- ✅ Permette monkey-patching per mocks
**✅ AZIONE 4.1.1:** Mantenere il lazy proxy - è necessario per la simulation mode che target2 non ha.
---
## 5. DIFFERENZE IN leo_grifo_io_box.py
### 5.1 Identico
**Risultato:** I file `leo_grifo_io_box.py` in target2 e nella versione corrente sono **identici**.
**✅ AZIONE 5.1.1:** Nessuna modifica necessaria.
---
## 6. FUNZIONALITÀ NUOVE DA PRESERVARE
Le seguenti features della versione corrente **NON** sono presenti in target2 e devono essere **mantenute**:
### 6.1 Sistema Known Failures
- Lista `KNOWN_FAILURES` configurabile
- Distinzione tra real failures e known failures
- Reporting separato
### 6.2 Statistiche Aggregate
- Dizionario `test_statistics` globale
- Tracking per-run di:
- `pbit_time`
- `bit_available`
- `success/fail counts`
- `B6/B8 statistics`
### 6.3 Export CSV
- Flag `EXPORT_STATISTICS_CSV`
- Generazione file CSV con timing e failures
### 6.4 Report PDF Avanzato
- Funzione `generate_final_statistics_report()`
- Formattazione professionale
- Grafici e tabelle
### 6.5 Simulation Mode
- `--simulate` flag
- Mock objects in `GRIFO_M_PBIT_mock.py`
- Lazy proxy pattern
### 6.6 GUI Launcher
- `GRIFO_M_PBIT_gui.py`
- Selezione interattiva parametri
---
## 7. PIANO DI IMPLEMENTAZIONE MODIFICHE
### PRIORITÀ ALTA (Implementare subito)
#### Modifica 1: Aggiungere wait_before alle funzioni power
**File:** `TestEnvironment/env/test_common_function.py`
**Modifica:**
```python
def power_grifo_on(wait_after=0, wait_before=0):
time.sleep(wait_before) # ← NUOVA RIGA
setValue(theBrainBox,True,'MAIN_POWER')
ret,err = check(theBrainBox,1,'MAIN_POWER')
time.sleep(wait_after)
return ret
def power_grifo_off(wait_after=0, wait_before=0):
time.sleep(wait_before) # ← NUOVA RIGA
setValue(theBrainBox,False,'MAIN_POWER')
ret,err = check(theBrainBox,0,'MAIN_POWER',timeout=0.1)
time.sleep(wait_after)
return ret
```
**Retrocompatibilità:** ✅ Default `wait_before=0` preserva comportamento esistente
---
#### Modifica 2: Usare wait_before nelle chiamate power
**File:** `TestEnvironment/scripts/GRIFO_M_PBIT.py`
**Localizzazione:** Cerca le chiamate a `power_grifo_off()` nel loop principale
**Modifica:**
```python
# PRIMA:
power_grifo_off(4)
# DOPO:
power_grifo_off(wait_after=4, wait_before=1) # Come in target2
```
**Motivazione:** Target2 usa 1 secondo di wait_before per stabilizzare hardware prima di spegnere.
---
### PRIORITÀ MEDIA (Testare e valutare)
#### Modifica 3: Valutare timeout PBIT
**File:** `TestEnvironment/scripts/GRIFO_M_PBIT.py`
**Test:**
1. Eseguire test con `PBIT_SEC_TIME = 180` (corrente)
2. Eseguire test con `PBIT_SEC_TIME = 182` (target2)
3. Verificare se ci sono timeout con 180s
**Azione:** Se si verificano timeout, aumentare a 182s.
---
#### Modifica 4: Aggiungere flag FORCE_B8_DRILL_DOWN
**File:** `TestEnvironment/scripts/GRIFO_M_PBIT.py`
**Modifica:**
```python
# Nella sezione configurazione:
FORCE_B8_DRILL_DOWN = False # Set True to force B8 check even with only known failures
# Nel codice B8 drill-down:
if b6_fail_count > 0 or (FORCE_B8_DRILL_DOWN and b6_known_fail_count > 0):
logging.info("Performing B8 drill-down...")
# ... existing B8 logic ...
```
**Motivazione:** Permette di replicare il comportamento target2 quando necessario, ma mantiene la logica ottimizzata come default.
---
### PRIORITÀ BASSA (Nice to have)
#### Modifica 5: Documentare differenza force check
**File:** `GRIFO_M_PBIT.py` docstring
**Aggiungere nota:**
```python
"""
...
Configuration Options:
FORCE_B8_DRILL_DOWN: If True, always perform B8 drill-down even when only
known failures are detected (matches target2 behavior
for complete SW requirement verification).
...
"""
```
---
## 8. CHECKLIST PRE-DEPLOYMENT
Prima di considerare le modifiche complete:
- [ ] Implementata Modifica 1 (wait_before in power functions)
- [ ] Implementata Modifica 2 (wait_before nelle chiamate)
- [ ] Testato in simulation mode con nuove modifiche
- [ ] Testato su hardware (se disponibile) con nuove modifiche
- [ ] Verificato che KNOWN_FAILURES funzioni correttamente
- [ ] Verificato che CSV export funzioni
- [ ] Verificato che PDF report sia generato
- [ ] Verificato retrocompatibilità con script esistenti
- [ ] Valutato se implementare FORCE_B8_DRILL_DOWN
- [ ] Testato timeout PBIT (180 vs 182 secondi)
---
## 9. ANALISI RISCHI
### Rischio 1: wait_before Timing
**Probabilità:** Bassa
**Impatto:** Medio
**Mitigazione:** Test estensivo con timing diversi. Default 0 mantiene comportamento attuale.
### Rischio 2: Force Check B8
**Probabilità:** Bassa
**Impatto:** Basso
**Mitigazione:** Flag configurabile permette di abilitare solo se necessario.
### Rischio 3: Timeout PBIT
**Probabilità:** Media
**Impatto:** Alto (test fallisce prematuramente)
**Mitigazione:** Monitorare log per timeout reali, aumentare se necessario.
---
## 10. CONCLUSIONI
### Modifiche Essenziali (MUST HAVE):
1. ✅ Aggiungere parametro `wait_before` alle funzioni power
2. ✅ Usare `power_grifo_off(4, 1)` come in target2
### Modifiche Opzionali (NICE TO HAVE):
3. ⚠️ Valutare `PBIT_SEC_TIME = 182` vs 180
4. ⚠️ Implementare flag `FORCE_B8_DRILL_DOWN`
### Features da Mantenere:
- Sistema Known Failures
- Statistiche aggregate
- Export CSV
- Report PDF avanzato
- Simulation mode
- GUI launcher
- Tracking seriale
### Verdetto Finale:
La versione corrente è **significativamente più avanzata** di target2. Le uniche modifiche critiche da riportare sono i timing di power cycling (`wait_before`). Tutto il resto sono features nuove che target2 non ha e che dobbiamo preservare.
---
## ALLEGATI
### A. Differenze Dimensionali
| File | Target2 (righe) | Corrente (righe) | Delta |
|------|----------------|------------------|-------|
| GRIFO_M_PBIT.py | 379 | 1250 | +871 |
| leo_grifo_terminal.py | 48 | 126 | +78 |
| leo_grifo_1553.py | 148 | 211 | +63 |
| leo_grifo_io_box.py | 78 | 78 | 0 |
| test_common_function.py | ~85 | ~85 | 0 |
### B. Files Presenti Solo in Target2
- `brainbox_interface - Copia.py` (backup file, ignorare)
- `GRIFO_M_PBIT - Copia.py` (backup file, ignorare)
- `GRIFO_M_PBIT - Copia (2).py` (backup file, ignorare)
- `GRIFO_M_PBIT.py.bak` (backup file, ignorare)
- Log files (runtime artifacts)
### C. Files Presenti Solo in Versione Corrente
- `GRIFO_M_PBIT_mock.py` (simulation support)
- `GRIFO_M_PBIT_gui.py` (GUI launcher)
- `GRIFO_M_PBIT_simulate_launcher.py` (simulation wrapper)
- `test_lazy_proxy.py` (unit test)
- `LAZY_INITIALIZATION_GUIDE.md` (documentation)
- `IMPLEMENTATION_SUMMARY.md` (documentation)
---
**Fine Analisi**
Data: 2 Febbraio 2026
Revisione: 1.0