Initial commit
This commit is contained in:
323
archive/old_docs/REFONTE_DETECTION_WORKFLOWS.md
Normal file
323
archive/old_docs/REFONTE_DETECTION_WORKFLOWS.md
Normal file
@@ -0,0 +1,323 @@
|
||||
# 🔄 Refonte : Détection de Workflows Complets
|
||||
|
||||
## 🎯 Objectif
|
||||
|
||||
Transformer le système d'un détecteur de **micro-patterns** (3 clics identiques) en un détecteur de **macro-workflows** (séquences d'actions répétées).
|
||||
|
||||
## ❌ Problème Actuel
|
||||
|
||||
### Ce qui est implémenté
|
||||
```python
|
||||
# EventCapture détecte :
|
||||
Clic A, Clic A, Clic A → Pattern détecté ✅
|
||||
```
|
||||
|
||||
**Problème** : Personne ne clique 3 fois sur le même bouton dans la vraie vie !
|
||||
|
||||
### Ce qu'il faut
|
||||
```python
|
||||
# Détecter des workflows :
|
||||
Jour 1: [Ouvre App → Clic Menu → Type Texte → Sauvegarde]
|
||||
Jour 2: [Ouvre App → Clic Menu → Type Texte → Sauvegarde]
|
||||
Jour 3: [Ouvre App → Clic Menu → Type Texte → Sauvegarde]
|
||||
→ Workflow détecté ✅
|
||||
```
|
||||
|
||||
## ✅ Solution : Workflow Pattern Detector
|
||||
|
||||
### 1. Nouvelle Architecture
|
||||
|
||||
```
|
||||
EventCapture (capture toutes les actions)
|
||||
↓
|
||||
WorkflowBuffer (garde les N dernières actions)
|
||||
↓
|
||||
WorkflowDetector (détecte les séquences répétées)
|
||||
↓
|
||||
WorkflowManager (crée et gère les workflows)
|
||||
↓
|
||||
SuggestionManager (suggère le workflow suivant)
|
||||
```
|
||||
|
||||
### 2. Algorithme de Détection
|
||||
|
||||
#### Étape 1 : Segmentation Temporelle
|
||||
```python
|
||||
# Diviser les actions en "sessions"
|
||||
# Une session = actions dans une fenêtre de temps (ex: 5 minutes)
|
||||
|
||||
Session 1: [Action1, Action2, Action3, Action4] # 10h00-10h05
|
||||
Session 2: [Action5, Action6, Action7] # 10h30-10h35
|
||||
Session 3: [Action8, Action9, Action10, Action11] # 11h00-11h05
|
||||
```
|
||||
|
||||
#### Étape 2 : Comparaison de Séquences
|
||||
```python
|
||||
# Comparer les sessions pour trouver des similarités
|
||||
|
||||
def compare_sessions(session1, session2):
|
||||
# Utiliser la distance de Levenshtein sur les embeddings
|
||||
# Ou DTW (Dynamic Time Warping)
|
||||
# Ou similarité cosinus entre séquences
|
||||
|
||||
similarity = calculate_sequence_similarity(session1, session2)
|
||||
return similarity > threshold # ex: 0.75
|
||||
```
|
||||
|
||||
#### Étape 3 : Détection de Répétition
|
||||
```python
|
||||
# Si 3 sessions similaires → Workflow détecté
|
||||
|
||||
if count_similar_sessions() >= 3:
|
||||
workflow = create_workflow(sessions)
|
||||
save_workflow(workflow)
|
||||
notify_user("Workflow détecté !")
|
||||
```
|
||||
|
||||
### 3. Structure de Données
|
||||
|
||||
#### Workflow
|
||||
```python
|
||||
@dataclass
|
||||
class Workflow:
|
||||
workflow_id: str
|
||||
name: str # "Ouvrir OnlyOffice et créer document"
|
||||
steps: List[WorkflowStep]
|
||||
repetitions: int # Nombre de fois observé
|
||||
confidence: float
|
||||
last_seen: datetime
|
||||
|
||||
@dataclass
|
||||
class WorkflowStep:
|
||||
step_id: int
|
||||
action_type: str # "click", "type", "scroll"
|
||||
target_description: str # "Bouton Nouveau Document"
|
||||
screenshot: np.ndarray
|
||||
embedding: np.ndarray
|
||||
position: Tuple[int, int]
|
||||
window: str
|
||||
```
|
||||
|
||||
### 4. Détection en Temps Réel
|
||||
|
||||
```python
|
||||
class WorkflowDetector:
|
||||
def __init__(self):
|
||||
self.action_buffer = deque(maxlen=100) # 100 dernières actions
|
||||
self.sessions = []
|
||||
self.known_workflows = []
|
||||
|
||||
def on_action(self, action):
|
||||
# Ajouter l'action au buffer
|
||||
self.action_buffer.append(action)
|
||||
|
||||
# Vérifier si on doit créer une nouvelle session
|
||||
if self.should_start_new_session(action):
|
||||
self.finalize_current_session()
|
||||
self.start_new_session()
|
||||
|
||||
# Ajouter l'action à la session courante
|
||||
self.current_session.append(action)
|
||||
|
||||
# Vérifier si on détecte un workflow
|
||||
if len(self.sessions) >= 3:
|
||||
workflow = self.detect_workflow()
|
||||
if workflow:
|
||||
self.on_workflow_detected(workflow)
|
||||
|
||||
def should_start_new_session(self, action):
|
||||
# Nouvelle session si :
|
||||
# - Plus de 5 minutes depuis la dernière action
|
||||
# - Changement de fenêtre majeur
|
||||
# - Action de "fin" (fermeture, sauvegarde)
|
||||
|
||||
if not self.current_session:
|
||||
return True
|
||||
|
||||
last_action = self.current_session[-1]
|
||||
time_gap = action.timestamp - last_action.timestamp
|
||||
|
||||
return (
|
||||
time_gap > timedelta(minutes=5) or
|
||||
action.window != last_action.window or
|
||||
action.action_type in ["close", "save"]
|
||||
)
|
||||
|
||||
def detect_workflow(self):
|
||||
# Comparer les 3 dernières sessions
|
||||
recent_sessions = self.sessions[-3:]
|
||||
|
||||
# Calculer la similarité entre elles
|
||||
sim_01 = self.compare_sessions(recent_sessions[0], recent_sessions[1])
|
||||
sim_12 = self.compare_sessions(recent_sessions[1], recent_sessions[2])
|
||||
sim_02 = self.compare_sessions(recent_sessions[0], recent_sessions[2])
|
||||
|
||||
avg_similarity = (sim_01 + sim_12 + sim_02) / 3
|
||||
|
||||
if avg_similarity > 0.75:
|
||||
# Créer le workflow
|
||||
return self.create_workflow_from_sessions(recent_sessions)
|
||||
|
||||
return None
|
||||
|
||||
def compare_sessions(self, session1, session2):
|
||||
# Utiliser DTW (Dynamic Time Warping) pour comparer
|
||||
# les séquences d'embeddings
|
||||
|
||||
embeddings1 = [action.embedding for action in session1]
|
||||
embeddings2 = [action.embedding for action in session2]
|
||||
|
||||
distance = dtw_distance(embeddings1, embeddings2)
|
||||
similarity = 1 / (1 + distance)
|
||||
|
||||
return similarity
|
||||
```
|
||||
|
||||
### 5. Suggestion de Workflow
|
||||
|
||||
```python
|
||||
class WorkflowSuggestionManager:
|
||||
def check_for_workflow_suggestion(self, current_actions):
|
||||
# Vérifier si les actions actuelles correspondent
|
||||
# au début d'un workflow connu
|
||||
|
||||
for workflow in self.known_workflows:
|
||||
match_score = self.match_workflow_start(
|
||||
current_actions,
|
||||
workflow.steps
|
||||
)
|
||||
|
||||
if match_score > 0.75:
|
||||
# On est probablement au début du workflow !
|
||||
return {
|
||||
"workflow": workflow,
|
||||
"confidence": match_score,
|
||||
"next_steps": workflow.steps[len(current_actions):]
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
def match_workflow_start(self, current_actions, workflow_steps):
|
||||
# Comparer les N premières actions avec le début du workflow
|
||||
|
||||
if len(current_actions) > len(workflow_steps):
|
||||
return 0.0
|
||||
|
||||
similarities = []
|
||||
for i, action in enumerate(current_actions):
|
||||
step = workflow_steps[i]
|
||||
sim = cosine_similarity(action.embedding, step.embedding)
|
||||
similarities.append(sim)
|
||||
|
||||
return np.mean(similarities)
|
||||
```
|
||||
|
||||
## 📊 Exemple Concret
|
||||
|
||||
### Scénario : OnlyOffice
|
||||
|
||||
```python
|
||||
# Jour 1 - 10h00
|
||||
Session 1:
|
||||
1. Clic sur lanceur (embedding_1)
|
||||
2. Type "office" (embedding_2)
|
||||
3. Clic sur OnlyOffice (embedding_3)
|
||||
4. Clic "Nouveau document" (embedding_4)
|
||||
5. Type "Bonjour" (embedding_5)
|
||||
6. Clic "Fermer" (embedding_6)
|
||||
7. Clic "Non" (embedding_7)
|
||||
|
||||
# Jour 2 - 14h30
|
||||
Session 2:
|
||||
1. Clic sur lanceur (embedding_1') # Similaire à embedding_1
|
||||
2. Type "office" (embedding_2')
|
||||
3. Clic sur OnlyOffice (embedding_3')
|
||||
4. Clic "Nouveau document" (embedding_4')
|
||||
5. Type "Hello" (embedding_5') # Différent mais même type d'action
|
||||
6. Clic "Fermer" (embedding_6')
|
||||
7. Clic "Non" (embedding_7')
|
||||
|
||||
# Jour 3 - 16h00
|
||||
Session 3:
|
||||
1. Clic sur lanceur (embedding_1'')
|
||||
2. Type "office" (embedding_2'')
|
||||
3. Clic sur OnlyOffice (embedding_3'')
|
||||
4. Clic "Nouveau document" (embedding_4'')
|
||||
5. Type "Test" (embedding_5'')
|
||||
6. Clic "Fermer" (embedding_6'')
|
||||
7. Clic "Non" (embedding_7'')
|
||||
|
||||
# Détection
|
||||
compare_sessions(Session1, Session2) = 0.89
|
||||
compare_sessions(Session2, Session3) = 0.91
|
||||
compare_sessions(Session1, Session3) = 0.87
|
||||
|
||||
avg_similarity = 0.89 > 0.75 ✅
|
||||
|
||||
→ Workflow "Ouvrir OnlyOffice et créer document" détecté !
|
||||
```
|
||||
|
||||
### Jour 4 - Suggestion
|
||||
|
||||
```python
|
||||
# L'utilisateur commence
|
||||
Action 1: Clic sur lanceur
|
||||
Action 2: Type "office"
|
||||
|
||||
# Le système détecte
|
||||
match_score = match_workflow_start([Action1, Action2], Workflow.steps)
|
||||
match_score = 0.92 > 0.75 ✅
|
||||
|
||||
# Suggestion !
|
||||
"Je peux continuer ce workflow pour toi ?"
|
||||
[Oui] [Non] [Corriger]
|
||||
```
|
||||
|
||||
## 🔧 Implémentation
|
||||
|
||||
### Fichiers à Créer
|
||||
|
||||
1. `geniusia2/core/workflow_detector.py` - Détection de workflows
|
||||
2. `geniusia2/core/workflow_manager.py` - Gestion des workflows
|
||||
3. `geniusia2/core/session_manager.py` - Segmentation en sessions
|
||||
|
||||
### Fichiers à Modifier
|
||||
|
||||
1. `geniusia2/core/event_capture.py` - Intégrer WorkflowDetector
|
||||
2. `geniusia2/core/orchestrator.py` - Utiliser workflows au lieu de patterns
|
||||
3. `geniusia2/core/suggestion_manager.py` - Suggérer workflows complets
|
||||
|
||||
## 📈 Avantages
|
||||
|
||||
### Avant (Micro-Patterns)
|
||||
- ❌ Détecte seulement les clics répétés
|
||||
- ❌ Inutilisable en pratique
|
||||
- ❌ Ne correspond pas à l'usage réel
|
||||
|
||||
### Après (Macro-Workflows)
|
||||
- ✅ Détecte les workflows complets
|
||||
- ✅ Utilisable en pratique
|
||||
- ✅ Correspond à l'usage réel
|
||||
- ✅ Vrai RPA Vision !
|
||||
|
||||
## 🎯 Prochaines Étapes
|
||||
|
||||
1. **Implémenter WorkflowDetector** (3-4h)
|
||||
2. **Implémenter SessionManager** (2h)
|
||||
3. **Modifier EventCapture** (1h)
|
||||
4. **Tester avec ton workflow OnlyOffice** (1h)
|
||||
5. **Ajuster les seuils** (1h)
|
||||
|
||||
**Total** : ~8-10 heures de développement
|
||||
|
||||
## 💡 Note Importante
|
||||
|
||||
C'est un **changement majeur** mais **nécessaire** pour que le système soit vraiment utilisable !
|
||||
|
||||
Le système actuel est un MVP qui ne fonctionne que pour des cas d'usage artificiels.
|
||||
|
||||
Avec cette refonte, on aura un **vrai RPA Vision** qui apprend des workflows réels ! 🚀
|
||||
|
||||
---
|
||||
|
||||
**Veux-tu qu'on commence l'implémentation ?** 💪
|
||||
Reference in New Issue
Block a user