def test_top_incident_reasons_by_timeframes_returns_proper_counts(self):
        [StandardizedFireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(5),
                             actual_nfirs_incident_type_description="Broken Nose")
         for i in range(0, 5)]
        [StandardizedFireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(20),
                             actual_nfirs_incident_type_description="Stubbed Toe")
         for i in range(0, 8)]
        [StandardizedFireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(40),
                             actual_nfirs_incident_type_description="Myocardial Infarction")
         for i in range(0, 7)]
        [StandardizedFireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(200),
                             actual_nfirs_incident_type_description="Lung Fell Off")
         for i in range(0, 10)]

        [StandardizedPoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(5),
                               final_cad_call_type_description="Stepped on a Crack")
         for i in range(0, 3)]
        [StandardizedPoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(20),
                               final_cad_call_type_description="Whipped It")
         for i in range(0, 8)]
        [StandardizedPoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(40),
                               final_cad_call_type_description="Safety Dance")
         for i in range(0, 9)]
        [StandardizedPoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(200),
                               final_cad_call_type_description="Runnin' With The Devil")
         for i in range(0, 6)]


        db.session.flush()


        incidents = fetch_incidents_at_address("123 MAIN ST")
        actual_top_reasons = get_top_incident_reasons_by_timeframes(incidents, [7, 30, 90, 365])

        expected_top_reasons = {
           'fire': {
               7: [('Broken Nose', 5)],
               30: [('Stubbed Toe', 8), ('Broken Nose', 5)],
               90: [('Stubbed Toe', 8), ('Myocardial Infarction', 7), ('Broken Nose', 5)],
               365: [('Lung Fell Off', 10), ('Stubbed Toe', 8), ('Myocardial Infarction', 7), ('Broken Nose', 5)]
           },
           'police': {
               7: [('Stepped on a Crack', 3)],
               30: [('Whipped It', 8), ('Stepped on a Crack', 3)],
               90: [('Safety Dance', 9), ('Whipped It', 8), ('Stepped on a Crack', 3)],
               365: [('Safety Dance', 9), ('Whipped It', 8), ("Runnin' With The Devil", 6), ('Stepped on a Crack', 3)]
           }
        }

        self.assertEquals(expected_top_reasons, actual_top_reasons)
Beispiel #2
0
    def test_top_incident_reasons_by_timeframes_returns_proper_counts(self):
        [FireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(5),
                             actual_nfirs_incident_type_description="Broken Nose")
         for i in range(0, 5)]
        [FireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(20),
                             actual_nfirs_incident_type_description="Stubbed Toe")
         for i in range(0, 8)]
        [FireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(40),
                             actual_nfirs_incident_type_description="Myocardial Infarction")
         for i in range(0, 7)]
        [FireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(200),
                             actual_nfirs_incident_type_description="Lung Fell Off")
         for i in range(0, 10)]

        [PoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(5),
                               final_cad_call_type_description="Stepped on a Crack")
         for i in range(0, 3)]
        [PoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(20),
                               final_cad_call_type_description="Whipped It")
         for i in range(0, 8)]
        [PoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(40),
                               final_cad_call_type_description="Safety Dance")
         for i in range(0, 9)]
        [PoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(200),
                               final_cad_call_type_description="Runnin' With The Devil")
         for i in range(0, 6)]


        db.session.flush()


        incidents = fetch_incidents_at_address("123 MAIN ST")
        actual_top_reasons = get_top_incident_reasons_by_timeframes(incidents, [7, 30, 90, 365])

        expected_top_reasons = {
           'fire': {
               7: [('Broken Nose', 5)],
               30: [('Stubbed Toe', 8), ('Broken Nose', 5)],
               90: [('Stubbed Toe', 8), ('Myocardial Infarction', 7), ('Broken Nose', 5)],
               365: [('Lung Fell Off', 10), ('Stubbed Toe', 8), ('Myocardial Infarction', 7), ('Broken Nose', 5)]
           },
           'police': {
               7: [('Stepped on a Crack', 3)],
               30: [('Whipped It', 8), ('Stepped on a Crack', 3)],
               90: [('Safety Dance', 9), ('Whipped It', 8), ('Stepped on a Crack', 3)],
               365: [('Safety Dance', 9), ('Whipped It', 8), ("Runnin' With The Devil", 6), ('Stepped on a Crack', 3)]
           }
        }

        self.assertEquals(expected_top_reasons, actual_top_reasons)
