-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(votes): one tally module for score #501
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
Open
chiptus
wants to merge
3
commits into
main
Choose a base branch
from
feat-13/vote-tally-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,52 @@ | ||
| # One vote Score, replacing rating and popularity | ||
|
|
||
| Three vote-aggregation formulas coexisted, each hand-rolled from `vote_type` | ||
| literals in a different file: **rating** (mean of vote values, drove the | ||
| `rating-desc` sort and the Minimum Rating filter), **popularity** | ||
| (`2·mustGo + interested`, no Won't-Go term, drove the default | ||
| `popularity-desc` sort), and a **net score** (`2·mustGo + interested − wontGo`, | ||
| the Set-detail "Score" badge). All three bypassed the vote config's canonical | ||
| weights. The popularity/net split was documented in the sort-help popover, so | ||
| it was intentional — but it meant a set could rank above another it visibly | ||
| "scores" below, and none of the aggregation logic was tested. | ||
|
|
||
| We consolidated on a single metric: **Score = the sum of a set's vote values** | ||
| (`2·mustGo + interested − wontGo`, weights read from the vote config). It is | ||
| computed in one pure module, `src/lib/votes/score.ts` (`tallyVotes(votes) → | ||
| { counts, score }`), which also owns per-type counting. One sort ("Top Score", | ||
| `score-desc`, the default) replaces both vote sorts; the Minimum Rating filter | ||
| is removed; the badge is unchanged but now provably shows the same number the | ||
| sort ranks by. The vote config moved to `src/lib/votes/config.ts` alongside it. | ||
|
|
||
| ## Considered Options | ||
|
|
||
| - **Single net Score (chosen).** UpLine's core loop is group consensus, and | ||
| Won't-Go is the consensus signal — a sort that ignores it hides exactly the | ||
| disagreement a group needs to see. One number users can verify by counting | ||
| the per-type counts displayed beside it. Sum over mean because every set is | ||
| scored by the same small pool (a group), so normalization buys little, and | ||
| "more people caring moves it up" matches intuition. | ||
| - **Keep rating + popularity as documented, deliberately distinct metrics.** | ||
| Defensible (popularity as an "enthusiasm/buzz" measure that tolerates | ||
| controversy), but it permanently costs explaining why the #1-ranked set can | ||
| show a lower score than #3. With no usage data indicating anyone relies on | ||
| the distinction, legibility won. | ||
| - **Mean rating as the single metric.** Normalized, but favours | ||
| few-but-enthusiastic votes over broad support, and its own filter UI proved | ||
| how illegible it was: the "Minimum Rating 3+" option was unreachable (max | ||
| possible mean is 2). | ||
|
|
||
| ## Consequences | ||
|
|
||
| - Ranking visibly changes: sets with many Won't-Go votes drop relative to the | ||
| old default popularity sort. One-time reshuffle toward the number already | ||
| shown on the detail page. | ||
| - Old bookmarked URLs with `sort=rating-desc`/`popularity-desc` or `minRating` | ||
| degrade gracefully: the zod `.catch` falls back to `score-desc` and unknown | ||
| params are dropped. | ||
| - If a "buzz"-style enthusiasm metric is ever wanted (e.g. for an explore | ||
| surface), add it as a new named concept in `tallyVotes` and `CONTEXT.md` — | ||
| do not re-derive from `vote_type` literals in components, and do not reuse | ||
| the names "rating" or "popularity" (retired, see CONTEXT.md). | ||
| - `useVoteCount` was deleted; all per-type counts come from | ||
| `tallyVotes().counts`. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
This file contains hidden or 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,85 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { tallyVotes } from "./score"; | ||
|
|
||
| describe("tallyVotes", () => { | ||
| it("returns zero counts and zero score for no votes", () => { | ||
| expect(tallyVotes([])).toEqual({ | ||
| counts: { mustGo: 0, interested: 0, wontGo: 0 }, | ||
| score: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it("returns zero counts and zero score for undefined votes", () => { | ||
| expect(tallyVotes(undefined)).toEqual({ | ||
| counts: { mustGo: 0, interested: 0, wontGo: 0 }, | ||
| score: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it("returns zero counts and zero score for null votes", () => { | ||
| expect(tallyVotes(null)).toEqual({ | ||
| counts: { mustGo: 0, interested: 0, wontGo: 0 }, | ||
| score: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it("counts each vote type", () => { | ||
| const { counts } = tallyVotes([ | ||
| vote(2), | ||
| vote(2), | ||
| vote(2), | ||
| vote(1), | ||
| vote(1), | ||
| vote(-1), | ||
| ]); | ||
| expect(counts).toEqual({ mustGo: 3, interested: 2, wontGo: 1 }); | ||
| }); | ||
|
|
||
| it("scores as the sum of vote values: 2·mustGo + interested − wontGo", () => { | ||
| const { score } = tallyVotes([ | ||
| vote(2), | ||
| vote(2), | ||
| vote(2), | ||
| vote(1), | ||
| vote(1), | ||
| vote(-1), | ||
| ]); | ||
| expect(score).toBe(2 * 3 + 2 - 1); | ||
| }); | ||
|
|
||
| it("goes negative when Won't Go votes outweigh the rest", () => { | ||
| const { score } = tallyVotes([vote(-1), vote(-1), vote(-1), vote(1)]); | ||
| expect(score).toBe(-2); | ||
| }); | ||
|
|
||
| it("scores an all-negative vote set as minus the vote count", () => { | ||
| expect(tallyVotes([vote(-1), vote(-1), vote(-1)])).toEqual({ | ||
| counts: { mustGo: 0, interested: 0, wontGo: 3 }, | ||
| score: -3, | ||
| }); | ||
| }); | ||
|
|
||
| it("ignores unknown vote_type values in both counts and score", () => { | ||
| const result = tallyVotes([vote(2), vote(0), vote(99), vote(-5)]); | ||
| expect(result).toEqual({ | ||
| counts: { mustGo: 1, interested: 0, wontGo: 0 }, | ||
| score: 2, | ||
| }); | ||
| }); | ||
|
|
||
| it("tallies a group-scoped subset independently of the full set", () => { | ||
| const all = [vote(2), vote(2), vote(1), vote(-1)]; | ||
| const groupSubset = all.slice(0, 3); | ||
| expect(tallyVotes(all).score).toBe(4); | ||
| expect(tallyVotes(groupSubset).score).toBe(5); | ||
| expect(tallyVotes(groupSubset).counts).toEqual({ | ||
| mustGo: 2, | ||
| interested: 1, | ||
| wontGo: 0, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| function vote(vote_type: number) { | ||
| return { vote_type }; | ||
| } |
This file contains hidden or 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,28 @@ | ||
| import { VOTES_TYPES, VOTE_CONFIG, VoteType, getVoteConfig } from "./config"; | ||
|
|
||
| export interface VoteTally { | ||
| counts: Record<VoteType, number>; | ||
| score: number; | ||
| } | ||
|
|
||
| export function tallyVotes( | ||
| votes: Array<{ vote_type: number }> | null | undefined, | ||
| ): VoteTally { | ||
| const counts = Object.fromEntries( | ||
| VOTES_TYPES.map((voteType) => [voteType, 0]), | ||
| ) as Record<VoteType, number>; | ||
|
|
||
| for (const vote of votes || []) { | ||
| const voteType = getVoteConfig(vote.vote_type); | ||
| if (voteType) { | ||
| counts[voteType] += 1; | ||
| } | ||
| } | ||
|
|
||
| const score = VOTES_TYPES.reduce( | ||
| (sum, voteType) => sum + counts[voteType] * VOTE_CONFIG[voteType].value, | ||
| 0, | ||
| ); | ||
|
|
||
| return { counts, score }; | ||
| } |
This file contains hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
src/pages/EditionView/tabs/ScheduleTab/horizontal/OverviewStageRow.tsx
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.