election_day.utils.archive_generator

Module Contents

Classes

ArchiveGenerator

Iterates over all Votes, Election and ElectionCompounds and runs the

Attributes

Entity

election_day.utils.archive_generator.Entity: typing_extensions.TypeAlias[source]
class election_day.utils.archive_generator.ArchiveGenerator(app: onegov.election_day.ElectionDayApp)[source]

Iterates over all Votes, Election and ElectionCompounds and runs the csv export function on each of them. This creates a bunch of csv files, which are zipped and the path to the zip is returned.

property archive_system_path: str | None[source]
archive_dir: SubFS[FS][source]
generate_csv() None[source]

Creates csv files with a directory structure like this:

archive ├── elections │ └── 2022 │ ├── election1.csv │ ├── election2.csv │ └── … │ └── votes

├── 2021 │ └── vote1.csv └── 2022

└── vote1.csv

get_all_rows_for_votes(votes: Collection[Vote]) list[dict[str, Any]][source]
group_by_year(entities: Iterable[EntityT]) list[list[EntityT]][source]

Creates a list of lists, grouped by year.

Parameters:

entities (list[Vote] | list[Election] | list[ElectionCompound]) – Iterable of entities

Returns:

A nested list, where each sublist contains all from one year.

For example:

Given a list: votes = [vote_1, vote_2, vote_3, …]

We create a new list: groups = [[vote_1, vote_2], [vote_3], …]

where vote_1.date.year == vote_2.date.year

zip_dir(base_dir: SubFS[FS]) str | None[source]

Recursively zips a directory (base_dir).

Parameters:

base_dir – is a directory in a temporary file system.

Contains subdirectories ‘votes’ and ‘elections’, as well as various other files to include.

:returns path to the zipfile or None if base_dir doesn’t exist or is empty.

all_counted_votes_with_results() list[onegov.ballot.Vote][source]
all_counted_election_with_results() list[onegov.ballot.Election][source]
all_counted_election_compounds_with_results() list[onegov.ballot.ElectionCompound][source]
filter_by_final_results(all_entities: Iterable[EntityT]) list[EntityT][source]
include_docs() None[source]
export_item(item: EntityT, dir: str) None[source]
generate_archive() str | None[source]