Beispiel #3
0
    def test_count_incidents_returns_proper_counts_for_default_days(self):
        [
            FireIncidentFactory(standardized_address="123 MAIN ST",
                                alarm_datetime=get_date_days_ago(5))
            for i in range(0, 5)
        ]
        [
            FireIncidentFactory(standardized_address="123 MAIN ST",
                                alarm_datetime=get_date_days_ago(20))
            for i in range(0, 8)
        ]
        [
            FireIncidentFactory(standardized_address="123 MAIN ST",
                                alarm_datetime=get_date_days_ago(40))
            for i in range(0, 7)
        ]
        [
            FireIncidentFactory(standardized_address="123 MAIN ST",
                                alarm_datetime=get_date_days_ago(200))
            for i in range(0, 10)
        ]

        [
            PoliceIncidentFactory(standardized_address="123 MAIN ST",
                                  call_datetime=get_date_days_ago(5))
            for i in range(0, 3)
        ]
        [
            PoliceIncidentFactory(standardized_address="123 MAIN ST",
                                  call_datetime=get_date_days_ago(20))
            for i in range(0, 8)
        ]
        [
            PoliceIncidentFactory(standardized_address="123 MAIN ST",
                                  call_datetime=get_date_days_ago(40))
            for i in range(0, 9)
        ]
        [
            PoliceIncidentFactory(standardized_address="123 MAIN ST",
                                  call_datetime=get_date_days_ago(200))
            for i in range(0, 6)
        ]

        db.session.flush()

        incidents = fetch_incidents_at_address("123 main st")
        counts = count_incidents_by_timeframes(incidents, [7, 30, 90, 365])

        assert counts['fire'][7] == 5
        assert counts['fire'][30] == 13
        assert counts['fire'][90] == 20
        assert counts['fire'][365] == 30

        assert counts['police'][7] == 3
        assert counts['police'][30] == 11
        assert counts['police'][90] == 20
        assert counts['police'][365] == 26
Beispiel #4
0
    def test_fetch_incidents_at_address_returns_all_empty_types(self):

        incidents = fetch_incidents_at_address("123 main st")

        assert 'fire' in incidents
        assert 'police' in incidents
        assert 'businesses' in incidents

        assert len(incidents['fire']) == 0
        assert len(incidents['police']) == 0
        assert len(incidents['businesses']) == 0
Beispiel #5
0
    def test_fetch_incidents_at_address_returns_all_empty_types(self):

        incidents = fetch_incidents_at_address("123 main st")

        assert 'fire' in incidents
        assert 'police' in incidents
        assert 'businesses' in incidents

        assert len(incidents['fire']) == 0
        assert len(incidents['police']) == 0
        assert len(incidents['businesses']) == 0
Beispiel #6
0
    def test_count_incidents_returns_zeros_when_no_incidents(self):
        incidents = fetch_incidents_at_address("123 main st")
        counts = count_incidents_by_timeframes(incidents, [7, 30, 90, 365])

        assert counts['fire'][7] == 0
        assert counts['fire'][30] == 0
        assert counts['fire'][90] == 0
        assert counts['fire'][365] == 0

        assert counts['police'][7] == 0
        assert counts['police'][30] == 0
        assert counts['police'][90] == 0
        assert counts['police'][365] == 0
Beispiel #7
0
    def test_count_incidents_returns_zeros_when_no_incidents(self):
        incidents = fetch_incidents_at_address("123 main st")
        counts = count_incidents_by_timeframes(incidents, [7, 30, 90, 365])

        assert counts['fire'][7] == 0
        assert counts['fire'][30] == 0
        assert counts['fire'][90] == 0
        assert counts['fire'][365] == 0

        assert counts['police'][7] == 0
        assert counts['police'][30] == 0
        assert counts['police'][90] == 0
        assert counts['police'][365] == 0
Beispiel #8
0
    def test_fetch_incident_at_address_works_if_lowercase_supplied(self):
        [FireIncidentFactory(standardized_address="123 MAIN ST")
         for i in range(0, 5)]
        [PoliceIncidentFactory(standardized_address="123 MAIN ST")
         for i in range(0, 3)]
        [BusinessLicenseFactory(business_address="123 MAIN ST")
         for i in range(0, 1)]

        db.session.flush()

        incidents = fetch_incidents_at_address("123 main st")
        assert len(incidents['fire']) == 5
        assert len(incidents['police']) == 3
        assert len(incidents['businesses']) == 1
