Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/api/scoreboard_dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func TestScoreboardDump_Handler(t *testing.T) {
if result.Rigs[0].Handle != "alice" {
t.Errorf("rig handle = %q, want alice", result.Rigs[0].Handle)
}
if result.Rigs[0].TrustTier != "newcomer" {
t.Errorf("rig trust_tier = %q, want newcomer (1 root stamp = weight 5)", result.Rigs[0].TrustTier)
}
if len(result.Stamps) != 1 {
t.Errorf("stamps count = %d, want 1", len(result.Stamps))
}
Expand Down
26 changes: 26 additions & 0 deletions internal/commons/scoreboard_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type RigRow struct {
DisplayName string `json:"display_name,omitempty"`
DolthubOrg string `json:"dolthub_org,omitempty"`
TrustLevel int `json:"trust_level"`
TrustTier string `json:"trust_tier"`
RegisteredAt string `json:"registered_at,omitempty"`
LastSeen string `json:"last_seen,omitempty"`
RigType string `json:"rig_type,omitempty"`
Expand Down Expand Up @@ -100,9 +101,34 @@ func QueryScoreboardDump(db DB) (*ScoreboardDump, error) {
return nil, fmt.Errorf("dumping badges: %w", err)
}

// Derive trust_tier for each rig from stamp weighted scores.
populateDumpTrustTiers(dump)

return dump, nil
}

// populateDumpTrustTiers computes weighted scores from stamps and sets
// TrustTier on each RigRow, ensuring the dump uses the same tier labels
// as the scoreboard API.
func populateDumpTrustTiers(dump *ScoreboardDump) {
scores := make(map[string]int)
for _, s := range dump.Stamps {
weight := 0
switch s.Severity {
case "root":
weight = 5
case "branch":
weight = 3
case "leaf":
weight = 1
}
scores[s.Subject] += weight
}
for i := range dump.Rigs {
dump.Rigs[i].TrustTier = DeriveTrustTier(scores[dump.Rigs[i].Handle])
}
}

func queryDumpRigs(db DB) ([]RigRow, error) {
query := `SELECT handle, COALESCE(display_name,'') AS display_name, COALESCE(dolthub_org,'') AS dolthub_org,
COALESCE(trust_level,0) AS trust_level, COALESCE(registered_at,'') AS registered_at,
Expand Down
4 changes: 4 additions & 0 deletions internal/commons/scoreboard_dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func TestQueryScoreboardDump_Basic(t *testing.T) {
if dump.Rigs[0].DisplayName != "Alice Chen" {
t.Errorf("rig display_name = %q, want Alice Chen", dump.Rigs[0].DisplayName)
}
// alice has 1 root stamp (weight=5) → newcomer tier
if dump.Rigs[0].TrustTier != "newcomer" {
t.Errorf("rig trust_tier = %q, want newcomer", dump.Rigs[0].TrustTier)
}

if len(dump.Stamps) != 1 {
t.Fatalf("stamps count = %d, want 1", len(dump.Stamps))
Expand Down