def test_current_badge(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        OfficerBadgeNumberFactory(officer=officer_1, star='123', current=True)
        OfficerBadgeNumberFactory(officer=officer_2, current=False)
        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()

        expect(officer_1.current_badge).to.eq('123')
        expect(officer_2.current_badge).to.eq(None)
    def test_trr_count(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        TRRFactory.create_batch(2, officer=officer_1)
        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()
        officer_2.refresh_from_db()

        expect(officer_1.trr_count).to.eq(2)
        expect(officer_2.trr_count).to.eq(0)
    def test_allegation_count(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        OfficerAllegationFactory.create_batch(2, final_finding='NS', officer=officer_1)
        OfficerAllegationFactory(final_finding='SU', officer=officer_1)
        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()
        officer_2.refresh_from_db()

        expect(officer_1.allegation_count).to.eq(3)
        expect(officer_2.allegation_count).to.eq(0)
    def test_discipline_count(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        OfficerAllegationFactory.create_batch(2, officer=officer_1, disciplined=True)
        OfficerAllegationFactory(officer=officer_1, disciplined=False)
        OfficerAllegationFactory(officer=officer_2, disciplined=False)
        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()
        officer_2.refresh_from_db()

        expect(officer_1.discipline_count).to.eq(2)
        expect(officer_2.discipline_count).to.eq(0)
    def test_last_unit(self):
        officer = OfficerFactory()
        expect(officer.last_unit).to.equal(None)

        last_unit = PoliceUnitFactory(unit_name='BDCH')

        OfficerHistoryFactory(officer=officer, unit=PoliceUnitFactory(unit_name='CAND'), end_date=date(2000, 1, 1))
        OfficerHistoryFactory(officer=officer, unit=last_unit, end_date=date(2002, 1, 1))
        officer_cache_manager.build_cached_columns()
        officer.refresh_from_db()

        expect(officer.last_unit).to.eq(last_unit)
    def test_major_award_count(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        AwardFactory(officer=officer_1, award_type='HONORED POLICE STAR')
        AwardFactory(officer=officer_1, award_type='POLICE MEDAL')
        AwardFactory(officer=officer_1, award_type='PIPE BAND AWARD')
        AwardFactory(officer=officer_1, award_type='LIFE SAVING AWARD')
        AwardFactory(officer=officer_2, award_type='LIFE SAVING AWARD')
        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()
        officer_2.refresh_from_db()

        expect(officer_1.major_award_count).to.eq(2)
        expect(officer_2.major_award_count).to.eq(0)
    def test_civilian_compliment_count(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        AwardFactory(officer=officer_1, award_type='Other')
        AwardFactory(officer=officer_1, award_type='Complimentary Letter')
        AwardFactory(officer=officer_1, award_type='Complimentary Letter')
        AwardFactory(officer=officer_1, award_type='Honorable Mention')
        AwardFactory(officer=officer_1, award_type='ABC Honorable Mention')
        AwardFactory(officer=officer_2, award_type='Honorable Mention')
        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()
        officer_2.refresh_from_db()

        expect(officer_1.civilian_compliment_count).to.eq(2)
        expect(officer_2.civilian_compliment_count).to.eq(0)
    def test_current_salary(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        expect(officer_1.current_salary).to.be.none()

        SalaryFactory(officer=officer_1, year=2010, salary=5000)
        SalaryFactory(officer=officer_1, year=2012, salary=10000)
        SalaryFactory(officer=officer_1, year=2015, salary=15000)
        SalaryFactory(officer=officer_1, year=2017, salary=20000)
        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()
        officer_2.refresh_from_db()

        expect(officer_1.current_salary).to.eq(20000)
        expect(officer_2.current_salary).to.be.none()
    def test_has_unique_name(self):
        officer_1 = OfficerFactory(first_name='Jerome', last_name='Finnigan')
        officer_2 = OfficerFactory(first_name='Jerome', last_name='Finnigan')
        officer_3 = OfficerFactory(first_name='German', last_name='Finnigan')
        officer_4 = OfficerFactory(first_name='Jerome', last_name='Piwinicki')
        officer_5 = OfficerFactory(first_name='German', last_name='Piwinicki')
        expect(officer_1.has_unique_name).to.be.false()
        expect(officer_2.has_unique_name).to.be.false()
        expect(officer_3.has_unique_name).to.be.false()
        expect(officer_4.has_unique_name).to.be.false()
        expect(officer_5.has_unique_name).to.be.false()

        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()
        officer_2.refresh_from_db()
        officer_3.refresh_from_db()
        officer_4.refresh_from_db()
        officer_5.refresh_from_db()

        expect(officer_1.has_unique_name).to.be.false()
        expect(officer_2.has_unique_name).to.be.false()
        expect(officer_3.has_unique_name).to.be.true()
        expect(officer_4.has_unique_name).to.be.true()
        expect(officer_5.has_unique_name).to.be.true()
Ejemplo n.º 10
0
    def test_request_complaint_summary(self):
        allegation = AllegationFactory(crid='11',
                                       incident_date=datetime(2002,
                                                              2,
                                                              28,
                                                              tzinfo=pytz.utc),
                                       summary='Summary')
        category = AllegationCategoryFactory(category='Use of Force')
        OfficerAllegationFactory(
            allegation=allegation,
            officer=OfficerFactory(appointed_date=date(2001, 1, 1)),
            start_date=date(2003, 2, 28),
            end_date=date(2004, 4, 28),
            allegation_category=category)
        OfficerAllegationFactory(
            allegation=allegation,
            officer=OfficerFactory(appointed_date=date(2001, 1, 1)),
            start_date=date(2003, 2, 28),
            end_date=date(2004, 4, 28),
            allegation_category=None)

        officer_cache_manager.build_cached_yearly_percentiles()
        officer_cache_manager.build_cached_columns()
        allegation_cache_manager.cache_data()

        response = self.client.get(reverse('api-v2:cr-complaint-summaries'))
        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expect(response.data).to.eq([{
            'crid':
            '11',
            'category_names': ['Unknown', 'Use of Force'],
            'incident_date':
            '2002-02-28',
            'summary':
            'Summary'
        }])
Ejemplo n.º 11
0
    def test_top_officers_by_allegation(self):
        OfficerFactory(
            id=1, first_name='Daryl', last_name='Mack',
            trr_percentile=12.0000,
            civilian_allegation_percentile=98.4344,
            internal_allegation_percentile=99.7840,
            complaint_percentile=99.3450,
            race='White', gender='M', birth_year=1975,
            rank='Police Officer'
        )
        OfficerFactory(
            id=2,
            first_name='Ronald', last_name='Watts',
            trr_percentile=0.0000,
            civilian_allegation_percentile=98.4344,
            internal_allegation_percentile=99.7840,
            complaint_percentile=99.5000,
            race='White', gender='M', birth_year=1975,
            rank='Detective'
        )
        OfficerFactory(
            id=3,
            first_name='Officer', last_name='low percentile',
            trr_percentile=0.0000,
            civilian_allegation_percentile=0.0000,
            internal_allegation_percentile=0.0000,
            complaint_percentile=96.3450,
            race='White', gender='M', birth_year=1975,
            rank=''
        )
        OfficerFactory(
            id=4,
            first_name='Officer', last_name='no visual token',
            trr_percentile=0.0000,
            internal_allegation_percentile=0.0000,
            complaint_percentile=99.8800,
            race='White', gender='M', birth_year=1975,
            rank='Police Officer'
        )
        OfficerFactory(
            id=5,
            first_name='Officer', last_name='filter out',
            trr_percentile=0.0000,
            civilian_allegation_percentile=0.0000,
            internal_allegation_percentile=0.0000,
            complaint_percentile=99.2000,
            race='White', gender='M', birth_year=1975,
            rank='Detective'
        )
        OfficerFactory(
            id=6,
            first_name='Officer', last_name='no percentiles',
            complaint_percentile=99.8000,
            race='White', gender='M', birth_year=1975,
            rank='Police Officer'
        )

        officer_cache_manager.build_cached_columns()
        allegation_cache_manager.cache_data()

        response = self.client.get(reverse('api-v2:officers-top-by-allegation'), {'limit': 2})
        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expect(response.data).to.have.length(2)
        expect(response.data).to.eq([{
            'id': 2,
            'full_name': 'Ronald Watts',
            'complaint_count': 0,
            'sustained_count': 0,
            'birth_year': 1975,
            'race': 'White',
            'gender': 'Male',
            'rank': 'Detective',
            'percentile_allegation': '99.5000',
            'percentile_allegation_civilian': '98.4344',
            'percentile_allegation_internal': '99.7840',
            'percentile_trr': '0.0000',
        }, {
            'id': 1,
            'full_name': 'Daryl Mack',
            'complaint_count': 0,
            'sustained_count': 0,
            'birth_year': 1975,
            'race': 'White',
            'gender': 'Male',
            'rank': 'Police Officer',
            'percentile_trr': '12.0000',
            'percentile_allegation': '99.3450',
            'percentile_allegation_civilian': '98.4344',
            'percentile_allegation_internal': '99.7840',
        }])
Ejemplo n.º 12
0
    def test_summary(self):
        officer = OfficerFactory(
            tags=[],
            first_name='Kevin', last_name='Kerl', id=123, race='White', gender='M',
            appointed_date=date(2017, 2, 27), rank='PO', resignation_date=date(2017, 12, 27),
            active=ACTIVE_YES_CHOICE, birth_year=1910, complaint_percentile=32.5,
            sustained_count=1, allegation_count=1, discipline_count=1, trr_count=1,
            civilian_compliment_count=1, honorable_mention_count=1, major_award_count=1,
            last_unit_id=1, current_badge='123456', current_salary=90000, has_unique_name=True
        )
        allegation = AllegationFactory()
        allegation_category = AllegationCategoryFactory(category='Use of Force')
        OfficerHistoryFactory(officer=officer, unit=PoliceUnitFactory(id=1, unit_name='CAND', description=''))
        ComplainantFactory(allegation=allegation, race='White', age=18, gender='F')
        OfficerBadgeNumberFactory(officer=officer, star='123456', current=True)
        OfficerAllegationFactory(
            officer=officer, allegation=allegation, allegation_category=allegation_category,
            final_finding='SU', start_date=date(2000, 1, 1), disciplined=True
        )
        AwardFactory(officer=officer, award_type='Complimentary Letter')
        AwardFactory(officer=officer, award_type='Honored Police Star')
        AwardFactory(officer=officer, award_type='Honorable Mention')
        SalaryFactory(officer=officer, salary=50000, year=2015)
        SalaryFactory(officer=officer, salary=90000, year=2017)
        TRRFactory(officer=officer)

        officer_cache_manager.build_cached_columns()
        allegation_cache_manager.cache_data()

        response = self.client.get(reverse('api-v2:officers-summary', kwargs={'pk': 123}))
        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expected_data = {
            'id': 123,
            'unit': {
                'id': 1,
                'unit_name': 'CAND',
                'description': '',
                'long_unit_name': 'Unit CAND',
            },
            'date_of_appt': '2017-02-27',
            'date_of_resignation': '2017-12-27',
            'active': 'Active',
            'rank': 'PO',
            'full_name': 'Kevin Kerl',
            'race': 'White',
            'badge': '123456',
            'historic_units': [{
                'id': 1,
                'unit_name': 'CAND',
                'description': '',
                'long_unit_name': 'Unit CAND'
            }],
            'gender': 'Male',
            'birth_year': 1910,
            'sustained_count': 1,
            'civilian_compliment_count': 1,
            'allegation_count': 1,
            'discipline_count': 1,
            'honorable_mention_count': 1,
            'to': '/officer/123/kevin-kerl/',
            'url': 'http://cpdb.lvh.me/officer/kevin-kerl/123',
            'current_salary': 90000,
            'trr_count': 1,
            'major_award_count': 1,
            'unsustained_count': 0,
            'percentile_allegation': '32.5000',
            'coaccusals': [],
            'percentiles': [],
            'tags': [],
            'historic_badges': [],
            'has_unique_name': True
        }
        expect(response.data).to.eq(expected_data)
Ejemplo n.º 13
0
    def test_retrieve(self):
        area = AreaFactory(name='Lincoln Square')
        officer1 = OfficerFactory(
            id=123,
            first_name='Mr',
            last_name='Foo',
            gender='M',
            race='White',
            rank='Officer',
            appointed_date=date(2001, 1, 1),
            birth_year=1993,
            complaint_percentile=4.4,
            civilian_allegation_percentile=1.1,
            internal_allegation_percentile=2.2,
            trr_percentile=3.3,
            allegation_count=1,
            sustained_count=1,
        )
        OfficerBadgeNumberFactory(officer=officer1, star='12345', current=True)
        allegation = AllegationFactory(crid='12345',
                                       point=Point(12, 21),
                                       incident_date=datetime(2002,
                                                              2,
                                                              28,
                                                              tzinfo=pytz.utc),
                                       add1=3510,
                                       add2='Michigan Ave',
                                       city='Chicago',
                                       location='Police Communications System',
                                       beat=area,
                                       is_officer_complaint=False,
                                       summary='Summary',
                                       first_start_date=date(2003, 3, 20),
                                       first_end_date=date(2006, 5, 26))
        ComplainantFactory(allegation=allegation,
                           gender='M',
                           race='Black',
                           age='18')
        VictimFactory(allegation=allegation, gender='M', race='Black', age=53)
        OfficerAllegationFactory(
            officer=officer1,
            allegation=allegation,
            final_finding='SU',
            disciplined=True,
            final_outcome='Separation',
            recc_outcome='10 Day Suspension',
            start_date=date(2003, 3, 20),
            end_date=date(2006, 5, 26),
            allegation_category=AllegationCategoryFactory(
                category='Operation/Personnel Violations',
                allegation_name='Secondary/Special Employment'))
        officer = OfficerFactory(
            id=3,
            first_name='Raymond',
            last_name='Piwinicki',
            appointed_date=date(2001, 5, 1),
            complaint_percentile=4.4,
            trr_percentile=5.5,
            allegation_count=1,
            sustained_count=1,
        )
        OfficerAllegationFactory(officer=officer,
                                 final_finding='SU',
                                 start_date=date(2003, 2, 28),
                                 allegation__incident_date=datetime(
                                     2002, 2, 28, tzinfo=pytz.utc),
                                 allegation__is_officer_complaint=False)
        PoliceWitnessFactory(officer=officer, allegation=allegation)
        investigator = OfficerFactory(
            id=1,
            first_name='Ellis',
            last_name='Skol',
            appointed_date=date(2001, 5, 1),
            complaint_percentile=6.6,
            civilian_allegation_percentile=7.7,
            internal_allegation_percentile=8.8,
            allegation_count=1,
            sustained_count=0,
        )
        OfficerAllegationFactory(officer=investigator,
                                 final_finding='NS',
                                 start_date=date(2003, 2, 28),
                                 allegation__incident_date=datetime(
                                     2002, 2, 28, tzinfo=pytz.utc),
                                 allegation__is_officer_complaint=False)
        investigator = InvestigatorFactory(officer=investigator)
        InvestigatorAllegationFactory(allegation=allegation,
                                      investigator=investigator,
                                      current_rank='IPRA investigator')

        AttachmentFileFactory(tag='TRR',
                              allegation=allegation,
                              title='CR document',
                              id='123456',
                              url='http://cr-document.com/',
                              file_type=MEDIA_TYPE_DOCUMENT)
        AttachmentFileFactory(tag='TRR',
                              allegation=allegation,
                              title='CR arrest report document',
                              url='http://cr-document.com/',
                              file_type=MEDIA_TYPE_DOCUMENT)
        AttachmentFileFactory(tag='AR',
                              allegation=allegation,
                              title='CR document 2',
                              id='654321',
                              url='http://AR-document.com/',
                              file_type=MEDIA_TYPE_DOCUMENT)

        officer_cache_manager.build_cached_columns()
        allegation_cache_manager.cache_data()

        response = self.client.get(
            reverse('api-v2:cr-detail', kwargs={'pk': '12345'}))
        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expect(dict(response.data)).to.eq({
            'crid':
            '12345',
            'most_common_category': {
                'category': 'Operation/Personnel Violations',
                'allegation_name': 'Secondary/Special Employment'
            },
            'coaccused': [{
                'id': 123,
                'full_name': 'Mr Foo',
                'gender': 'Male',
                'race': 'White',
                'rank': 'Officer',
                'birth_year': 1993,
                'recommended_outcome': '10 Day Suspension',
                'final_outcome': 'Separation',
                'final_finding': 'Sustained',
                'category': 'Operation/Personnel Violations',
                'complaint_count': 1,
                'sustained_count': 1,
                'percentile_allegation': '4.4000',
                'percentile_allegation_civilian': '1.1000',
                'percentile_allegation_internal': '2.2000',
                'percentile_trr': '3.3000',
                'disciplined': True
            }],
            'complainants': [{
                'race': 'Black',
                'gender': 'Male',
                'age': 18
            }],
            'victims': [{
                'race': 'Black',
                'gender': 'Male',
                'age': 53
            }],
            'point': {
                'lon': 12.0,
                'lat': 21.0
            },
            'summary':
            'Summary',
            'incident_date':
            '2002-02-28',
            'start_date':
            '2003-03-20',
            'end_date':
            '2006-05-26',
            'address':
            '3510 Michigan Ave, Chicago',
            'location':
            'Police Communications System',
            'beat':
            'Lincoln Square',
            'involvements': [{
                'involved_type': 'investigator',
                'officer_id': 1,
                'full_name': 'Ellis Skol',
                'badge': 'CPD',
                'percentile_allegation': '6.6000',
                'percentile_allegation_civilian': '7.7000',
                'percentile_allegation_internal': '8.8000',
            }, {
                'involved_type': 'police_witness',
                'officer_id': 3,
                'full_name': 'Raymond Piwinicki',
                'allegation_count': 1,
                'sustained_count': 1,
                'percentile_trr': '5.5000',
                'percentile_allegation': '4.4000',
            }],
            'attachments': [{
                'title': 'CR document',
                'file_type': 'document',
                'url': 'http://cr-document.com/',
                'id': '123456',
            }]
        })
Ejemplo n.º 14
0
    def test_retrieve_data_range_too_small_cause_no_percentiles(self):

        officer = OfficerFactory(
            tags=[],
            first_name='Kevin', last_name='Kerl', id=123, race='White', gender='M',
            appointed_date=date(2002, 2, 27), rank='PO', resignation_date=date(2017, 12, 27),
            active=ACTIVE_YES_CHOICE, birth_year=1960, complaint_percentile=32.5,
            sustained_count=1, allegation_count=2, discipline_count=1, trr_count=1,
            civilian_compliment_count=1, honorable_mention_count=1, major_award_count=1,
            last_unit_id=1, current_badge='123456'
        )
        allegation = AllegationFactory(incident_date=datetime(2002, 3, 1, tzinfo=pytz.utc))
        internal_allegation = AllegationFactory(
            incident_date=datetime(2002, 4, 1, tzinfo=pytz.utc),
            is_officer_complaint=True
        )
        allegation_category = AllegationCategoryFactory(category='Use of Force')
        OfficerHistoryFactory(
            officer=officer, effective_date=datetime(2002, 2, 27, tzinfo=pytz.utc),
            unit=PoliceUnitFactory(id=1, unit_name='CAND', description='')
        )
        ComplainantFactory(allegation=allegation, race='White', age=18, gender='F')
        OfficerBadgeNumberFactory(officer=officer, star='123456', current=True)
        OfficerBadgeNumberFactory(officer=officer, star='789', current=False)
        OfficerAllegationFactory(
            officer=officer, allegation=allegation, allegation_category=allegation_category,
            final_finding='SU', start_date=date(2002, 3, 2), disciplined=True
        )
        OfficerAllegationFactory(
            officer=officer, allegation=internal_allegation,
            final_finding='NS', start_date=date(2002, 3, 2), disciplined=False
        )
        AwardFactory(officer=officer, award_type='Complimentary Letter', start_date=date(2014, 5, 1))
        AwardFactory(officer=officer, award_type='Honored Police Star', start_date=date(2014, 6, 1))
        AwardFactory(officer=officer, award_type='Honorable Mention', start_date=date(2014, 7, 1))
        SalaryFactory(officer=officer, salary=50000, year=2002)
        SalaryFactory(officer=officer, salary=90000, year=2017)
        TRRFactory(officer=officer, trr_datetime=datetime(2002, 3, 1, tzinfo=pytz.utc))

        second_officer = OfficerFactory(
            tags=[],
            first_name='Kevin', last_name='Osborn', id=456, race='Black', gender='M',
            appointed_date=date(2002, 1, 27), resignation_date=date(2017, 12, 27), rank='PO',
            active=ACTIVE_YES_CHOICE, birth_year=1970
        )
        TRRFactory(officer=second_officer, trr_datetime=datetime(2002, 5, 1, tzinfo=pytz.utc))
        TRRFactory(officer=second_officer, trr_datetime=datetime(2002, 12, 1, tzinfo=pytz.utc))

        OfficerFactory(
            tags=[],
            first_name='Kevin', last_name='Edward', id=789, race='Black', gender='M',
            appointed_date=date(2002, 3, 27), resignation_date=date(2017, 12, 27), rank='PO',
            active=ACTIVE_YES_CHOICE, birth_year=1970
        )

        officer_cache_manager.build_cached_columns()
        allegation_cache_manager.cache_data()

        response = self.client.get(reverse('api-v2:officers-mobile-detail', kwargs={'pk': 123}))
        expected_response = {
            'officer_id': 123,
            'unit': {
                'unit_id': 1,
                'unit_name': 'CAND',
                'description': '',
            },
            'date_of_appt': '2002-02-27',
            'date_of_resignation': '2017-12-27',
            'active': 'Active',
            'rank': 'PO',
            'full_name': 'Kevin Kerl',
            'race': 'White',
            'badge': '123456',
            'historic_badges': ['789'],
            'gender': 'Male',
            'birth_year': 1960,
            'sustained_count': 1,
            'unsustained_count': 1,
            'civilian_compliment_count': 1,
            'allegation_count': 2,
            'discipline_count': 1,
            'honorable_mention_count': 1,
            'trr_count': 1,
            'major_award_count': 1,
            'percentile_allegation': '32.5000',
            'percentiles': []
        }
        expect(response.data).to.eq(expected_response)