election_day.utils.archive_generator
Attributes
Classes
Iterates over all Votes, Election and ElectionCompounds and runs the |
Module Contents
- election_day.utils.archive_generator.Entity: TypeAlias = Election | ElectionCompound | Vote[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.
- 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
- 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.