Skip to content

Commit

Permalink
use | on Q instead of | on queryset
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 27, 2024
1 parent 10200a0 commit fe4e2fc
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions recipes/VideoBotsStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fe4e2fc

Please sign in to comment.