47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
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:
|
|
rendered_questions = [i.render_short(self.cursor) for i in qp.select_by_test_id(test_id)]
|
|
else:
|
|
rendered_questions = [i.render_short(self.cursor) for i in qp.iter()]
|
|
|
|
return "\n".join(rendered_questions)
|
|
|
|
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)
|