feat(words): единый источник csv_words — wordquiz, bubblewords, pronunciation + CRUD
This commit is contained in:
+13
-20
@@ -32,23 +32,20 @@ async def get_next_quiz(request: Request):
|
||||
async def pick_word(exclude, respect_exclude=True):
|
||||
if respect_exclude and exclude:
|
||||
placeholders = ",".join([f"${i+2}" for i in range(len(exclude))])
|
||||
# 🔧 ФИКС (30.09.2026): csv_words_source —
|
||||
# источник слов переехал с level_words (старая схема level_id IS NULL)
|
||||
# на csv_words (level_code). Один источник — CSV-база.
|
||||
return await conn.fetchrow(f"""
|
||||
SELECT word_pl, translation_ru, translation_uk, translation_en
|
||||
FROM (
|
||||
SELECT DISTINCT ON (word_pl) word_pl, translation_ru, translation_uk, translation_en
|
||||
FROM level_words
|
||||
WHERE level = $1 AND level_id IS NULL AND word_pl NOT IN ({placeholders})
|
||||
) AS unique_words
|
||||
FROM csv_words
|
||||
WHERE level_code = $1 AND word_pl NOT IN ({placeholders})
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 1
|
||||
""", current_level, *exclude)
|
||||
return await conn.fetchrow("""
|
||||
SELECT word_pl, translation_ru, translation_uk, translation_en
|
||||
FROM (
|
||||
SELECT DISTINCT ON (word_pl) word_pl, translation_ru, translation_uk, translation_en
|
||||
FROM level_words
|
||||
WHERE level = $1 AND level_id IS NULL
|
||||
) AS unique_words
|
||||
FROM csv_words
|
||||
WHERE level_code = $1
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 1
|
||||
""", current_level)
|
||||
@@ -67,25 +64,21 @@ async def get_next_quiz(request: Request):
|
||||
# Ищем неправильные варианты
|
||||
exclude_for_wrong = recent_words + [correct_polish]
|
||||
placeholders = ",".join([f"${i+3}" for i in range(len(exclude_for_wrong))])
|
||||
# 🔧 ФИКС (30.09.2026): csv_words_source — источник переведён на csv_words.
|
||||
wrong_words = await conn.fetch(f"""
|
||||
SELECT word_pl
|
||||
FROM (
|
||||
SELECT DISTINCT ON (word_pl) word_pl
|
||||
FROM level_words
|
||||
WHERE level = $1 AND level_id IS NULL AND word_pl != $2 AND word_pl NOT IN ({placeholders})
|
||||
) AS unique_wrong
|
||||
FROM csv_words
|
||||
WHERE level_code = $1 AND word_pl != $2 AND word_pl NOT IN ({placeholders})
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 5
|
||||
""", current_level, correct_polish, *exclude_for_wrong)
|
||||
|
||||
if len(wrong_words) < 2:
|
||||
# 🔧 ФИКС (30.09.2026): csv_words_source — fallback тоже на csv_words.
|
||||
wrong_words = await conn.fetch("""
|
||||
SELECT word_pl
|
||||
FROM (
|
||||
SELECT DISTINCT ON (word_pl) word_pl
|
||||
FROM level_words
|
||||
WHERE level = $1 AND level_id IS NULL AND word_pl != $2
|
||||
) AS unique_wrong
|
||||
FROM csv_words
|
||||
WHERE level_code = $1 AND word_pl != $2
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 5
|
||||
""", current_level, correct_polish)
|
||||
|
||||
Reference in New Issue
Block a user