Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 15, 2024
2 parents 82b0de4 + caf6227 commit 6868cd3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
7 changes: 2 additions & 5 deletions bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,7 @@ def to_df_format(
else None
), # only show first feedback as per Sean's request
"Analysis JSON": message.analysis_result,
"Response Time": (
message.response_time
and round(message.response_time.total_seconds(), 1)
),
"Run Time": message.saved_run.run_time if message.saved_run else 0, # user messages have no run/run_time
}
rows.append(row)
df = pd.DataFrame.from_records(
Expand All @@ -950,7 +947,7 @@ def to_df_format(
"Sent",
"Feedback",
"Analysis JSON",
"Response Time",
"Run Time",
],
)
return df
Expand Down
36 changes: 5 additions & 31 deletions recipes/VideoBotsStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,16 @@ def render_date_view_inputs(self, bi):
start_date = bi.created_at
end_date = timezone.now()
else:
start_of_year_date = timezone.now().replace(month=1, day=1)
fifteen_days_ago = timezone.now() - timedelta(days=15)
fifteen_days_ago = fifteen_days_ago.replace(hour=0, minute=0, second=0)
st.session_state.setdefault(
"start_date",
self.request.query_params.get(
"start_date", start_of_year_date.strftime("%Y-%m-%d")
"start_date", fifteen_days_ago.strftime("%Y-%m-%d")
),
)
start_date: datetime = (
st.date_input("Start date", key="start_date") or start_of_year_date
st.date_input("Start date", key="start_date") or fifteen_days_ago
)
st.session_state.setdefault(
"end_date",
Expand All @@ -311,7 +312,7 @@ def render_date_view_inputs(self, bi):
st.date_input("End date", key="end_date") or timezone.now()
)
st.session_state.setdefault(
"view", self.request.query_params.get("view", "Weekly")
"view", self.request.query_params.get("view", "Daily")
)
st.write("---")
view = st.horizontal_radio(
Expand Down Expand Up @@ -439,18 +440,14 @@ def calculate_stats_binned_by_time(
)
)
.annotate(Average_runtime=Avg("saved_run__run_time"))
.annotate(Average_response_time=Avg("response_time"))
.annotate(Average_analysis_time=Avg("analysis_run__run_time"))
.annotate(Unique_feedback_givers=Count("feedbacks", distinct=True))
.values(
"date",
"Messages_Sent",
"Convos",
"Senders",
"Unique_feedback_givers",
"Average_response_time",
"Average_runtime",
"Average_analysis_time",
)
)

Expand Down Expand Up @@ -504,9 +501,7 @@ def calculate_stats_binned_by_time(
"Convos",
"Senders",
"Unique_feedback_givers",
"Average_response_time",
"Average_runtime",
"Average_analysis_time",
],
)
df = df.merge(
Expand Down Expand Up @@ -546,11 +541,6 @@ def calculate_stats_binned_by_time(
) * 100
df["Msgs_per_convo"] = df["Messages_Sent"] / df["Convos"]
df["Msgs_per_user"] = df["Messages_Sent"] / df["Senders"]
try:
df["Average_response_time"] = df["Average_response_time"].dt.total_seconds()
except AttributeError:
pass
df["Average_response_time"] = df["Average_response_time"] * factor
df.fillna(0, inplace=True)
df = df.round(0).astype("int32", errors="ignore")
return df
Expand Down Expand Up @@ -699,14 +689,6 @@ def plot_graphs(self, view, df):
st.write("---")
fig = go.Figure(
data=[
go.Scatter(
name="Average Response Time",
mode="lines+markers",
x=list(df["date"]),
y=list(df["Average_response_time"]),
text=list(df["Average_response_time"]),
hovertemplate="Average Response Time: %{y:.0f}<extra></extra>",
),
go.Scatter(
name="Average Run Time",
mode="lines+markers",
Expand All @@ -715,14 +697,6 @@ def plot_graphs(self, view, df):
text=list(df["Average_runtime"]),
hovertemplate="Average Runtime: %{y:.0f}<extra></extra>",
),
go.Scatter(
name="Average Analysis Time",
mode="lines+markers",
x=list(df["date"]),
y=list(df["Average_analysis_time"]),
text=list(df["Average_analysis_time"]),
hovertemplate="Average Analysis Time: %{y:.0f}<extra></extra>",
),
],
layout=dict(
margin=dict(l=0, r=0, t=28, b=0),
Expand Down

0 comments on commit 6868cd3

Please sign in to comment.