datamade / bga-payroll

💰 How much do your public officials make?
4 stars 4 forks source link

Classification/data issue - Marywood and North Aurora FPD #500

Closed deraj1013 closed 4 years ago

deraj1013 commented 4 years ago

Another oddball...Marywood FPD and North Aurora FPD don't seem to show up when I search for them in the employer list. They also show up as unclassified employers on the dev site. This is minor, but I'd like to be able to classify these and link data to them.

https://bga-payroll.datamade.us/unit/north-aurora-fpd-c7190b29/?data_year=2017

hancush commented 4 years ago

For my own reference, both show up in the Employer search:

They do not show up in the responding agency list when adding source files, e.g.,

Screen Shot 2020-09-21 at 8 26 19 AM

Looking into it.

hancush commented 4 years ago

@deraj1013 Patched. Not sure what happened with North Aurora FPD, but Marywood FPD had a responding agency ID of 967 in the data, which maps to Hoffman Estates FPD in our lookup table.

Let me know if you have any more issues like this!

hancush commented 4 years ago

Again for my reference, here's what I did to fix the issue:


>>> from data_import import *
>>> from payroll.models import *
# North Aurora FPD had no responding agency
>>> e = Unit.objects.get(slug='north-aurora-fpd-c7190b29')
>>> e
<Unit: North Aurora FPD>
>>> e.responding_agencies.all()
<QuerySet []>
>>> RespondingAgency.objects.filter(name='North Aurora FPD')
<QuerySet []>
# Created one, then created the relationship to link it to North Aurora in 2017
>>> ra = RespondingAgency.objects.create(name='North Aurora FPD')
>>> UnitRespondingAgency.objects.create(unit=e, responding_agency=ra, reporting_year=2017)
<UnitRespondingAgency: UnitRespondingAgency object (12221)>
# Marywood FPD had the wrong responding agency
>>> e = Unit.objects.get(slug='marywood-fpd-f771dd9f')
>>> e.responding_agencies.all()
<QuerySet [<UnitRespondingAgency: UnitRespondingAgency object (9749)>]>
>>> e.responding_agencies.get().responding_agency
<RespondingAgency: Hoffman Estates FPD>
>>> UnitRespondingAgency.objects.get(id=9749)
<UnitRespondingAgency: UnitRespondingAgency object (9749)>
>>> UnitRespondingAgency.objects.get(id=9749).unit
<Employer: Marywood FPD>
>>> UnitRespondingAgency.objects.get(id=9749).responding_agency
<RespondingAgency: Hoffman Estates FPD>
# Removed the incorrect relationship
>>> UnitRespondingAgency.objects.get(id=9749).delete()
(1, {'payroll.UnitRespondingAgency': 1})
>>> RespondingAgency.objects.filter(name='Marywood FPD')
<QuerySet []>
>>> ra = RespondingAgency.objects.create(name='Marywood FPD')
>>> e
<Unit: Marywood FPD>
>>> ra
<RespondingAgency: Marywood FPD>
# Created the right one
>>> UnitRespondingAgency.objects.create(unit=e, responding_agency=ra, reporting_year=2017)
<UnitRespondingAgency: UnitRespondingAgency object (12222)>