Redistricting Analytics in Python
This repository (rdapy) re-implements the main analytics used in Dave's Redistricting (DRA), ignoring a few DRA-specific aspects (in particular, the five [0-100] ratings). Unlike the analytics used in the app (dra-analytics) which are implememented in TypeScript, these are implemented in Python to make them easier to use outside of DRA.
There are both a PyPi package and a command-line interface. They are described in detail at the website for this repository.
To install the package:
pip install rdapyThe latest version of the package is 2.3.3.
Then in your code, either import rdapy or from rdapy import ....
To setup the repository for local command-line use:
Clone the repository:
git clone https://github.com/dra2020/rdapy
cd rdapyThen create a virtual environment that uses Python 3.12.
Then reset Python outside the virtual environment to the normal setting.
For example, using pyenv:
pyenv shell 3.12
python3 -m venv "./rdapy"
source "./rdapy/bin/activate"
deactivate
pyenv shell --unsetThen activate the virtual environment again, and install the required dependencies:
source "./rdapy/bin/activate"
pip install -r requirements.txt
pip install --upgrade pipFinally, test that the automated tests run:
pytestand that the command-line interface works:
scripts/score/SCORE.sh \
--state NC \
--plan-type congress \
--geojson testdata/data/NC_vtd_datasets.v4.geojson \
--graph testdata/examples/NC_graph.json \
--precomputed testdata/precomputed/NC_congress_precomputed.json \
--plans testdata/plans/NC_congress_plans.tagged.jsonl \
--scores temp/TEST_congress_scores.csv \
--by-district temp/TEST_congress_by-district.jsonlThere is a launch.json for VS Code debugging in the docs directory.
Run automated tests with:
pytestEmail questions to feedback.