Skip to content

Commit

Permalink
tables adhere to data filters
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Feb 1, 2024
1 parent fb9d32c commit 570963c
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions recipes/VideoBotsStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,15 @@ def render(self):
sort_by = st.session_state["sort_by"]

df = self.get_tabular_data(
bi, run_url, conversations, messages, details, sort_by, rows=500
bi,
run_url,
conversations,
messages,
details,
sort_by,
rows=500,
start_date=start_date,
end_date=end_date,
)

if not df.empty:
Expand All @@ -233,7 +241,14 @@ def render(self):
st.html("<br/>")
if st.checkbox("Export"):
df = self.get_tabular_data(
bi, run_url, conversations, messages, details, sort_by
bi,
run_url,
conversations,
messages,
details,
sort_by,
start_date=start_date,
end_date=end_date,
)
csv = df.to_csv()
b64 = base64.b64encode(csv.encode()).decode()
Expand Down Expand Up @@ -642,12 +657,29 @@ def plot_graphs(self, view, df):
st.plotly_chart(fig)

def get_tabular_data(
self, bi, run_url, conversations, messages, details, sort_by, rows=10000
self,
bi,
run_url,
conversations,
messages,
details,
sort_by,
rows=10000,
start_date=None,
end_date=None,
):
df = pd.DataFrame()
if details == "Conversations":
if start_date and end_date:
conversations = conversations.filter(
created_at__date__gte=start_date, created_at__date__lte=end_date
)
df = conversations.to_df_format(row_limit=rows)
elif details == "Messages":
if start_date and end_date:
messages = messages.filter(
created_at__date__gte=start_date, created_at__date__lte=end_date
)
df = messages.order_by("-created_at", "conversation__id").to_df_format(
row_limit=rows
)
Expand All @@ -658,30 +690,52 @@ def get_tabular_data(
message__conversation__bot_integration=bi,
rating=Feedback.Rating.RATING_THUMBS_UP,
) # type: ignore
if start_date and end_date:
pos_feedbacks = pos_feedbacks.filter(
created_at__date__gte=start_date, created_at__date__lte=end_date
)
df = pos_feedbacks.to_df_format(row_limit=rows)
df["Run URL"] = run_url
df["Bot"] = bi.name
elif details == "Feedback Negative":
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(
created_at__date__gte=start_date, created_at__date__lte=end_date
)
df = neg_feedbacks.to_df_format(row_limit=rows)
df["Run URL"] = run_url
df["Bot"] = bi.name
elif details == "Answered Successfully":
successful_messages: MessageQuerySet = Message.objects.filter(
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(
created_at__date__gte=start_date, created_at__date__lte=end_date
)
df = successful_messages.to_df_analysis_format(row_limit=rows)
df["Run URL"] = run_url
df["Bot"] = bi.name
elif details == "Answered Unsuccessfully":
unsuccessful_messages: MessageQuerySet = Message.objects.filter(
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(
created_at__date__gte=start_date, created_at__date__lte=end_date
)
df = unsuccessful_messages.to_df_analysis_format(row_limit=rows)
df["Run URL"] = run_url
df["Bot"] = bi.name
Expand Down

0 comments on commit 570963c

Please sign in to comment.