2024-05-28 17:47:08 +03:00
|
|
|
from db.question import QuestionPool
|
|
|
|
|
|
|
|
class QuestionList:
|
|
|
|
def __init__(self, cursor):
|
|
|
|
self.cursor = cursor
|
|
|
|
|
|
|
|
def render(self, test_id = None):
|
|
|
|
qp = QuestionPool(self.cursor)
|
|
|
|
|
|
|
|
if test_id:
|
2024-06-01 13:49:13 +03:00
|
|
|
rendered_questions = [i.render_short(self.cursor) for i in qp.select_by_test_id(test_id)]
|
2024-05-28 17:47:08 +03:00
|
|
|
else:
|
2024-06-01 13:49:13 +03:00
|
|
|
rendered_questions = [i.render_short(self.cursor) for i in qp.iter()]
|
2024-05-28 17:47:08 +03:00
|
|
|
|
|
|
|
return "\n".join(rendered_questions)
|
2024-06-01 19:45:47 +03:00
|
|
|
|
|
|
|
def count(self):
|
|
|
|
qp = QuestionPool(self.cursor)
|
|
|
|
return len(qp.object_pool.pool)
|
|
|
|
|
|
|
|
def get_avg_time(self):
|
|
|
|
qp = QuestionPool(self.cursor)
|
|
|
|
avg_time = sum([i.get_max_time() for i in qp.iter()]) / len(qp.object_pool.pool)
|
|
|
|
return self.get_time_label(avg_time)
|
|
|
|
|
|
|
|
def get_time_label(self, max_time):
|
|
|
|
total_time = max_time
|
|
|
|
|
|
|
|
hours = total_time // 3600
|
|
|
|
total_time -= hours * 3600
|
|
|
|
|
|
|
|
minutes = total_time // 60
|
|
|
|
total_time -= minutes * 60
|
|
|
|
|
|
|
|
seconds = total_time
|
|
|
|
|
|
|
|
total_label = []
|
|
|
|
|
|
|
|
if hours:
|
|
|
|
total_label.append(f"{round(hours)} год.")
|
|
|
|
if minutes:
|
|
|
|
total_label.append(f"{round(minutes)} хв.")
|
|
|
|
if seconds:
|
|
|
|
total_label.append(f"{round(seconds)} c.")
|
|
|
|
|
|
|
|
return " ".join(total_label)
|