Phonembewertung speichern und anzeigen

Azure-Phonemwerte in Versuchen sichern, schwache Laute im Fortschritt und Flowise-Kontext auswerten und die Web-Anzeige ergänzen. README dokumentiert Datenfluss, Betrieb und Grenzen der Funktion.
This commit is contained in:
Eugenius Naumenko
2026-10-10 17:59:44 +00:00
parent bac840e091
commit 82d8768a99
13 changed files with 451 additions and 59 deletions
+53
View File
@@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
"speech-learning-api/internal/domain"
@@ -393,6 +394,7 @@ func (s *PostgresStore) Progress(ctx context.Context, userID string, limit int)
return domain.ProgressSummary{}, err
}
summary.WeakWords = latestWeakWords(summary.RecentAttempts)
summary.WeakPhonemes = latestWeakPhonemes(summary.RecentAttempts)
return summary, nil
}
@@ -416,6 +418,57 @@ func latestWeakWords(attempts []domain.Attempt) []domain.WordScore {
return weak
}
// Keep the newest scored occurrence for each word and phoneme. Within one
// attempt, use the lowest score if the same sound occurs more than once.
func latestWeakPhonemes(attempts []domain.Attempt) []domain.WeakPhoneme {
seen := make(map[string]bool)
var weak []domain.WeakPhoneme
for _, attempt := range attempts {
current := make(map[string]domain.WeakPhoneme)
for _, word := range attempt.WordScores {
if strings.EqualFold(word.ErrorType, "Omission") {
continue
}
wordKey := strings.ToLower(strings.TrimSpace(word.Word))
if wordKey == "" {
continue
}
for _, phoneme := range word.PhonemeScores {
name := strings.TrimSpace(phoneme.Phoneme)
if name == "" {
continue
}
key := wordKey + "\x00" + name
if seen[key] {
continue
}
if previous, ok := current[key]; !ok || phoneme.Accuracy < previous.Accuracy {
current[key] = domain.WeakPhoneme{Word: word.Word, Phoneme: name, Accuracy: phoneme.Accuracy}
}
}
}
for key, score := range current {
seen[key] = true
if score.Accuracy < 75 {
weak = append(weak, score)
}
}
}
sort.Slice(weak, func(i, j int) bool {
if weak[i].Accuracy == weak[j].Accuracy {
if weak[i].Word == weak[j].Word {
return weak[i].Phoneme < weak[j].Phoneme
}
return weak[i].Word < weak[j].Word
}
return weak[i].Accuracy < weak[j].Accuracy
})
if len(weak) > 12 {
weak = weak[:12]
}
return weak
}
func (s *PostgresStore) CreateConversationSession(ctx context.Context, userID, targetLanguage, cefrLevel string) (domain.ConversationSession, error) {
session := domain.ConversationSession{
ID: NewID("con"),