Sazzz02 commited on
Commit
14f2897
·
verified ·
1 Parent(s): 2cb83ee

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +26 -0
utils.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import numpy as np
3
+ from io import BytesIO
4
+ import base64
5
+
6
+ cheating_scores = []
7
+
8
+ def plot_cheating_graph():
9
+ fig, ax = plt.subplots()
10
+ ax.plot(cheating_scores, color='red', label='Cheating Score')
11
+ ax.set_xlabel("Time")
12
+ ax.set_ylabel("Cheating Probability")
13
+ ax.set_title("Live Cheating Detection Graph")
14
+ ax.legend()
15
+ buf = BytesIO()
16
+ plt.savefig(buf, format='png')
17
+ buf.seek(0)
18
+ encoded = base64.b64encode(buf.read()).decode('utf-8')
19
+ plt.close(fig)
20
+ return f"data:image/png;base64,{encoded}"
21
+
22
+ def update_score(cheating):
23
+ score = 1 if cheating else 0
24
+ cheating_scores.append(score)
25
+ if len(cheating_scores) > 50:
26
+ cheating_scores.pop(0)