77
88from __future__ import annotations
99
10+ import random
1011from typing import Any
1112
13+ from app .lessons_13_25 import LESSONS_13_25
14+
15+ TERM_SYNONYMS = {
16+ "sorted" : ("сортировка" ,),
17+ "арифметический оператор" : ("арифметика" , "оператор" ),
18+ "оператор %" : ("%" , "остаток" ),
19+ "оператор and" : ("and" , "логическое и" ),
20+ "срез" : ("slice" , "срез строки" ),
21+ "метод replace" : ("replace" , "замена" ),
22+ "метод join" : ("join" , "соединение строк" ),
23+ "f-строка" : ("f string" , "форматированная строка" ),
24+ "кортеж" : ("tuple" ,),
25+ "распаковка" : ("unpacking" ,),
26+ "append" : ("метод append" , "добавление в список" ),
27+ }
28+
1229
1330def _theory (title : str , text : str , example : str , tip : str = "" ) -> dict [str , str ]:
1431 return {"title" : title , "text" : text , "example" : example , "tip" : tip }
@@ -1389,21 +1406,24 @@ def _make_questions(
13891406) -> list [dict [str , Any ]]:
13901407 _ , title , subtitle , keyword , example , concept , _ = lesson_spec
13911408 code_task = _code_task (task_kind )
1409+ choice_id = f"{ lesson_id } -choice"
1410+ options = [example , "print('Сначала пишем код, потом думаем')" , "value = input() + 1" ]
1411+ random .Random (f"{ lesson_id } :{ choice_id } " ).shuffle (options )
13921412 return [
13931413 {
1394- "id" : f" { lesson_id } -choice" ,
1414+ "id" : choice_id ,
13951415 "kind" : "choice" ,
13961416 "prompt" : f"Какой пример относится к теме «{ title } »?" ,
1397- "options" : [ example , "print('Сначала пишем код, потом думаем')" , "value = input() + 1" ] ,
1417+ "options" : options ,
13981418 "answer" : example ,
13991419 "explanation" : concept ,
14001420 },
14011421 {
14021422 "id" : f"{ lesson_id } -term" ,
14031423 "kind" : "input" ,
14041424 "prompt" : f"Какой ключевой инструмент или термин связывает урок «{ title } »?" ,
1405- "answers" : [keyword ],
1406- "placeholder" : "Например: словарь " ,
1425+ "answers" : [keyword , * TERM_SYNONYMS . get ( keyword , ()) ],
1426+ "placeholder" : "Введите термин " ,
14071427 "explanation" : f"Ключевой ориентир урока — «{ keyword } ». { subtitle } ." ,
14081428 },
14091429 {"id" : f"{ lesson_id } -code" , "kind" : "code" , ** code_task },
@@ -1429,11 +1449,10 @@ def build_extended_course() -> tuple[
14291449 "icon" : unit ["icon" ],
14301450 }
14311451 )
1432- question_ids : list [str ] = []
1452+ question_ids_by_kind : dict [ str , list [str ]] = { "choice" : [], "input" : [], "code" : []}
14331453 for lesson_index , spec in enumerate (unit ["lessons" ]):
14341454 slug , title , subtitle , keyword , example , concept , advice = spec
14351455 lesson_id = f"{ module_id } -{ slug } "
1436- question_ids .append (f"{ lesson_id } -choice" )
14371456 if order >= 26 :
14381457 questions = _make_questions (lesson_id , spec , TASK_CYCLES [unit_index ][lesson_index ])
14391458 lessons .append (
@@ -1462,10 +1481,31 @@ def build_extended_course() -> tuple[
14621481 "questions" : questions ,
14631482 }
14641483 )
1484+ else :
1485+ questions = next (lesson for lesson in LESSONS_13_25 if lesson ["id" ] == lesson_id )[
1486+ "questions"
1487+ ]
1488+ for question in questions :
1489+ question_ids_by_kind [question ["kind" ]].append (question ["id" ])
14651490 order += 1
1491+ question_ids = [
1492+ random .Random (f"{ module_id } :{ kind } " ).choice (ids )
1493+ for kind , ids in question_ids_by_kind .items ()
1494+ if ids
1495+ ]
1496+ remaining_ids = [
1497+ question_id
1498+ for ids in question_ids_by_kind .values ()
1499+ for question_id in ids
1500+ if question_id not in question_ids
1501+ ]
1502+ random .Random (f"{ module_id } :exam" ).shuffle (remaining_ids )
1503+ if remaining_ids :
1504+ question_ids .append (remaining_ids [0 ])
1505+ random .Random (f"{ module_id } :exam-order" ).shuffle (question_ids )
14661506 exams [module_id ] = {
14671507 "title" : f"Контрольная точка: { unit ['title' ]} " ,
1468- "description" : f"Четыре коротких вопроса по разделу «{ unit ['title' ]} »." ,
1508+ "description" : f"Четыре вопроса разных типов по разделу «{ unit ['title' ]} »." ,
14691509 "question_ids" : question_ids ,
14701510 }
14711511 return modules , lessons , exams
0 commit comments