From 27befeb92bfe6693dad2c2c8691d21fdb53819a6 Mon Sep 17 00:00:00 2001 From: Play Life Bot Date: Fri, 2 Jan 2026 16:50:40 +0300 Subject: [PATCH] Refactor group 2 word selection: use (failure+1)/(success+1) ratio, bump version to 2.8.0 --- VERSION | 2 +- play-life-backend/main.go | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index a4dd9db..834f262 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.7.4 +2.8.0 diff --git a/play-life-backend/main.go b/play-life-backend/main.go index b533c96..6b5e83d 100644 --- a/play-life-backend/main.go +++ b/play-life-backend/main.go @@ -1123,7 +1123,7 @@ func (a *App) getTestWordsHandler(w http.ResponseWriter, r *http.Request) { group1WordIDs[word.ID] = true } - // Group 2: (failure - success) >= 5, sorted by (failure - success) DESC, then last_success_at ASC (NULL first) + // Group 2: sorted by (failure + 1)/(success + 1) DESC, take top 40% // Exclude words already in group1 group2Exclude := "" group2Args := make([]interface{}, 0) @@ -1142,15 +1142,14 @@ func (a *App) getTestWordsHandler(w http.ResponseWriter, r *http.Request) { group2Query := ` SELECT ` + baseSelect + ` ` + baseFrom + ` - AND (COALESCE(p.failure, 0) - COALESCE(p.success, 0)) >= 5 ` + group2Exclude + ` ORDER BY - (COALESCE(p.failure, 0) - COALESCE(p.success, 0)) DESC, + (COALESCE(p.failure, 0) + 1.0) / (COALESCE(p.success, 0) + 1.0) DESC, CASE WHEN p.last_success_at IS NULL THEN 0 ELSE 1 END, p.last_success_at ASC LIMIT $` + fmt.Sprintf("%d", len(group2Args)+1) - group2Args = append(group2Args, group2Count*2) // Get more to ensure uniqueness + group2Args = append(group2Args, group2Count) group2Rows, err := a.DB.Query(group2Query, group2Args...) if err != nil { sendErrorWithCORS(w, err.Error(), http.StatusInternalServerError) @@ -1160,7 +1159,7 @@ func (a *App) getTestWordsHandler(w http.ResponseWriter, r *http.Request) { group2Words := make([]Word, 0) group2WordIDs := make(map[int]bool) - for group2Rows.Next() && len(group2Words) < group2Count { + for group2Rows.Next() { var word Word var lastSuccess, lastFailure sql.NullString