Skip to content

Commit

Permalink
Merge pull request #139 from openstates/resolve-person-with-chamber-c…
Browse files Browse the repository at this point in the history
…ontext

Use incoming Chamber in resolve_person() to improve sponsorship matches
  • Loading branch information
jessemortenson authored Sep 10, 2024
2 parents dc4488e + ee86245 commit d16a958
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions openstates/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,12 @@ def resolve_person(

# turn spec into DB query
spec = get_pseudo_id(psuedo_person_id)

# if chamber is included in pseudo_person_id, use that as org_classification
if "chamber" in spec and org_classification is None:
org_classification = spec["chamber"]
del spec["chamber"]

if list(spec.keys()) == ["name"]:
# if we're just resolving on name, include other names and family name
name = spec["name"]
Expand Down
7 changes: 5 additions & 2 deletions openstates/scrape/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def add_sponsorship(
entity_type,
primary,
*,
chamber=None,
chamber=None, # upper, lower or legislature
entity_id=None,
):
sp = {
Expand All @@ -124,7 +124,10 @@ def add_sponsorship(
# overwrite the id that exists
if entity_type:
if not entity_id:
entity_id = _make_pseudo_id(name=name)
if chamber is not None:
entity_id = _make_pseudo_id(name=name, chamber=chamber)
else:
entity_id = _make_pseudo_id(name=name)
sp[entity_type + "_id"] = entity_id
if sp in self.sponsorships:
warnings.warn(f"duplicate sponsor {sp}", RuntimeWarning)
Expand Down
2 changes: 1 addition & 1 deletion openstates/scrape/tests/test_bill_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_add_sponsor():
)
assert len(b.sponsorships) == 1
assert b.sponsorships[0] == {
"person_id": '~{"name": "Joe Bleu"}',
"person_id": '~{"chamber": "upper", "name": "Joe Bleu"}',
"name": "Joe Bleu",
"classification": "Author",
"entity_type": "person",
Expand Down

0 comments on commit d16a958

Please sign in to comment.