Spaces:
Running
Running
score diff since app start
Browse files- app/leaderboard.py +27 -2
- app/ui_leaderboard.py +1 -1
- app/vote.py +4 -4
app/leaderboard.py
CHANGED
@@ -1,14 +1,18 @@
|
|
1 |
from .config import *
|
2 |
from .db import *
|
3 |
from .models import *
|
|
|
4 |
|
5 |
import pandas as pd
|
|
|
|
|
|
|
6 |
def get_leaderboard(reveal_prelim = False):
|
|
|
7 |
|
8 |
conn = get_db()
|
9 |
cursor = conn.cursor()
|
10 |
sql = 'SELECT name, upvote, downvote, name AS orig_name FROM model'
|
11 |
-
# if not reveal_prelim: sql += ' WHERE EXISTS (SELECT 1 FROM model WHERE (upvote + downvote) > 750)'
|
12 |
if not reveal_prelim: sql += ' WHERE (upvote + downvote) > 300'
|
13 |
cursor.execute(sql)
|
14 |
data = cursor.fetchall()
|
@@ -22,6 +26,7 @@ def get_leaderboard(reveal_prelim = False):
|
|
22 |
|
23 |
## ELO SCORE
|
24 |
df['score'] = 1200
|
|
|
25 |
for i in range(len(df)):
|
26 |
for j in range(len(df)):
|
27 |
if i != j:
|
@@ -36,6 +41,26 @@ def get_leaderboard(reveal_prelim = False):
|
|
36 |
print(f"Error in ELO calculation for rows {i} and {j}: {str(e)}")
|
37 |
continue
|
38 |
df['score'] = round(df['score'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
## ELO SCORE
|
40 |
df = df.sort_values(by='score', ascending=False)
|
41 |
# medals
|
@@ -53,7 +78,6 @@ def get_leaderboard(reveal_prelim = False):
|
|
53 |
|
54 |
df['order'] = [assign_medal(i, not reveal_prelim and len(df) > 2) for i in range(len(df))]
|
55 |
# fetch top_five
|
56 |
-
top_five = []
|
57 |
for orig_name in df['orig_name']:
|
58 |
if (
|
59 |
reveal_prelim
|
@@ -62,6 +86,7 @@ def get_leaderboard(reveal_prelim = False):
|
|
62 |
):
|
63 |
top_five.append(orig_name)
|
64 |
|
|
|
65 |
df = df[['order', 'name', 'score', 'votes']]
|
66 |
return df
|
67 |
|
|
|
1 |
from .config import *
|
2 |
from .db import *
|
3 |
from .models import *
|
4 |
+
from .synth import top_five
|
5 |
|
6 |
import pandas as pd
|
7 |
+
|
8 |
+
# for diff
|
9 |
+
leaderboard_df = {}
|
10 |
def get_leaderboard(reveal_prelim = False):
|
11 |
+
global leaderboard_df
|
12 |
|
13 |
conn = get_db()
|
14 |
cursor = conn.cursor()
|
15 |
sql = 'SELECT name, upvote, downvote, name AS orig_name FROM model'
|
|
|
16 |
if not reveal_prelim: sql += ' WHERE (upvote + downvote) > 300'
|
17 |
cursor.execute(sql)
|
18 |
data = cursor.fetchall()
|
|
|
26 |
|
27 |
## ELO SCORE
|
28 |
df['score'] = 1200
|
29 |
+
df['score_diff'] = ""
|
30 |
for i in range(len(df)):
|
31 |
for j in range(len(df)):
|
32 |
if i != j:
|
|
|
41 |
print(f"Error in ELO calculation for rows {i} and {j}: {str(e)}")
|
42 |
continue
|
43 |
df['score'] = round(df['score'])
|
44 |
+
df['score_diff'] = df['score']
|
45 |
+
|
46 |
+
if (
|
47 |
+
reveal_prelim == False
|
48 |
+
and len(leaderboard_df) == 0
|
49 |
+
):
|
50 |
+
leaderboard_df = df
|
51 |
+
|
52 |
+
if (reveal_prelim == False):
|
53 |
+
for i in range(len(df)):
|
54 |
+
score_diff = (df['score'].iloc[i] - leaderboard_df['score'].iloc[i])
|
55 |
+
if (score_diff == 0):
|
56 |
+
continue
|
57 |
+
if (score_diff > 0):
|
58 |
+
plus = '<em style="color: green; font-family: monospace">+'
|
59 |
+
else:
|
60 |
+
plus = '<em style="color: red; font-family: monospace">'
|
61 |
+
|
62 |
+
df.at[i, 'score_diff'] = str(df['score'].iloc[i]) + plus + str(score_diff) +'</em>'
|
63 |
+
|
64 |
## ELO SCORE
|
65 |
df = df.sort_values(by='score', ascending=False)
|
66 |
# medals
|
|
|
78 |
|
79 |
df['order'] = [assign_medal(i, not reveal_prelim and len(df) > 2) for i in range(len(df))]
|
80 |
# fetch top_five
|
|
|
81 |
for orig_name in df['orig_name']:
|
82 |
if (
|
83 |
reveal_prelim
|
|
|
86 |
):
|
87 |
top_five.append(orig_name)
|
88 |
|
89 |
+
df['score'] = df['score_diff']
|
90 |
df = df[['order', 'name', 'score', 'votes']]
|
91 |
return df
|
92 |
|
app/ui_leaderboard.py
CHANGED
@@ -10,7 +10,7 @@ with gr.Blocks() as leaderboard:
|
|
10 |
min_width=0,
|
11 |
wrap=False,
|
12 |
column_widths=[30, 200, 50, 50],
|
13 |
-
datatype=["str", "html", "
|
14 |
)
|
15 |
reloadbtn = gr.Button("Refresh")
|
16 |
with gr.Row():
|
|
|
10 |
min_width=0,
|
11 |
wrap=False,
|
12 |
column_widths=[30, 200, 50, 50],
|
13 |
+
datatype=["str", "html", "html", "number"]
|
14 |
)
|
15 |
reloadbtn = gr.Button("Refresh")
|
16 |
with gr.Row():
|
app/vote.py
CHANGED
@@ -117,11 +117,11 @@ def reload(chosenmodel1=None, chosenmodel2=None, userid=None, chose_a=False, cho
|
|
117 |
]
|
118 |
style = 'text-align: center; font-size: 1rem; margin-bottom: 0; padding: var(--input-padding)'
|
119 |
if chose_a == True:
|
120 |
-
out.append(gr.
|
121 |
-
out.append(gr.
|
122 |
else:
|
123 |
-
out.append(gr.
|
124 |
-
out.append(gr.
|
125 |
out.append(gr.update(visible=True))
|
126 |
return out
|
127 |
|
|
|
117 |
]
|
118 |
style = 'text-align: center; font-size: 1rem; margin-bottom: 0; padding: var(--input-padding)'
|
119 |
if chose_a == True:
|
120 |
+
out.append(gr.HTML(value=f'<p style="{style}">Your vote: {chosenmodel1}</p>', visible=True))
|
121 |
+
out.append(gr.HTML(value=f'<p style="{style}">{chosenmodel2}</p>', visible=True))
|
122 |
else:
|
123 |
+
out.append(gr.HTML(value=f'<p style="{style}">{chosenmodel1}</p>', visible=True))
|
124 |
+
out.append(gr.HTML(value=f'<p style="{style}">Your vote: {chosenmodel2}</p>', visible=True))
|
125 |
out.append(gr.update(visible=True))
|
126 |
return out
|
127 |
|