forked from Haidra-Org/AI-Horde
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_sentry_test.py
More file actions
76 lines (60 loc) · 2.45 KB
/
Copy pathrun_sentry_test.py
File metadata and controls
76 lines (60 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2026 AI Power Grid
#
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Sentry Test - Run this to watch for kudos changes
"""
import time
from datetime import datetime
import requests
API_URL = "https://api.aipowergrid.io/api/v2/workers"
WORK_WEIGHT = 0.90
UPTIME_WEIGHT = 0.10
TOTAL_PAYOUT = 5.0 # tokens per interval
def main() -> None:
print("=" * 60)
print("SENTRY TEST - Watching for kudos changes")
print(f"API: {API_URL}")
print("Press Ctrl+C to stop")
print("=" * 60)
old_data = requests.get(API_URL).json()
old_map = {w["id"]: w for w in old_data}
print(f"\n[{datetime.now().strftime('%H:%M:%S')}] Initial: {len(old_data)} workers")
poll_count = 0
while True:
time.sleep(60) # Poll every 60 seconds
poll_count += 1
try:
new_data = requests.get(API_URL).json()
except Exception:
print(f"[{datetime.now().strftime('%H:%M:%S')}] API error, retrying...")
continue
changes = []
for w in new_data:
wid = w["id"]
if wid not in old_map:
continue
old = old_map[wid].get("kudos_details", {})
new = w.get("kudos_details", {})
gen_diff = (new.get("generated") or 0) - (old.get("generated") or 0)
up_diff = (new.get("uptime") or 0) - (old.get("uptime") or 0)
if gen_diff > 0 or up_diff > 0:
score = (gen_diff * WORK_WEIGHT) + (up_diff * UPTIME_WEIGHT)
changes.append({"name": w["name"], "wallet": w.get("wallet_address"), "gen": gen_diff, "up": up_diff, "score": score})
if changes:
total_score = sum(c["score"] for c in changes)
print(f"\n[{datetime.now().strftime('%H:%M:%S')}] CHANGES DETECTED!")
print("-" * 50)
for c in sorted(changes, key=lambda x: x["score"], reverse=True):
share = c["score"] / total_score if total_score > 0 else 0
payout = share * TOTAL_PAYOUT
print(f" {c['name'][:35]}")
print(f" +{c['gen']} gen, +{c['up']} up -> {payout:.4f} tokens")
print(f" wallet: {c['wallet']}")
print("-" * 50)
else:
print(f"[{datetime.now().strftime('%H:%M:%S')}] Poll #{poll_count}: No changes ({len(new_data)} workers)")
old_map = {w["id"]: w for w in new_data}
if __name__ == "__main__":
main()