Skip to content
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

Add generate election package script #5721

Merged
merged 8 commits into from
Dec 11, 2024

Conversation

carolinemodic
Copy link
Contributor

Overview

Next step of the plan outlined in #5695 and implementing a lot of the work from that draft.

This PR adds a script to lib/fixture-generators to generate an election package in a given lib/fixtures directory folder. I add the generated results for 1 initial election but the only work in this PR that uses those fixtures is the new test that makes sure election packages generated are up to date.

Future Planned Work Still Includes:

  • Adding res-to-ts helpers to make working with the exported election packages easier
  • Finish migration for electionPrimaryWithPrecinctSplits to remove the current "election.json" and migrate all usages to either load the election package or electionGeneratedWithGridLayoutsMultiLang.json . The only usage of baseElection_DEPRECATED should be in the fixture generator test. Remove the re-generated election.json in libs/hmpb and use the generated election here.
  • Migrate remaining fixtures
  • At some point along the way I assume I'll need to add support for different system settings files, different election packages per election fixture, but I want to understand the extent of the need for that before I implement it.

Testing Plan

Ran tests
Manually tested using generated election package with generated json linked in dev dock for smart cards

layouts and translations. Follow the instructions to setup Google Cloud account
authentication [here](/../backend/src/language_and_audio/README.md) before
using.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this README section interrupts the Election Fixture Generator section. Also, it doesn't seem to include usage instructions for Election Package Generator

* Helper function that renders ballots and generates an election definition for the standard
* VxSuite hmpb ballot layout.
*/
export async function createElectionDefinitionForDefaultHmpbLayouts(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe "Template" rather than "Layouts"

* Helper function to generate all necessary strings used in an election package.
* Returns three packages of strings: app strings, HMPB strings, and election strings.
*/
export async function getAllStringsForElectionPackage(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: change get to translate to be more specific about what's happening

import { generateElectionPackage } from '../../generate-election-package';

// A script to generate an election package.
// Usage: ./generate-election-package <election_fixtures_directory_path> <is_multi_language> <force_restranslate>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API suggestions to improve clarity and better mesh with existing scripts in this lib:

  • Take a path to the election.json rather than requiring that it is named baseElection.json so the script can be used more flexibly
  • Instead of force_retranslate, optionally take a path to the election package that should be used as a translation cache (e.g. --reuse-translations <path_to_package>)
  • Change is_multi_language to a flag --multi-language. It's a bit confusing just seeing a 1 in the command
  • Require an output path to be specified --outputPath <path>

Take them or leave them, not blocking

// by passing a third argument of '1'.

// The generated election.json file for this election package will be stored alongside it in the
// election package directory for convenance.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: convenance -> convenience

): Promise<number> {
if (argv.length !== 5) {
stderr.write(
'Usage: generate-election-package <election_fixtures_directory_path> <is_multi_language> <force_restranslate>]\n'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling: force_restranslate -> force_retranslate


/**
* Mock implementation of the SpeechSynthesizer interface. Returns the input text with '(audio)' appended rather
* than a base64 encoded audio clip.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't seem to be accurate

@carolinemodic carolinemodic enabled auto-merge (squash) December 11, 2024 17:06
@carolinemodic carolinemodic merged commit 3f40050 into main Dec 11, 2024
62 checks passed
@carolinemodic carolinemodic deleted the caro/add_generate_election_package_script branch December 11, 2024 17:06
eventualbuddha pushed a commit that referenced this pull request Dec 12, 2024
* add generate-election-packages script with test when it needs regen

* make default latest metadata

* add version of electionPrimaryPrecinctSplits without ballot strings

* all new fixtures generated files

* fixtures build:resources

* export newly added fixtures for use in package generator test

* address pr comments

* fix refactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants