SamanthaStorm commited on
Commit
5888ec6
·
verified ·
1 Parent(s): 7f3126b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -15,21 +15,26 @@ def generate_abuse_score_chart(dates, scores, labels):
15
  import io
16
  from PIL import Image
17
  from datetime import datetime
 
18
 
19
- try:
20
- parsed_dates = [datetime.strptime(d, "%Y-%m-%d") for d in dates]
21
- except Exception:
22
- parsed_dates = list(range(len(dates)))
 
 
 
23
 
24
  fig, ax = plt.subplots(figsize=(8, 3))
25
- ax.plot(parsed_dates, scores, marker='o', linestyle='-', color='darkred', linewidth=2)
26
 
27
- for i, (x, y) in enumerate(zip(parsed_dates, scores)):
28
  label = labels[i]
29
  ax.text(x, y + 2, f"{label}\n{int(y)}%", ha='center', fontsize=8, color='black')
30
 
31
- ax.set_title("Abuse Intensity Over Time")
32
- ax.set_xlabel("Date")
 
33
  ax.set_ylabel("Abuse Score (%)")
34
  ax.set_ylim(0, 105)
35
  ax.grid(True)
 
15
  import io
16
  from PIL import Image
17
  from datetime import datetime
18
+ import re
19
 
20
+ # Determine if all entries are valid dates
21
+ if all(re.match(r"\d{4}-\d{2}-\d{2}", d) for d in dates):
22
+ parsed_x = [datetime.strptime(d, "%Y-%m-%d") for d in dates]
23
+ x_labels = [d.strftime("%Y-%m-%d") for d in parsed_x]
24
+ else:
25
+ parsed_x = list(range(1, len(dates) + 1))
26
+ x_labels = [f"Message {i+1}" for i in range(len(dates))]
27
 
28
  fig, ax = plt.subplots(figsize=(8, 3))
29
+ ax.plot(parsed_x, scores, marker='o', linestyle='-', color='darkred', linewidth=2)
30
 
31
+ for i, (x, y) in enumerate(zip(parsed_x, scores)):
32
  label = labels[i]
33
  ax.text(x, y + 2, f"{label}\n{int(y)}%", ha='center', fontsize=8, color='black')
34
 
35
+ ax.set_xticks(parsed_x)
36
+ ax.set_xticklabels(x_labels)
37
+ ax.set_xlabel("") # No axis label
38
  ax.set_ylabel("Abuse Score (%)")
39
  ax.set_ylim(0, 105)
40
  ax.grid(True)