commit 7934a705fcb18c0497fa28bd7ccf6d6725dae134 Author: gtitov Date: Mon Jun 20 23:17:25 2022 +0300 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a145bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +.venv +scheme \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..705bc69 --- /dev/null +++ b/main.py @@ -0,0 +1,21 @@ +from fastapi import FastAPI +import json +import random + +app = FastAPI() + +with open("questions.json", "r", encoding="UTF-8") as f: + content = json.load(f) + questions_with_answers = content["questions"] + remove_keys = ["author", "answer", "topic"] + questions_without_answers = [{key: value for key, value in q.items() if key not in remove_keys} for q in questions_with_answers] + +@app.get("/") +def give_quiz(student: str): + quiz_questions = random.sample(questions_without_answers, len(questions_without_answers)) # questions selection would be more complicated + return { + "version": 1, + "student": student, + "attempt": 0, # TODO how to count attempts? + "questions": quiz_questions + } \ No newline at end of file diff --git a/pictures/teodolit.png b/pictures/teodolit.png new file mode 100644 index 0000000..95d3453 Binary files /dev/null and b/pictures/teodolit.png differ diff --git a/questions.json b/questions.json new file mode 100644 index 0000000..4aa957d --- /dev/null +++ b/questions.json @@ -0,0 +1,33 @@ +{ + "version": 1, + "questions": [ + { + "id": 1, + "topic": "теодолит", + "author": "GT", + "question": "Что такое теодолит?", + "picture": "pictures/teodolit.png", + "options": [ + "Прибор для измерения земли", + "Прибор для измерения углов", + "Прибор для измерения расстояний", + "Прибор для измерения высот" + ], + "answer": "Прибор для измерения углов" + }, + { + "id": 2, + "topic": "геометрия", + "author": "GT", + "question": "Сумма углов выпуклого пятиугольника составляет?", + "answer": 520 + }, + { + "id": 3, + "topic": "нивелир", + "author": "GT", + "question": "Как называется прибор для измерения превышений?", + "answer": "нивелир" + } + ] +} \ No newline at end of file diff --git a/students.json b/students.json new file mode 100644 index 0000000..6371f09 --- /dev/null +++ b/students.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "students": [ + { + "name": "Екатерина Александровна Щербацкая", + "professor": "Михаил Иванович Кознышев" + } + ] +} \ No newline at end of file