Flowise-Übungen stabilisieren und Lernfortschritt korrigieren
Vermeide kürzlich angezeigte Sätze bei neuen Übungen und frage Flowise bei Wiederholungen einmal erneut. Validiere strukturierte Antworten, protokolliere die Übungsquelle und schütze nutzerspezifische Übungs-IDs. Berechne schwierige Wörter anhand der neuesten Aussprache pro Wort. Passe das Lehrerfeedback an gute Bewertungen an und verbessere das Laden neuer Übungen im Web. Ergänze gezielte Go-Tests.
This commit is contained in:
@@ -83,7 +83,7 @@ func (s *PostgresStore) SaveGeneratedExercise(ctx context.Context, userID string
|
||||
return domain.Lesson{}, domain.Exercise{}, err
|
||||
}
|
||||
exercise := domain.Exercise{
|
||||
ID: valueOr(generated.ID, NewID("exg")),
|
||||
ID: NewID("exg"),
|
||||
LessonID: lesson.ID,
|
||||
TargetLanguage: targetLanguage,
|
||||
CEFRLevel: cefrLevel,
|
||||
@@ -103,21 +103,6 @@ func (s *PostgresStore) SaveGeneratedExercise(ctx context.Context, userID string
|
||||
success_criteria_json, reason_for_choice, agent_context_json
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'flowise', $9, $10, $11, $12, $13, $14)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
lesson_id = EXCLUDED.lesson_id,
|
||||
target_language = EXCLUDED.target_language,
|
||||
cefr_level = EXCLUDED.cefr_level,
|
||||
type = EXCLUDED.type,
|
||||
prompt_text = EXCLUDED.prompt_text,
|
||||
target_text = EXCLUDED.target_text,
|
||||
difficulty = EXCLUDED.difficulty,
|
||||
source = EXCLUDED.source,
|
||||
created_by_user_id = EXCLUDED.created_by_user_id,
|
||||
tts_text = EXCLUDED.tts_text,
|
||||
focus_points_json = EXCLUDED.focus_points_json,
|
||||
success_criteria_json = EXCLUDED.success_criteria_json,
|
||||
reason_for_choice = EXCLUDED.reason_for_choice,
|
||||
agent_context_json = EXCLUDED.agent_context_json
|
||||
RETURNING id, lesson_id, target_language, cefr_level, type, prompt_text, target_text, difficulty, source
|
||||
`, exercise.ID, exercise.LessonID, exercise.TargetLanguage, exercise.CEFRLevel, exercise.Type,
|
||||
exercise.PromptText, exercise.TargetText, exercise.Difficulty, userID, generated.TTSText,
|
||||
@@ -289,7 +274,7 @@ func (s *PostgresStore) GetLanguage(ctx context.Context, code string) (domain.La
|
||||
return lang, nil
|
||||
}
|
||||
|
||||
func (s *PostgresStore) NextLessonAndExercise(ctx context.Context, profile domain.LearnerProfile) (domain.Lesson, domain.Exercise, error) {
|
||||
func (s *PostgresStore) NextLessonAndExercise(ctx context.Context, profile domain.LearnerProfile, avoidReferenceText ...string) (domain.Lesson, domain.Exercise, error) {
|
||||
var lesson domain.Lesson
|
||||
var exercise domain.Exercise
|
||||
row := s.db.QueryRowContext(ctx, `
|
||||
@@ -299,14 +284,18 @@ func (s *PostgresStore) NextLessonAndExercise(ctx context.Context, profile domai
|
||||
FROM exercises e
|
||||
JOIN lessons l ON l.id = e.lesson_id
|
||||
WHERE e.target_language = $1 AND e.cefr_level = $2
|
||||
AND (COALESCE(e.source, 'seed') = 'seed' OR e.created_by_user_id = $3)
|
||||
AND COALESCE(e.source, 'seed') = 'seed'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM jsonb_array_elements_text($4::jsonb) AS avoided(sentence)
|
||||
WHERE lower(trim(avoided.sentence)) = lower(trim(e.target_text))
|
||||
)
|
||||
ORDER BY (
|
||||
SELECT COUNT(*)
|
||||
FROM attempts a
|
||||
WHERE a.exercise_id = e.id AND a.user_id = $3
|
||||
), e.difficulty, e.id
|
||||
LIMIT 1
|
||||
`, profile.TargetLanguage, profile.CEFRLevel, profile.UserID)
|
||||
`, profile.TargetLanguage, profile.CEFRLevel, profile.UserID, mustJSON(avoidReferenceText))
|
||||
if err := row.Scan(
|
||||
&lesson.ID, &lesson.TargetLanguage, &lesson.CEFRLevel, &lesson.Topic, &lesson.Title,
|
||||
&exercise.ID, &exercise.LessonID, &exercise.TargetLanguage, &exercise.CEFRLevel, &exercise.Type,
|
||||
@@ -320,13 +309,13 @@ func (s *PostgresStore) NextLessonAndExercise(ctx context.Context, profile domai
|
||||
return lesson, exercise, nil
|
||||
}
|
||||
|
||||
func (s *PostgresStore) GetExercise(ctx context.Context, id string) (domain.Exercise, error) {
|
||||
func (s *PostgresStore) GetExercise(ctx context.Context, id, userID string) (domain.Exercise, error) {
|
||||
var e domain.Exercise
|
||||
row := s.db.QueryRowContext(ctx, `
|
||||
SELECT id, lesson_id, target_language, cefr_level, type, prompt_text, target_text, difficulty, COALESCE(source, 'seed')
|
||||
FROM exercises
|
||||
WHERE id = $1
|
||||
`, id)
|
||||
WHERE id = $1 AND (COALESCE(source, 'seed') = 'seed' OR created_by_user_id = $2)
|
||||
`, id, userID)
|
||||
if err := row.Scan(&e.ID, &e.LessonID, &e.TargetLanguage, &e.CEFRLevel, &e.Type, &e.PromptText, &e.TargetText, &e.Difficulty, &e.Source); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return domain.Exercise{}, ErrNotFound
|
||||
@@ -393,26 +382,38 @@ func (s *PostgresStore) Progress(ctx context.Context, userID string, limit int)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
weakByWord := map[string]domain.WordScore{}
|
||||
for rows.Next() {
|
||||
attempt, err := scanAttempt(rows)
|
||||
if err != nil {
|
||||
return domain.ProgressSummary{}, err
|
||||
}
|
||||
summary.RecentAttempts = append(summary.RecentAttempts, attempt)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return domain.ProgressSummary{}, err
|
||||
}
|
||||
summary.WeakWords = latestWeakWords(summary.RecentAttempts)
|
||||
return summary, nil
|
||||
}
|
||||
|
||||
// RecentAttempts are ordered newest first. A newer successful score clears an
|
||||
// older weak score for the same word within the progress window.
|
||||
func latestWeakWords(attempts []domain.Attempt) []domain.WordScore {
|
||||
seen := make(map[string]bool)
|
||||
var weak []domain.WordScore
|
||||
for _, attempt := range attempts {
|
||||
for _, word := range attempt.WordScores {
|
||||
key := strings.ToLower(strings.TrimSpace(word.Word))
|
||||
if key == "" || seen[key] {
|
||||
continue
|
||||
}
|
||||
seen[key] = true
|
||||
if word.Accuracy < 75 {
|
||||
existing, ok := weakByWord[strings.ToLower(word.Word)]
|
||||
if !ok || word.Accuracy < existing.Accuracy {
|
||||
weakByWord[strings.ToLower(word.Word)] = word
|
||||
}
|
||||
weak = append(weak, word)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, word := range weakByWord {
|
||||
summary.WeakWords = append(summary.WeakWords, word)
|
||||
}
|
||||
return summary, rows.Err()
|
||||
return weak
|
||||
}
|
||||
|
||||
func (s *PostgresStore) CreateConversationSession(ctx context.Context, userID, targetLanguage, cefrLevel string) (domain.ConversationSession, error) {
|
||||
|
||||
Reference in New Issue
Block a user