-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersonality_update_helper.go
More file actions
62 lines (53 loc) · 1.58 KB
/
Copy pathpersonality_update_helper.go
File metadata and controls
62 lines (53 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (C) 2025-2026 Jose R F Junior <web2ajax@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-or-later
package main
import (
"context"
"log"
"time"
)
// updatePersonalityAfterConversation atualiza estado de personalidade após uma conversa
func (s *SignalingServer) updatePersonalityAfterConversation(idosoID int64) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Buscar última emoção detectada nas memórias recentes
memories, err := s.memoryStore.GetRecent(ctx, idosoID, 5)
if err != nil {
log.Printf("⚠️ [PERSONALITY] Erro ao buscar memórias: %v", err)
return
}
// Detectar emoção dominante
emotionCounts := make(map[string]int)
var topics []string
for _, mem := range memories {
if mem.Emotion != "" {
emotionCounts[mem.Emotion]++
}
topics = append(topics, mem.Topics...)
}
// Pegar emoção mais frequente
dominantEmotion := "neutro"
maxCount := 0
for emotion, count := range emotionCounts {
if count > maxCount {
maxCount = count
dominantEmotion = emotion
}
}
// Atualizar estado de personalidade
err = s.personalityService.UpdateAfterConversation(ctx, idosoID, dominantEmotion, topics)
if err != nil {
log.Printf("❌ [PERSONALITY] Erro ao atualizar: %v", err)
return
}
// Buscar estado atualizado para log
state, err := s.personalityService.GetState(ctx, idosoID)
if err == nil {
log.Printf("🧠 [PERSONALITY] Atualizado: Idoso %d - Nível %d/10 (%d conversas) - Emoção: %s",
idosoID,
state.RelationshipLevel,
state.ConversationCount,
state.DominantEmotion,
)
}
}