Schema validations, migrations, and conversions to standardize the Ranked Choice Voting ecosystem
Project description
RCV Formats
Build tools for the Ranked Choice Voting Ecosystem without having to support each file format individually. RCV Formats converts data from several sources into a single, standardized format with just one line of code:
from rcvformats.conversions.automatic import AutomaticConverter
standardized_format = AutomaticConverter().convert_to_ut("any-file-format.json")
The standardized format is the Universal RCV Tabulator JSON. To understand this format, look at examples or the jsonschema.
Installation
pip3 install rcvformats
Additional Options
RCV Formats can also run schema validations and conversions from specific formats.
Schema Validation
Validate that your file format matches one of several available schemas:
- The Universal RCV Tabulator JSON format
- The Opavote JSON format
- The ElectionBuddy CSV format
Currently, validation is only on the structure of the data, not on its contents: it is possible for a validly-formatted file to still contain invalid data.
You can run the validation and examine errors via:
from rcvformats.schemas import universaltabulator
schema = universaltabulator.SchemaV0()
is_valid = schema.validate('/path/to/file.json')
if not is_valid:
print(schema.last_error())
Valid schema validators are:
from rcvformats.schemas.electionbuddy import SchemaV0
from rcvformats.schemas.opavote import SchemaV1_0
from rcvformats.schemas.universaltabulator import SchemaV0
File Format Conversion
You can convert from any of the supported formats and to the Universal RCV Tabulator format. The currently supported formats are:
- ElectionBuddy CSVs
- Opavote JSONs
You can run the conversion via:
from rcvformats.conversions import electionbuddy
converter = electionbuddy.ElectionBuddyConverter()
try:
converter.convert_to_ut(filename)
except Exception as e:
print("Errors: ", e)
Valid converters are:
from rcvformats.converters.automatic import AutomaticConverter
from rcvformats.conversions.electionbuddy import ElectionBuddyConverter
from rcvformats.conversions.opavote import OpavoteConverter
The AutomaticConverter checks if the file matches any of the available schemas, and if it finds a matching schema, it runs the corresponding conversion (if a conversion is needed at all).
Upcoming plans
- Allow any format to be converted both to and from the Universal Tabulator format
- More unit tests
- Create both structure and data validations for the Universal Tabulator format
- Validation for both tabulated formats and cast vote records
Running test suite
Run nosetests
in the root directory
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for rcvformats-0.0.19-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 530830355534341b485f11dca245602fcded111cf2bedeb6424dec59e6e66fb8 |
|
MD5 | 723d1a647376946fb3223866064c4170 |
|
BLAKE2b-256 | 6388f779df79b108614910f10b955edbcacbe2ecb2213e6a3f5e864673220332 |