-
Notifications
You must be signed in to change notification settings - Fork 0
Add live evidence-linked contributor leaderboard #2
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| const BASELINE = 100; | ||
|
|
||
| const DELTAS = Object.freeze({ | ||
| 'missing-evidence': -5, | ||
| 'review-concerns': -3, | ||
| 'auto-revert': -6, | ||
| 'corrective-reland': 4, | ||
| 'verified-evidence': 3, | ||
| }); | ||
|
|
||
| function dateValue(value) { | ||
| const time = new Date(value).getTime(); | ||
| return Number.isFinite(time) ? time : 0; | ||
| } | ||
|
|
||
| export function scoreEvents(events, baseline = BASELINE) { | ||
| let score = baseline; | ||
| const scored = [...events] | ||
| .sort((left, right) => dateValue(left.at) - dateValue(right.at)) | ||
| .map((event) => { | ||
| const delta = DELTAS[event.kind] ?? 0; | ||
| const from = score; | ||
| score += delta; | ||
| return { ...event, delta, from, to: score }; | ||
| }); | ||
| return { score, trend: [baseline, ...scored.map((event) => event.to)], events: scored }; | ||
| } | ||
|
|
||
| function eventKind(status) { | ||
| if (status === 'blocked') return 'missing-evidence'; | ||
| if (status === 'concerns') return 'review-concerns'; | ||
| if (status === 'approved') return 'verified-evidence'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a PR has no active contract, the standard review path can approve it without checking any evidence, yet this status-only mapping records a Useful? React with 👍 / 👎. |
||
| return null; | ||
| } | ||
|
|
||
| export function reviewEventForReceipt(receipt, status = receipt.status, at = null) { | ||
| const kind = eventKind(status); | ||
| if (!kind) return null; | ||
| const number = receipt.github?.number ?? receipt.prNum; | ||
| return { | ||
| kind, | ||
| status, | ||
| at: at ?? receipt.github?.publication?.publishedAt ?? receipt.ts, | ||
| label: `PR #${number} ${status}`, | ||
| url: receipt.github?.htmlUrl ?? null, | ||
| source: receipt.github?.repository ?? 'MongoDB receipt', | ||
| }; | ||
| } | ||
|
|
||
| function receiptEvents(receipt) { | ||
| if (!receipt.reviewEvents?.length) { | ||
| const current = reviewEventForReceipt(receipt); | ||
| return current ? [current] : []; | ||
| } | ||
| return receipt.reviewEvents | ||
| .map((event) => { | ||
| const generated = reviewEventForReceipt(receipt, event.status, event.at); | ||
| return generated ? { ...generated, ...event } : null; | ||
| }) | ||
| .filter(Boolean); | ||
| } | ||
|
|
||
| function reviewBand(score) { | ||
| if (score >= 100) return { key: 'normal', label: 'normal review' }; | ||
| if (score >= 90) return { key: 'elevated', label: 'elevated review' }; | ||
| return { key: 'maximum', label: 'maximum review' }; | ||
| } | ||
|
|
||
| export function buildContributorLeaderboard({ profiles, receipts }) { | ||
| const byScope = new Map( | ||
| profiles.map((profile) => [`${profile.handle}\u0000${profile.subsystem}`, { ...profile }]), | ||
| ); | ||
|
|
||
| for (const receipt of receipts) { | ||
| if (!receipt.author || !receipt.subsystem || !receipt.github) continue; | ||
| const key = `${receipt.author}\u0000${receipt.subsystem}`; | ||
| if (!byScope.has(key)) { | ||
| byScope.set(key, { | ||
| handle: receipt.author, | ||
| repo: receipt.github.repository, | ||
| subsystem: receipt.subsystem, | ||
| isCurrentUser: receipt.author === 'gorajing', | ||
| events: [], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| const rows = []; | ||
| for (const profile of byScope.values()) { | ||
| const liveEvents = receipts | ||
| .filter((receipt) => receipt.author === profile.handle && receipt.subsystem === profile.subsystem) | ||
| .flatMap(receiptEvents); | ||
| const scored = scoreEvents([...(profile.events ?? []), ...liveEvents]); | ||
| rows.push({ | ||
| handle: profile.handle, | ||
| repo: profile.repo, | ||
| subsystem: profile.subsystem, | ||
| isCurrentUser: Boolean(profile.isCurrentUser), | ||
| profileUrl: profile.profileUrl ?? `https://github.com/${profile.handle}`, | ||
| basis: profile.basis ?? 'Live PR-Elo receipts', | ||
| ...scored, | ||
| movement: scored.score - BASELINE, | ||
| band: reviewBand(scored.score), | ||
| }); | ||
| } | ||
|
|
||
| return rows.sort((left, right) => right.score - left.score || left.handle.localeCompare(right.handle)); | ||
| } | ||
|
|
||
| export const leaderboardScoring = { | ||
| baseline: BASELINE, | ||
| deltas: DELTAS, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For any row with multiple scored events, selecting only
latesthides all earlier evidence links and transitions even though those events still contribute to the displayed total. For example, the documented two-blocked-PR row shows a −10 movement but exposes only the second PR's 95→90 transition, preventing users from auditing the first −5; render the full event list or otherwise provide access to every contributing event.Useful? React with 👍 / 👎.