Beispiel #9
0
    def test_fetch_incident_at_address_returns_correct_number_of_items(self):
        [FireIncidentFactory(standardized_address="123 MAIN ST")
         for i in range(5)]
        [PoliceIncidentFactory(standardized_address="123 MAIN ST")
         for i in range(3)]
        [BusinessLicenseFactory(business_address="123 MAIN ST")
         for i in range(1)]

        db.session.flush()

        incidents = fetch_incidents_at_address("123 MAIN ST")
        assert len(incidents['fire']) == 5
        assert len(incidents['police']) == 3
        assert len(incidents['businesses']) == 1
    def test_fetch_incident_at_address_works_if_lowercase_supplied(self):
        [StandardizedFireIncidentFactory(standardized_address="123 MAIN ST")
         for i in range(0, 5)]
        [StandardizedPoliceIncidentFactory(standardized_address="123 MAIN ST")
         for i in range(0, 3)]
        [BusinessLicenseFactory(business_address="123 MAIN ST")
         for i in range(0, 1)]

        db.session.flush()

        incidents = fetch_incidents_at_address("123 main st")
        assert len(incidents['fire']) == 5
        assert len(incidents['police']) == 3
        assert len(incidents['businesses']) == 1
    def test_fetch_incident_at_address_returns_correct_number_of_items(self):
        [StandardizedFireIncidentFactory(standardized_address="123 MAIN ST")
         for i in range(5)]
        [StandardizedPoliceIncidentFactory(standardized_address="123 MAIN ST")
         for i in range(3)]
        [BusinessLicenseFactory(business_address="123 MAIN ST")
         for i in range(1)]

        db.session.flush()

        incidents = fetch_incidents_at_address("123 MAIN ST")
        assert len(incidents['fire']) == 5
        assert len(incidents['police']) == 3
        assert len(incidents['businesses']) == 1
Beispiel #12
0
    def test_top_incident_reasons_by_timeframes_returns_empty_lists_if_no_incident(self):
        incidents = fetch_incidents_at_address("123 MAIN ST")
        actual_top_reasons = get_top_incident_reasons_by_timeframes(incidents, [7, 30, 90, 365])

        expected_top_reasons = {
           'fire': {
               7: [],
               30: [],
               90: [],
               365: []
           },
           'police': {
               7: [],
               30: [],
               90: [],
               365: []
           }
        }

        self.assertEquals(expected_top_reasons, actual_top_reasons)
    def test_top_incident_reasons_by_timeframes_returns_empty_lists_if_no_incident(self):
        incidents = fetch_incidents_at_address("123 MAIN ST")
        actual_top_reasons = get_top_incident_reasons_by_timeframes(incidents, [7, 30, 90, 365])

        expected_top_reasons = {
           'fire': {
               7: [],
               30: [],
               90: [],
               365: []
           },
           'police': {
               7: [],
               30: [],
               90: [],
               365: []
           }
        }

        self.assertEquals(expected_top_reasons, actual_top_reasons)
Beispiel #14
0
    def test_count_incidents_returns_proper_counts_for_default_days(self):
        [FireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(5))
         for i in range(0, 5)]
        [FireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(20))
         for i in range(0, 8)]
        [FireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(40))
         for i in range(0, 7)]
        [FireIncidentFactory(standardized_address="123 MAIN ST",
                             alarm_datetime=get_date_days_ago(200))
         for i in range(0, 10)]

        [PoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(5))
         for i in range(0, 3)]
        [PoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(20))
         for i in range(0, 8)]
        [PoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(40))
         for i in range(0, 9)]
        [PoliceIncidentFactory(standardized_address="123 MAIN ST",
                               call_datetime=get_date_days_ago(200))
         for i in range(0, 6)]

        db.session.flush()

        incidents = fetch_incidents_at_address("123 main st")
        counts = count_incidents_by_timeframes(incidents, [7, 30, 90, 365])

        assert counts['fire'][7] == 5
        assert counts['fire'][30] == 13
        assert counts['fire'][90] == 20
        assert counts['fire'][365] == 30

        assert counts['police'][7] == 3
        assert counts['police'][30] == 11
        assert counts['police'][90] == 20
        assert counts['police'][365] == 26