Refactor group 2 word selection: use (failure+1)/(success+1) ratio, bump version to 2.8.0
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 35s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 35s
This commit is contained in:
@@ -1123,7 +1123,7 @@ func (a *App) getTestWordsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
group1WordIDs[word.ID] = true
|
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
|
// Exclude words already in group1
|
||||||
group2Exclude := ""
|
group2Exclude := ""
|
||||||
group2Args := make([]interface{}, 0)
|
group2Args := make([]interface{}, 0)
|
||||||
@@ -1142,15 +1142,14 @@ func (a *App) getTestWordsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
group2Query := `
|
group2Query := `
|
||||||
SELECT ` + baseSelect + `
|
SELECT ` + baseSelect + `
|
||||||
` + baseFrom + `
|
` + baseFrom + `
|
||||||
AND (COALESCE(p.failure, 0) - COALESCE(p.success, 0)) >= 5
|
|
||||||
` + group2Exclude + `
|
` + group2Exclude + `
|
||||||
ORDER BY
|
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,
|
CASE WHEN p.last_success_at IS NULL THEN 0 ELSE 1 END,
|
||||||
p.last_success_at ASC
|
p.last_success_at ASC
|
||||||
LIMIT $` + fmt.Sprintf("%d", len(group2Args)+1)
|
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...)
|
group2Rows, err := a.DB.Query(group2Query, group2Args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendErrorWithCORS(w, err.Error(), http.StatusInternalServerError)
|
sendErrorWithCORS(w, err.Error(), http.StatusInternalServerError)
|
||||||
@@ -1160,7 +1159,7 @@ func (a *App) getTestWordsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
group2Words := make([]Word, 0)
|
group2Words := make([]Word, 0)
|
||||||
group2WordIDs := make(map[int]bool)
|
group2WordIDs := make(map[int]bool)
|
||||||
for group2Rows.Next() && len(group2Words) < group2Count {
|
for group2Rows.Next() {
|
||||||
var word Word
|
var word Word
|
||||||
var lastSuccess, lastFailure sql.NullString
|
var lastSuccess, lastFailure sql.NullString
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user