From b390ed9c2925d0c879870d9bf2a5775dace0687b Mon Sep 17 00:00:00 2001 From: maksim Date: Sat, 8 Jun 2024 01:23:36 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BD=D0=B0=20Positive=20=D0=B8=20Negative?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/repository.py b/repository.py index 4560f83..8548dda 100644 --- a/repository.py +++ b/repository.py @@ -72,7 +72,17 @@ class QuestionRepository: @staticmethod async def get_class_statistics() -> dict: async with new_session() as session: - query = select(QuestionOrm.answer, func.count(QuestionOrm.id)).group_by(QuestionOrm.answer) + query = select(QuestionOrm.type_mood, QuestionOrm.answer, func.count(QuestionOrm.id)).group_by(QuestionOrm.type_mood, QuestionOrm.answer) result = await session.execute(query) - statistics = {answer: count for answer, count in result.fetchall()} + statistics = {} + for row in result.fetchall(): + mood = row[0] + answer = row[1] + count = row[2] + if mood not in statistics: + statistics[mood] = {} + if answer not in statistics[mood]: + statistics[mood][answer] = count + else: + statistics[mood][answer] += count return statistics