sdk/hints: HintsDB.GetDetailedScores()

This commit is contained in:
fiatjaf
2025-04-06 11:47:08 -03:00
parent 05e2018d3a
commit 2e28cc809a
5 changed files with 175 additions and 0 deletions

View File

@@ -108,6 +108,31 @@ func (db *HintDB) PrintScores() {
}
}
func (db *HintDB) GetDetailedScores(pubkey string, n int) []hints.RelayScores {
db.Lock()
defer db.Unlock()
result := make([]hints.RelayScores, 0, n)
if rfpk, ok := db.OrderedRelaysByPubKey[pubkey]; ok {
// sort everything from scratch
slices.SortFunc(rfpk.Entries, func(a, b RelayEntry) int {
return int(b.Sum() - a.Sum())
})
for i, re := range rfpk.Entries {
if i >= n {
break
}
result = append(result, hints.RelayScores{
Relay: db.RelayBySerial[re.Relay],
Scores: re.Timestamps,
Sum: re.Sum(),
})
}
}
return result
}
type RelaysForPubKey struct {
Entries []RelayEntry
}