From fe4e2fc4d3854d829a618aac61e843b61c9f4f2d Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Tue, 27 Feb 2024 19:35:12 +0530 Subject: [PATCH] use | on Q instead of | on queryset --- recipes/VideoBotsStats.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/recipes/VideoBotsStats.py b/recipes/VideoBotsStats.py index 10e5ad527..4781d4b40 100644 --- a/recipes/VideoBotsStats.py +++ b/recipes/VideoBotsStats.py @@ -33,7 +33,7 @@ TruncYear, Concat, ) -from django.db.models import Count, Avg +from django.db.models import Count, Avg, Q ID_COLUMNS = [ "conversation__fb_page_id", @@ -817,13 +817,10 @@ def get_tabular_data( df["Bot"] = bi.name elif details == "Answered Successfully": successful_messages: MessageQuerySet = Message.objects.filter( + Q(analysis_result__contains={"Answered": True}) + | Q(analysis_result__contains={"assistant": {"answer": "Found"}}), conversation__bot_integration=bi, - analysis_result__contains={"Answered": True}, ) # type: ignore - successful_messages |= Message.objects.filter( - conversation__bot_integration=bi, - analysis_result__contains={"assistant": {"answer": "Found"}}, - ) if start_date and end_date: successful_messages = successful_messages.filter( created_at__date__gte=start_date, created_at__date__lte=end_date @@ -833,13 +830,10 @@ def get_tabular_data( df["Bot"] = bi.name elif details == "Answered Unsuccessfully": unsuccessful_messages: MessageQuerySet = Message.objects.filter( + Q(analysis_result__contains={"Answered": False}) + | Q(analysis_result__contains={"assistant": {"answer": "Missing"}}), conversation__bot_integration=bi, - analysis_result__contains={"Answered": False}, ) # type: ignore - unsuccessful_messages |= Message.objects.filter( - conversation__bot_integration=bi, - analysis_result__contains={"assistant": {"answer": "Missing"}}, - ) if start_date and end_date: unsuccessful_messages = unsuccessful_messages.filter( created_at__date__gte=start_date, created_at__date__lte=end_date