Skip to content
 
 

Repository files navigation

rdapy

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.

Installing the Package

To install the package:

pip install rdapy

The latest version of the package is 2.3.3.

Then in your code, either import rdapy or from rdapy import ....

Setting up the Command-Line Interface

To setup the repository for local command-line use:

Clone the repository:

git clone https://github.com/dra2020/rdapy
cd rdapy

Then 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 --unset

Then activate the virtual environment again, and install the required dependencies:

source "./rdapy/bin/activate"
pip install -r requirements.txt
pip install --upgrade pip

Finally, test that the automated tests run:

pytest

and 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.jsonl

Development

There is a launch.json for VS Code debugging in the docs directory.

Testing

Run automated tests with:

pytest

Questions

Email questions to feedback.

About

Redistricting analytics in Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages