election_day.utils.election.candidates

Classes

CandidateResultRow

Functions

get_candidates_results(→ Query[CandidateResultRow])

Returns the aggregated candidates results as list.

get_candidates_data(→ onegov.core.types.JSONObject_ro)

" Get the candidates as JSON. Used to for the candidates bar chart.

get_candidates_results_by_entity(...)

Returns the candidates results by entity.

Module Contents

class election_day.utils.election.candidates.CandidateResultRow[source]

Bases: NamedTuple

votes: int[source]
family_name: str[source]
first_name: str[source]
elected: bool[source]
party: str | None[source]
percentage: float[source]
list_name: str | None[source]
list_id: str | None[source]
election_day.utils.election.candidates.get_candidates_results(election: onegov.election_day.models.Election, session: sqlalchemy.orm.Session, entities: Collection[str] | None = None) Query[CandidateResultRow][source]

Returns the aggregated candidates results as list.

Also includes percentages of votes for majorz elections. Be aware that this may contain rounding errors.

election_day.utils.election.candidates.get_candidates_data(election: onegov.election_day.models.Election, limit: int | None = None, lists: Collection[str] | None = None, elected: bool | None = None, sort_by_lists: bool = False, entities: Collection[str] | None = None) onegov.core.types.JSONObject_ro[source]

“ Get the candidates as JSON. Used to for the candidates bar chart.

Allows to optionally - return only the first limit results. - return only results for candidates within the given list names (proporz)

or party names (majorz).

  • return only elected candidates. If not specified, only elected candidates are returned for proporz elections, all for majorz elections.

election_day.utils.election.candidates.get_candidates_results_by_entity(election: onegov.election_day.models.Election, sort_by_votes: bool = False) tuple[list[CandidateRow], list[tuple[str, list[ResultRow]]]][source]

Returns the candidates results by entity.

Allows to optionally order by the number of total votes instead of the candidate names.