Skip to content

Commit b65c565

Browse files
committed
update
1 parent 358b9f9 commit b65c565

File tree

9 files changed

+852
-280
lines changed

9 files changed

+852
-280
lines changed

fastchat/serve/monitor/basic_stats.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,22 @@ def load_log_files(filename):
3838
data = []
3939
for retry in range(5):
4040
try:
41-
lines = open(filename).readlines()
41+
for l in open(filename):
42+
row = json.loads(l)
43+
data.append(
44+
dict(
45+
type=row["type"],
46+
tstamp=row["tstamp"],
47+
model=row.get("model", ""),
48+
models=row.get("models", ["", ""]),
49+
)
50+
)
4251
break
4352
except FileNotFoundError:
4453
time.sleep(2)
4554

46-
for l in lines:
47-
row = json.loads(l)
48-
data.append(
49-
dict(
50-
type=row["type"],
51-
tstamp=row["tstamp"],
52-
model=row.get("model", ""),
53-
models=row.get("models", ["", ""]),
54-
)
55-
)
55+
if retry == 4:
56+
print(f"Failed to open {filename}")
5657
return data
5758

5859

@@ -134,6 +135,27 @@ def report_basic_stats(log_files):
134135
height=300,
135136
width=1200,
136137
)
138+
139+
# calculate conversion rate for each day (vote / chat)
140+
conversion_rate = {}
141+
for date in chat_dates_counts.index:
142+
chat_count = chat_dates_counts[date]
143+
vote_count = vote_dates_counts.get(date, 0)
144+
conversion_rate[date] = vote_count / chat_count if chat_count > 0 else 0
145+
conversion_rate_df = pd.DataFrame(
146+
{"date": list(conversion_rate.keys()), "rate": list(conversion_rate.values())}
147+
)
148+
conversion_rate_df = conversion_rate_df.sort_values("date")
149+
conversion_rate_fig = px.line(
150+
conversion_rate_df, x="date", y="rate", title="Conversion Rate (Vote / Chat)"
151+
)
152+
conversion_rate_fig.update_layout(
153+
xaxis_title="Dates",
154+
yaxis_title="Rate",
155+
height=300,
156+
width=1200,
157+
)
158+
137159

138160
# Model call counts
139161
model_hist_all = df_all[df_all["type"] == "chat"]["model"].value_counts()
@@ -198,6 +220,7 @@ def report_basic_stats(log_files):
198220

199221
return {
200222
"chat_dates_bar": chat_dates_bar,
223+
"conversion_rate_fig": conversion_rate_fig,
201224
"model_hist_md": model_hist_md,
202225
"action_hist_md": action_hist_md,
203226
"anony_vote_hist_md": anony_vote_hist_md,

0 commit comments

Comments
 (0)