Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pro-wh/junk/test
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Feb 21, 2020
2 parents 39f0a84 + e4132f5 commit 269279f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
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

0 comments on commit 269279f

Please sign in to comment.