From 538b9b0e6f3a0899d7127f9bd611b878d70f521a Mon Sep 17 00:00:00 2001 From: gtitov Date: Sat, 29 Apr 2023 11:17:40 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=84add=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index fc442c9..61554d7 100644 --- a/main.py +++ b/main.py @@ -64,6 +64,11 @@ def check_answers(student_answers: dict): @app.get("/check_questions") def check_questions(): + """Проверка вопросов на 1) наличие уникального идентификатора вопроса, 2) наличие правильного варианта ответа для вопросов с вариантами ответа + + Returns: + Сообщение о корректности / некорректности вопросов + """ unique_ids = [] errors = [] for q in all_questions: @@ -80,6 +85,11 @@ def check_questions(): @app.get("/hostip") def show_host_ip(): + """Возвращает IP-адрес компьютера, на котором запущен сервер тестирования, — к этому IP-адресу нужно подключаться с компьютеров пользователей + + Returns: + IP-адрес + """ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.settimeout(0) try: @@ -94,18 +104,23 @@ def show_host_ip(): @app.get("/students") def show_students(): + """Список студентов + + Returns: + JSON со списком студентов + """ return students @app.get("/get_quiz") def get_quiz(student_id, student: str): - """Get json-like quiz + """Получить JSON с тестом Args: - student_id (int): indentificator of a student - student (str): student name + student_id (int): идентификатор студента + student (str): имя студента Returns: - obj: json-like quiz + obj: JSON с тестом """ quiz_length = QUIZ_LENGTH questions_for_student = random.sample(quiz_questions, len(quiz_questions))[:quiz_length] # random order and only first n questions @@ -120,13 +135,13 @@ def get_quiz(student_id, student: str): @app.post("/save_student_answers") def send_student_answers(student_answers: str = Body()): - """Save answers as-is and check answers + """Сохранить ответы студента как есть (./answers/...) и сохранить проверенные ответы студента (./results/...) Args: - student_answers (str): json-like string with student's answers + student_answers (str): JSON с ответами студента Returns: - str: student name + str: имя студента """ json_answers = json.loads(student_answers) timestamp_str = datetime.now().strftime("%Y-%m-%dT%H-%M-%S") @@ -142,10 +157,10 @@ def send_student_answers(student_answers: str = Body()): @app.get("/end_quiz") def end_test(password: str): - """End test and save results to csv + """Сохранить результаты из файлов JSON в папке ./results в файл CSV Args: - password (str): password to end test + password (str): пароль для "окончания теста" """ if password == END_TEST_PASSWORD: csv_string = "student,percent,start,end\n"