IamHussain commited on
Commit
307771a
·
1 Parent(s): 26cd2c3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from datetime import datetime, timedelta
4
+ import random
5
+
6
+ # In-memory storage for validator submissions
7
+ submitted_scores = []
8
+
9
+ # Function to submit score
10
+ def submit_score(validator_id, miner_id, score, model_type, timestamp):
11
+ submitted_scores.append({
12
+ "validator_id": validator_id,
13
+ "miner_id": miner_id,
14
+ "score": score,
15
+ "model_type": model_type,
16
+ "timestamp": timestamp
17
+ })
18
+
19
+ # Function to calculate the average score for each miner
20
+ def calculate_top_miners():
21
+ miner_scores = {}
22
+ for entry in submitted_scores:
23
+ miner_id = entry["miner_id"]
24
+ score = entry["score"]
25
+
26
+ if miner_id not in miner_scores:
27
+ miner_scores[miner_id] = {"SNR": 0, "HNR": 0, "CLAP": 0, "count": 0}
28
+
29
+ miner_scores[miner_id]["SNR"] += score["SNR"]
30
+ miner_scores[miner_id]["HNR"] += score["HNR"]
31
+ miner_scores[miner_id]["CLAP"] += score["CLAP"]
32
+ miner_scores[miner_id]["count"] += 1
33
+
34
+ # Calculate average score
35
+ for miner_id, scores in miner_scores.items():
36
+ scores["SNR"] /= scores["count"]
37
+ scores["HNR"] /= scores["count"]
38
+ scores["CLAP"] /= scores["count"]
39
+
40
+ # Sort by total score (sum of SNR, HNR, CLAP)
41
+ sorted_miners = sorted(miner_scores.items(), key=lambda x: (x[1]["SNR"] + x[1]["HNR"] + x[1]["CLAP"]), reverse=True)
42
+
43
+ return sorted_miners[:10] # Return top 10 miners
44
+
45
+ # Streamlit UI
46
+ st.title("Top 10 Miner Scores")
47
+
48
+ # Display top 10 miners
49
+ if st.button("Display Top 10 Scores"):
50
+ top_miners = calculate_top_miners()
51
+ st.write("Top 10 Miners based on aggregated scores:")
52
+
53
+ # Prepare data for the table
54
+ miner_data = []
55
+ for miner, scores in top_miners:
56
+ miner_data.append([miner, scores["SNR"], scores["HNR"], scores["CLAP"]])
57
+
58
+ df = pd.DataFrame(miner_data, columns=["Miner ID", "SNR", "HNR", "CLAP"])
59
+ st.table(df)