Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

availability ranking for next Quest phase #2699

Merged
merged 3 commits into from
Feb 21, 2020
Merged
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
7 changes: 7 additions & 0 deletions .changelog/2699.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
go/extra/stats: Availability ranking for next Quest phase

A new availability score will take into account more than the number of
block signatures alone.
This introduces the mechanism to compute a score and print the
rankings based on that.
This also implements a provisional scoring formula.
21 changes: 13 additions & 8 deletions go/extra/stats/cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
cfgStartBlock = "start-block"
cfgEndBlock = "end-block"
cfgTopN = "top-n"

availabilityScorePerSignature = 1
availabilityScorePerProposal = 50
)

var (
Expand Down Expand Up @@ -68,10 +71,11 @@ type stats struct {
// printEntitySignatures prints topN entities by block signature counts.
func (s stats) printEntitySignatures(topN int) {
type results struct {
entityID signature.PublicKey
signatures int64
proposals int64
nodes int
entityID signature.PublicKey
signatures int64
proposals int64
nodes int
availablityScore int64
}
res := []results{}

Expand All @@ -84,18 +88,19 @@ func (s stats) printEntitySignatures(topN int) {
for _, proposals := range eStats.nodeProposals {
entity.proposals += proposals
}
entity.availablityScore = availabilityScorePerSignature*entity.signatures + availabilityScorePerProposal*entity.proposals
res = append(res, entity)
}

sort.Slice(res, func(i, j int) bool {
return res[i].signatures > res[j].signatures
return res[i].availablityScore > res[j].availablityScore
})

// Print results.
fmt.Printf("|%-5s|%-64s|%-6s|%10s|%10s|\n", "Rank", "Entity ID", "Nodes", "Signatures", "Proposals")
fmt.Println(strings.Repeat("-", 5+64+6+10+10+6))
fmt.Printf("|%-5s|%-64s|%-6s|%10s|%10s|%18s|\n", "Rank", "Entity ID", "Nodes", "Signatures", "Proposals", "Availability score")
fmt.Println(strings.Repeat("-", 5+64+6+10+10+18+7))
for idx, r := range res {
fmt.Printf("|%-5d|%-64s|%6d|%10d|%10d|\n", idx+1, r.entityID, r.nodes, r.signatures, r.proposals)
fmt.Printf("|%-5d|%-64s|%6d|%10d|%10d|%18d|\n", idx+1, r.entityID, r.nodes, r.signatures, r.proposals, r.availablityScore)
}
}

Expand Down