diff --git a/CHANGELOG.md b/CHANGELOG.md index ae4edde..8a3d52b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.0.5] - 2022-11-04 + +- [#39] Remove locality from race ID, add it back to subunit ID + ## [0.0.4] - 2022-11-04 - [#36] Remove county ID from precinct ID diff --git a/setup.py b/setup.py index 1369351..5491bd9 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ LONG_DESCRIPTION = f.read() # The full version, including alpha/beta/rc tags -RELEASE = '0.0.4' +RELEASE = '0.0.5' # The short X.Y version VERSION = '.'.join(RELEASE.split('.')[:2]) diff --git a/src/elexclarity/convert.py b/src/elexclarity/convert.py index 504b1d7..be50a43 100644 --- a/src/elexclarity/convert.py +++ b/src/elexclarity/convert.py @@ -53,6 +53,9 @@ def convert( data, vote_completion_mode=vote_completion_mode, office_id=office_id, + omit_locality_from_race_id=kwargs.get( + "omit_locality_from_race_id", True + ), **kwargs ) diff --git a/src/elexclarity/formatters/base.py b/src/elexclarity/formatters/base.py index 26ac33c..4ecb4f4 100644 --- a/src/elexclarity/formatters/base.py +++ b/src/elexclarity/formatters/base.py @@ -57,7 +57,7 @@ def get_choice_id(cls, name): return slugify(name, separator="_") def get_precinct_id(self, name, county_id=None): - return slugify(name, separator="-") + return "_".join(filter(None,[county_id, slugify(name, separator='-')])) def get_county_id(self, name): """ diff --git a/src/elexclarity/formatters/results.py b/src/elexclarity/formatters/results.py index 109ff2b..f3033a8 100644 --- a/src/elexclarity/formatters/results.py +++ b/src/elexclarity/formatters/results.py @@ -200,7 +200,7 @@ def format_race( election_type, office ] - if level == "precinct": + if level == "precinct" and not kwargs.get("omit_locality_from_race_id"): id_parts.append(county_id) race_id = "_".join(id_parts) diff --git a/tests/formatters/test_results.py b/tests/formatters/test_results.py index 50219dd..beb4964 100644 --- a/tests/formatters/test_results.py +++ b/tests/formatters/test_results.py @@ -20,7 +20,7 @@ def test_georgia_precinct_formatting_basic(atkinson_precincts, ga_county_mapping assert counts["jo_jorgensen_lib"] == 30 # Pearson City precinct - pearson = results["2020-11-03_GA_G_P_13003"]["subunits"]["pearson-city"] + pearson = results["2020-11-03_GA_G_P_13003"]["subunits"]["13003_pearson-city"] assert pearson["precinctsReportingPct"] == 100 assert pearson["expectedVotes"] == 564 assert pearson["counts"]["donald_j_trump_i_rep"] == 229 @@ -28,7 +28,7 @@ def test_georgia_precinct_formatting_basic(atkinson_precincts, ga_county_mapping assert pearson["counts"]["jo_jorgensen_lib"] == 6 # Willacoochee precinct - willacoochee = results["2020-11-03_GA_G_P_13003"]["subunits"]["willacoochee"] + willacoochee = results["2020-11-03_GA_G_P_13003"]["subunits"]["13003_willacoochee"] assert willacoochee["precinctsReportingPct"] == 100 assert willacoochee["expectedVotes"] == 522 assert willacoochee["counts"]["donald_j_trump_i_rep"] == 342 @@ -45,12 +45,12 @@ def test_georgia_precinct_formatting_vote_types_completion_mode(atkinson_precinc ) # Pearson City precinct - pearson = results["2020-11-03_GA_G_P_13003"]["subunits"]["pearson-city"] + pearson = results["2020-11-03_GA_G_P_13003"]["subunits"]["13003_pearson-city"] assert pearson["precinctsReportingPct"] == 100 assert pearson["expectedVotes"] == 564 # Willacoochee precinct - willacoochee = results["2020-11-03_GA_G_P_13003"]["subunits"]["willacoochee"] + willacoochee = results["2020-11-03_GA_G_P_13003"]["subunits"]["13003_willacoochee"] assert willacoochee["precinctsReportingPct"] == 0 assert willacoochee.get("expectedVotes") is None