# Dashboard Phase 1 - Modifications AppliquĂ©es **Date**: 7 janvier 2026 - 22:45 **Objectif**: Corriger les chemins screenshots + rendre visibles les screen_states --- ## 📝 Modifications DĂ©taillĂ©es ### Modification 1 - Fix Chemin Screenshots (Liste Sessions) **Fichier**: `web_dashboard/app.py` **Ligne**: 206-210 **AVANT** : ```python # Compter les screenshots screenshots_dir = session_dir / "screenshots" screenshot_files = list(screenshots_dir.glob('*.png')) if screenshots_dir.exists() else [] ``` **APRÈS** : ```python # Compter les screenshots # Structure : sessions/{session_id}/{session_id}/shots/*.png session_id = session.session_id screenshots_dir = session_dir / session_id / "shots" screenshot_files = list(screenshots_dir.glob('*.png')) if screenshots_dir.exists() else [] ``` **Raison** : - La structure rĂ©elle est `sessions/sess_xxx/sess_xxx/shots/shot_0001.png` - L'ancien code cherchait dans `sessions/sess_xxx/screenshots/` (n'existe pas) - RĂ©sultat : **TOUJOURS 0 screenshots affichĂ©s** **Impact** : - ✅ Screenshots count sera correct pour les sessions non nettoyĂ©es - ✅ L'utilisateur voit le nombre rĂ©el de captures --- ### Modification 2 - Fix Chemin Screenshots (DĂ©tails Session) **Fichier**: `web_dashboard/app.py` **Ligne**: 251-261 **AVANT** : ```python screenshots_dir = session_dir / "screenshots" ``` **APRÈS** : ```python # Structure : sessions/{session_id}/{session_id}/shots/*.png screenshots_dir = session_dir / session_id / "shots" ``` **Impact** : - ✅ La modal "📾 Screenshots" affiche les vraies images - ✅ Les URLs sont correctement gĂ©nĂ©rĂ©es --- ### Modification 3 - Fix Route Get Screenshot **Fichier**: `web_dashboard/app.py` **Ligne**: 287-320 **AVANT** : ```python screenshot_path = session_dir / "screenshots" / filename ``` **APRÈS** : ```python # Essayer le chemin correct en premier : {session_id}/shots/ screenshot_path = session_dir / session_id / "shots" / filename if not screenshot_path.exists(): # Essayer l'ancien chemin pour compatibilitĂ© screenshot_path = session_dir / "screenshots" / filename if not screenshot_path.exists(): # Essayer dans les sous-dossiers (fallback) for subdir in session_dir.iterdir(): if subdir.is_dir(): # Essayer shots/ alt_path = subdir / "shots" / filename if alt_path.exists(): screenshot_path = alt_path break # Essayer screenshots/ alt_path = subdir / "screenshots" / filename if alt_path.exists(): screenshot_path = alt_path break if not screenshot_path.exists(): return jsonify({'error': 'Screenshot non trouvĂ© ou supprimĂ© aprĂšs traitement'}), 404 ``` **Raison** : - Cherche d'abord dans le bon chemin - Fallback sur l'ancien chemin (compatibilitĂ©) - Message d'erreur clair si supprimĂ© aprĂšs traitement **Impact** : - ✅ Images servies correctement - ✅ Message clair si screenshot supprimĂ© (aprĂšs cleanup) --- ### Modification 4 - NOUVELLE Route `/api/screen_states` **Fichier**: `web_dashboard/app.py` **Ligne**: 355-425 **Code ajoutĂ©** : ```python @app.route('/api/screen_states') def list_screen_states(): """Liste tous les screen states traitĂ©s.""" try: screen_states = [] screen_states_path = DATA_PATH / "screen_states" if not screen_states_path.exists(): return jsonify({'screen_states': [], 'total': 0}) # Parcourir tous les fichiers JSON dans screen_states/ for date_dir in screen_states_path.iterdir(): if not date_dir.is_dir(): continue for state_file in date_dir.glob('*.json'): try: with open(state_file, 'r') as f: state_data = json.load(f) screen_states.append({ 'screen_state_id': state_data.get('screen_state_id', state_file.stem), 'session_id': state_data.get('session_id', 'unknown'), 'timestamp': state_data.get('timestamp', ''), 'window': state_data.get('window', {}), 'tags': state_data.get('context', {}).get('tags', []), 'workflow_candidate': state_data.get('context', {}).get('current_workflow_candidate'), 'user_id': state_data.get('context', {}).get('user_id', 'unknown'), 'business_variables': state_data.get('context', {}).get('business_variables', {}), 'file_path': str(state_file), 'date': date_dir.name }) except Exception as e: print(f"Erreur lecture screen state {state_file}: {e}") continue # Trier par timestamp (plus rĂ©cent en premier) screen_states.sort(key=lambda x: x['timestamp'], reverse=True) # Grouper par session sessions_grouped = {} for state in screen_states: session_id = state['session_id'] if session_id not in sessions_grouped: sessions_grouped[session_id] = { 'session_id': session_id, 'screen_states': [], 'count': 0, 'first_timestamp': state['timestamp'], 'last_timestamp': state['timestamp'], 'tags': state['tags'], 'user_id': state['user_id'] } sessions_grouped[session_id]['screen_states'].append(state) sessions_grouped[session_id]['count'] += 1 return jsonify({ 'screen_states': screen_states, 'total': len(screen_states), 'sessions_grouped': list(sessions_grouped.values()), 'sessions_count': len(sessions_grouped) }) except Exception as e: return jsonify({'error': str(e)}), 500 ``` **FonctionnalitĂ©s** : - ✅ Liste TOUS les screen_states (236 actuellement) - ✅ Groupe par session - ✅ Retourne mĂ©tadonnĂ©es (tags, workflow candidate, user, etc.) - ✅ Tri par timestamp (plus rĂ©cent en premier) **RĂ©ponse JSON** : ```json { "screen_states": [...], "total": 236, "sessions_grouped": [ { "session_id": "sess_20260107T220743_6be50905", "count": 40, "screen_states": [...], "tags": ["Facturation_T2A_demo"], "user_id": "demo_user" } ], "sessions_count": 6 } ``` --- ### Modification 5 - NOUVELLE Route `/api/screen_states/` **Fichier**: `web_dashboard/app.py` **Ligne**: 428-462 **Code ajoutĂ©** : ```python @app.route('/api/screen_states/') def get_session_screen_states(session_id): """RĂ©cupĂšre tous les screen states d'une session.""" try: screen_states = [] screen_states_path = DATA_PATH / "screen_states" if not screen_states_path.exists(): return jsonify({'error': 'Screen states directory not found'}), 404 # Parcourir tous les fichiers JSON dans screen_states/ for date_dir in screen_states_path.iterdir(): if not date_dir.is_dir(): continue for state_file in date_dir.glob('*.json'): try: with open(state_file, 'r') as f: state_data = json.load(f) if state_data.get('session_id') == session_id: screen_states.append(state_data) except Exception as e: continue # Trier par timestamp screen_states.sort(key=lambda x: x.get('timestamp', '')) return jsonify({ 'session_id': session_id, 'screen_states': screen_states, 'total': len(screen_states) }) except Exception as e: return jsonify({'error': str(e)}), 500 ``` **FonctionnalitĂ©s** : - ✅ RĂ©cupĂšre tous les screen_states d'une session spĂ©cifique - ✅ Retourne les donnĂ©es COMPLÈTES (pas de rĂ©sumĂ©) - ✅ Tri chronologique --- ## ✅ VĂ©rifications Avant DĂ©ploiement ### RĂ©trocompatibilitĂ© - ✅ Aucune route existante n'a Ă©tĂ© SUPPRIMÉE - ✅ Les routes existantes fonctionnent toujours (avec chemins corrigĂ©s) - ✅ 2 nouvelles routes AJOUTÉES (pas de modification d'existantes) ### Pas de Breaking Changes - ✅ `/api/system/status` - INCHANGÉ - ✅ `/api/agent/sessions` - CHEMINS CORRIGÉS (amĂ©lioration) - ✅ `/api/agent/sessions/` - CHEMINS CORRIGÉS (amĂ©lioration) - ✅ `/api/agent/sessions//screenshot/` - CHEMINS CORRIGÉS (amĂ©lioration) - ✅ `/api/workflows` - INCHANGÉ - ✅ `/api/chains` - INCHANGÉ - ✅ `/api/triggers` - INCHANGÉ --- ## 📋 DĂ©ploiement ### Option 1 - Script Automatique (RecommandĂ©) ```bash cd /home/dom/ai/rpa_vision_v3 ./deploy_dashboard_fix.sh ``` ### Option 2 - Manuel ```bash # Sauvegarde sudo cp /opt/rpa_vision_v3/web_dashboard/app.py \ /opt/rpa_vision_v3/web_dashboard/app.py.backup_phase1_$(date +%Y%m%d_%H%M%S) # DĂ©ploiement sudo cp /home/dom/ai/rpa_vision_v3/web_dashboard_app.py \ /opt/rpa_vision_v3/web_dashboard/app.py sudo chown rpa:rpa /opt/rpa_vision_v3/web_dashboard/app.py sudo chmod 644 /opt/rpa_vision_v3/web_dashboard/app.py # RedĂ©marrage sudo systemctl restart rpa-vision-v3-dashboard.service # VĂ©rification systemctl status rpa-vision-v3-dashboard.service ``` --- ## đŸ§Ș Tests Post-DĂ©ploiement ### Test 1 - Nouvelle Route Screen States ```bash curl http://localhost:5001/api/screen_states | python3 -m json.tool | head -50 ``` **Attendu** : ```json { "total": 236, "sessions_count": 6, "screen_states": [...] } ``` ### Test 2 - Screenshots Count CorrigĂ© ```bash curl http://localhost:5001/api/agent/sessions | python3 -m json.tool | grep screenshots_count ``` **Attendu** : - Sessions non nettoyĂ©es : `"screenshots_count": 30` (ou autre nombre > 0) - Sessions nettoyĂ©es : `"screenshots_count": 0` (normal, supprimĂ©s aprĂšs traitement) ### Test 3 - Pas de RĂ©gression ```bash curl http://localhost:5001/api/system/status | python3 -m json.tool ``` **Attendu** : ```json { "status": "online", "sessions_count": 8, "workflows_count": 2, ... } ``` ### Test 4 - Dashboard Web Ouvrir dans le navigateur : `http://localhost:5001` **VĂ©rifier** : - ✅ Onglet "Sessions" affiche screenshots_count > 0 pour sessions non nettoyĂ©es - ✅ Aucune erreur JavaScript dans la console - ✅ Toutes les anciennes fonctionnalitĂ©s marchent --- ## 📊 Impact Utilisateur ### Avant Phase 1 - ❌ Screenshots count toujours Ă  0 - ❌ 236 screen_states invisibles - ❌ Impossible de voir les donnĂ©es traitĂ©es ### AprĂšs Phase 1 - ✅ Screenshots count correct - ✅ Nouvelle API `/api/screen_states` pour accĂ©der aux 236 screen_states - ✅ Groupement par session disponible - ✅ TOUTES les anciennes fonctionnalitĂ©s intactes --- ## 🚀 Prochaines Étapes (Phase 2) 1. **CrĂ©er onglet "DonnĂ©es TraitĂ©es" dans le dashboard** - Afficher les 236 screen_states - Grouper par session - Filtrage par date, user, tags 2. **Ajouter stats de processing** - Route `/api/processing/stats` - Afficher dans "Vue d'ensemble" 3. **Distinction Raw vs Processed** - Renommer "Sessions" → "Sessions Brutes" - Ajouter statut (🟡 Attente, 🟱 TraitĂ©, 🔮 Erreur) --- **Version** : 1.0 - Phase 1 ComplĂšte **Status** : ✅ PrĂȘt pour DĂ©ploiement