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:
@@ -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"),
|
||||
|
||||
@@ -23,3 +23,20 @@ func TestLatestWeakWordsUsesNewestScorePerWord(t *testing.T) {
|
||||
t.Fatalf("latest scores should clear water and keep coffee/please weak, got %#v", weak)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLatestWeakPhonemesUsesNewestScoredAttempt(t *testing.T) {
|
||||
attempts := []domain.Attempt{
|
||||
{WordScores: []domain.WordScore{
|
||||
{Word: "Water", PhonemeScores: []domain.PhonemeScore{{Phoneme: "w", Accuracy: 100}, {Phoneme: "t", Accuracy: 61}, {Phoneme: "t", Accuracy: 55}}},
|
||||
}},
|
||||
{WordScores: []domain.WordScore{
|
||||
{Word: "water", PhonemeScores: []domain.PhonemeScore{{Phoneme: "w", Accuracy: 42}, {Phoneme: "t", Accuracy: 95}}},
|
||||
{Word: "tea", PhonemeScores: []domain.PhonemeScore{{Phoneme: "iː", Accuracy: 68}}},
|
||||
{Word: "missed", ErrorType: "Omission", PhonemeScores: []domain.PhonemeScore{{Phoneme: "m", Accuracy: 0}}},
|
||||
}},
|
||||
}
|
||||
weak := latestWeakPhonemes(attempts)
|
||||
if len(weak) != 2 || weak[0].Phoneme != "t" || weak[0].Accuracy != 55 || weak[1].Word != "tea" {
|
||||
t.Fatalf("newer /w/ success should clear old weakness; latest /t/ and /iː/ should remain, got %#v", weak)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user