-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
130 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const peerScoreMap = new Map<string, number>(); | ||
|
||
export const addOnePoint = (peer: string) => { | ||
const current = peerScoreMap.get(peer) || 0; | ||
peerScoreMap.set(peer, current + 1); | ||
}; | ||
|
||
export const resetScore = (peer: string) => peerScoreMap.set(peer, 0); | ||
export const resetAllScores = () => peerScoreMap.clear(); | ||
export const getScoreOf = (peer: string): number => peerScoreMap.get(peer) || 0; | ||
export const getAllScores = () => peerScoreMap.entries(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { getAllScores, resetAllScores } from "./index.js"; | ||
import { logger } from "../logger/index.js"; | ||
import { Table } from "console-table-printer"; | ||
import { sockets, keys } from "../constants.js"; | ||
import { encodeKeys } from "../bls/keys.js"; | ||
|
||
export const printScores = () => { | ||
const table = new Table({ | ||
columns: [ | ||
{ name: "peer", title: "Peer", alignment: "left", color: "blue" }, | ||
{ name: "name", title: "Name", alignment: "left", color: "yellow" }, | ||
{ name: "score", title: "Score", alignment: "center", color: "green" }, | ||
], | ||
}); | ||
|
||
const { publicKey: thisNode } = encodeKeys(keys); | ||
|
||
const rows = []; | ||
const publicKeyMap = new Map( | ||
[...sockets.entries()].map(([_, { publicKey, name }]) => [publicKey, name]) | ||
); | ||
|
||
for (const [peer, score] of getAllScores()) { | ||
if (peer === thisNode) { | ||
continue; | ||
} | ||
const name = publicKeyMap.get(peer) || "?"; | ||
rows.push({ peer, score, name }); | ||
} | ||
|
||
if (!rows.length) { | ||
return; | ||
} | ||
|
||
table.addRows(rows.sort((a, b) => b.score - a.score)); | ||
|
||
const sprint = Math.ceil(new Date().valueOf() / 300000); | ||
logger.info(`Scores for sprint ${sprint} are:`); | ||
table.printTable(); | ||
|
||
resetAllScores(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.