Skip to content

Commit 1a1c3fa

Browse files
authored
Merge pull request #146 from web-genie-ai/feat/dashboard
Dashboard feat
2 parents b64ce2d + e07bcf1 commit 1a1c3fa

File tree

7 files changed

+90
-9
lines changed

7 files changed

+90
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,5 @@ run_validator.sh
191191
# developer doc
192192
developer_doc.md
193193

194-
debug_images/
194+
debug_images/
195+
submit_results.py

neurons/validators/score_manager.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
MAX_UNANSWERED_TASKS
1818
)
1919
from webgenie.helpers.weights import save_file_to_wandb
20-
20+
from webgenie.storage import submit_results
2121
class ScoreManager:
2222
def __init__(self, neuron: BaseNeuron):
2323
self.neuron = neuron
@@ -282,3 +282,38 @@ def save_session_result_to_file(self, session_upto: int):
282282
bt.logging.error(f"Error saving session result to file: {e}")
283283
raise e
284284

285+
def submit_results_to_dashboard(self, session_upto: int):
286+
try:
287+
session_result = self.session_results[session_upto]
288+
289+
number_of_tasks = session_result["number_of_tasks"]
290+
session = session_result["session"]
291+
competition_type = session_result["competition_type"]
292+
scores = session_result["scores"]
293+
solved_tasks = session_result["solved_tasks"]
294+
competition = {
295+
"session_number": int(session),
296+
"competition_type": competition_type,
297+
}
298+
299+
submissions = []
300+
avg_scores = np.zeros(self.neuron.metagraph.n, dtype=np.float32)
301+
for uid in range(self.neuron.metagraph.n):
302+
if solved_tasks[uid] >= max(1, number_of_tasks - MAX_UNANSWERED_TASKS):
303+
avg_scores[uid] = scores[uid] / solved_tasks[uid]
304+
else:
305+
avg_scores[uid] = 0
306+
submissions.append({
307+
"neuron": {
308+
"hotkey": self.neuron.metagraph.hotkeys[uid],
309+
},
310+
"score": float(avg_scores[uid]),
311+
})
312+
313+
submit_results({
314+
"competition": competition,
315+
"submissions": submissions,
316+
})
317+
except Exception as e:
318+
bt.logging.error(f"Error submitting results to dashboard: {e}")
319+
raise e

neurons/validators/validator.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
)
3434
from webgenie.protocol import WebgenieTextSynapse, WebgenieImageSynapse
3535
from webgenie.rewards.lighthouse_reward import start_lighthouse_server_thread, stop_lighthouse_server
36-
from webgenie.storage import send_challenge_to_stats_collector
36+
from webgenie.storage import (
37+
send_challenge_to_stats_collector,
38+
submit_results,
39+
)
3740
from webgenie.utils.uids import get_validator_index
3841

3942
from neurons.validators.genie_validator import GenieValidator
@@ -183,11 +186,7 @@ def set_weights(self):
183186
with self.lock:
184187
self.score_manager.save_scores()
185188
self.score_manager.save_session_result_to_file(current_session-1)
186-
try:
187-
bt.logging.info(f"Sending challenge to stats collector for session {current_session-1}")
188-
send_challenge_to_stats_collector(self.wallet, current_session-1)
189-
except Exception as e:
190-
bt.logging.error(f"Error sending challenge to stats collector: {e}")
189+
self.score_manager.submit_results_to_dashboard(current_session-1)
191190

192191
bt.logging.success("set_weights on chain successfully!")
193192
else:

tests/test_submit_results.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import dotenv
2+
dotenv.load_dotenv(".env.validator")
3+
4+
from webgenie.storage import submit_results
5+
6+
7+
submit_results(
8+
miner_submissions_request={
9+
"competition": {
10+
"session_number": 12,
11+
"competition_type": "seo_competition",
12+
},
13+
"submissions": [
14+
{
15+
"neuron":{
16+
"hotkey": "sdasfasdfd1234567890",
17+
},
18+
"score": "0.92"
19+
},
20+
{
21+
"neuron":{
22+
"hotkey": "sdasfasdfd1234567890",
23+
},
24+
"score": "0.91"
25+
},
26+
{
27+
"neuron":{
28+
"hotkey": "sdasfasdfd1234567890",
29+
},
30+
"score": "0.90"
31+
},
32+
{
33+
"neuron":{
34+
"hotkey": "sdasfasdfd1234567890",
35+
},
36+
"score": "0.89"
37+
},
38+
]
39+
}
40+
)

uv.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webgenie/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@
9898
(psutil.virtual_memory().total) // (1024 * 1024 * 1024 * 4)
9999
)
100100
)
101+
102+
DASHBOARD_BACKEND_URL = os.getenv("DASHBOARD_BACKEND_URL", "http://209.126.9.130:19000") # dashboard backend url
103+
104+
API_TOKEN = os.getenv("API_TOKEN", "api_token") # api token

webgenie/storage/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
store_results_to_database,
33
send_challenge_to_stats_collector,
44
)
5+
from .submit_results import submit_results
56

0 commit comments

Comments
 (0)