diff --git a/recipes/VideoBotsStats.py b/recipes/VideoBotsStats.py index a8fd4e541..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", @@ -543,6 +543,7 @@ def calculate_stats_binned_by_time( df["Msgs_per_user"] = df["Messages_Sent"] / df["Senders"] df.fillna(0, inplace=True) df = df.round(0).astype("int32", errors="ignore") + df = df.sort_values(by=["date"], ascending=True).reset_index() return df def plot_graphs(self, view, df): @@ -806,8 +807,6 @@ def get_tabular_data( neg_feedbacks: FeedbackQuerySet = Feedback.objects.filter( message__conversation__bot_integration=bi, rating=Feedback.Rating.RATING_THUMBS_DOWN, - created_at__date__gte=start_date, - created_at__date__lte=end_date, ) # type: ignore if start_date and end_date: neg_feedbacks = neg_feedbacks.filter( @@ -818,10 +817,9 @@ 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}, - created_at__date__gte=start_date, - created_at__date__lte=end_date, ) # type: ignore if start_date and end_date: successful_messages = successful_messages.filter( @@ -832,10 +830,9 @@ 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}, - created_at__date__gte=start_date, - created_at__date__lte=end_date, ) # type: ignore if start_date and end_date: unsuccessful_messages = unsuccessful_messages.filter(