Skip to content

Commit

Permalink
Update preference terms to be updated based on race
Browse files Browse the repository at this point in the history
  • Loading branch information
ArendPeter committed Dec 12, 2024
1 parent 8046ecd commit 55d9f9b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
16 changes: 14 additions & 2 deletions packages/frontend/src/components/Election/Results/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function IRVResultsViewer() {
<VoterProfileWidget candidates={sortedCandidates} topScore={1} ranked frontRunners={sortedCandidates.slice(0, 2) as [Candidate, Candidate]}/>
</WidgetContainer>
<WidgetContainer>
<ColumnDistributionWidget ranked/>
<ColumnDistributionWidget/>
</WidgetContainer>
</DetailExpander>
</DetailExpander>
Expand Down Expand Up @@ -408,11 +408,23 @@ function PRResultsViewer() {
}

export default function Results({ race, results }: {race: Race, results: ElectionResults}) {
const { t, election } = useElection();
const { election } = useElection();
let showTitleAsTie = ['random', 'five_star'].includes(results.tieBreakType);
// added a null check for sandbox support
let removeTieBreakFromTitle = (election?.settings.break_ties_randomly ?? false) && results.tieBreakType == 'random';

const {t} = useSubstitutedTranslation(election?.settings?.term_type ?? 'election', {
methodKey: {
'STAR': 'star',
'Approval': 'approval',
'Plurality': 'choose_one',
'IRV': 'rcv',
'STV': 'stv',
'STAR_PR': 'star_pr',
'RankedRobin': 'ranked_robin',
}[results.votingMethod]
});

return (
<RaceContextProvider race={race} results={results} t={t}>
<hr/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import useAnonymizedBallots from "~/components/AnonymizedBallotsContextProvider";
import useElection from "~/components/ElectionContextProvider";
import Widget from "./Widget";
import useRace from "~/components/RaceContextProvider";
import { useState } from "react";
import { Box, Divider, MenuItem, Paper, Select, Typography } from "@mui/material";
import { Bar, BarChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
import { CHART_COLORS } from "~/components/util";
import { Candidate } from "@equal-vote/star-vote-shared/domain_model/Candidate";
import HeadToHeadChart from "./HeadToHeadChart";
import ResultsKey from "./ResultsKey";
import { Divider, Typography } from "@mui/material";
import ResultsBarChart from "./ResultsBarChart";

// candidates helps define the order
export default ({ranked=false} : {ranked?: boolean}) => {
const {t} = useElection();
const {ballots, ballotsForRace} = useAnonymizedBallots();
const {race} = useRace();
export default () => {
const {ballotsForRace} = useAnonymizedBallots();
const {t, race} = useRace();

// How many columns were used?
// Which columns were used?
Expand Down Expand Up @@ -46,13 +38,13 @@ export default ({ranked=false} : {ranked?: boolean}) => {

whichColumns = whichColumns.map(c => ({...c, name: c.name == 'blank'? 'blank' : `${c.name}⭐`}))

return <Widget title={t(`results.column_distribution_title_${ranked? 'ranked' : 'scored'}`)}>
<Typography variant='h6'>{t(`results.column_distribution_num_avg_${ranked? 'ranked' : 'scored'}`, {count: Math.round(100*totalColumns / b.length)/100})}</Typography>
return <Widget title={t(`results.column_distribution_title`)}>
<Typography variant='h6'>{t(`results.column_distribution_num_avg`, {count: Math.round(100*totalColumns / b.length)/100})}</Typography>
<Divider/>
<Typography variant='h6'>{t(`results.column_distribution_num_title_${ranked? 'ranked' : 'scored'}`)}</Typography>
<Typography variant='h6'>{t(`results.column_distribution_num_title`)}</Typography>
<ResultsBarChart data={numColumns} xKey='count' percentage={true} sortFunc={false}/>
<Divider/>
{!ranked && <>
{race.voting_method == 'STAR' && <>
<Typography variant='h6'>{t('results.column_distribution_which_title')}</Typography>
<ResultsBarChart data={whichColumns} xKey='count' percentage={true} sortFunc={false} percentDenominator={b.length}/>
</>}
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const useSubstitutedTranslation = (electionTermType='election', v={}) =>
timeZoneName: 'short', timeZone: v['time_zone'] ?? undefined
}

let values = processValues({...en.keyword, ...en.keyword[electionTermType], ...v, formatParams: {
let values = processValues({...en.keyword, ...en.keyword[electionTermType], ...en.keyword[v[ 'methodKey' ] ?? 'star'], ...v, formatParams: {
datetime: dt,
datetime2: dt,
listed_datetime: {
Expand Down
30 changes: 23 additions & 7 deletions packages/frontend/src/i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,10 @@ results:
voter_profile_average_scores: "{{name}} supporters' average scores:"
voter_profile_average_ranks: "{{name}} supporters' average rankings:"

column_distribution_title_ranked: Distribution of Ranks
column_distribution_title_scored: Distribution of Scores
column_distribution_num_title_ranked: Number of ranks given !tip(columns_given)
column_distribution_num_title_scored: Number of scores given !tip(columns_given)
column_distribution_which_title: Which scores were used? !tip(columns_used)
column_distribution_num_avg_ranked: Voters gave {{count}} ranks on average
column_distribution_num_avg_scored: Voters gave {{count}} scores on average
column_distribution_title: Distribution of {{capital_preferences}}
column_distribution_num_avg: Voters gave {{count}} {{preferences}} on average
column_distribution_num_title: Number of {{preferences}} given !tip(columns_given)
column_distribution_which_title: Which {{preferences}} were used? !tip(columns_used)

candidate_selector: '{{capital_candidate}}'

Expand Down Expand Up @@ -915,6 +912,23 @@ emails:

# General Terms
keyword:
# Method Terms
star:
preferences: scores
star_pr:
preferences: scores
approval:
preferences: approvals
rcv:
preferences: ranks
stv:
preferences: ranks
ranked_robin:
preferences: ranks
choose_one:
preferences: preferences

# Election vs Poll Terms
election:
election: election
elections: elections
Expand All @@ -923,6 +937,7 @@ keyword:
race: race
ballot: ballot
vote: vote

poll:
election: poll
elections: polls
Expand All @@ -932,6 +947,7 @@ keyword:
ballot: response
vote: response

# General Terms
yes: Yes
no: No

Expand Down

0 comments on commit 55d9f9b

Please sign in to comment.