Exemplo n.º 1
0
    def test_evaluates_no_activity(self):
        # Should return 0 activities
        overview = OfficerActivityOverview(q('time__gte=2015-01-01'))
        over_time_results = overview.to_dict()['allocation_over_time']
        by_beat_results = overview.to_dict()['on_duty_by_beat']
        by_district_results = overview.to_dict()['on_duty_by_district']

        self.assertEqual(list(over_time_results), [])
        self.assertEqual(list(by_beat_results), [])
        self.assertEqual(list(by_district_results), [])
Exemplo n.º 2
0
    def test_matches_expected_structure(self):
        """
        Make sure the results' structure matches our expectations.

        The results should be a dict with string representations of
        times as keys; each value should be another dict with
        activity names as keys.  Each of these nested dicts should
        have another dict as their value; these dicts should
        have metric names as keys and metric values (integers)
        as values.
        """

        overview = OfficerActivityOverview(q(''))
        results = overview.to_dict()['allocation_over_time']

        self.assertEqual(type(results), dict)

        # Keys should be strings, not datetimes,
        # so we can transmit them to the client
        self.assertEqual(type(list(results.keys())[0]), str)

        outer_value = list(results.values())[0]
        self.assertEqual(type(outer_value), dict)

        self.assertEqual(type(list(outer_value.keys())[0]), str)

        inner_value = list(outer_value.values())[0]
        self.assertEqual(type(inner_value), dict)

        self.assertEqual(type(list(inner_value.keys())[0]), str)
        self.assertEqual(type(list(inner_value.values())[0]), int)
Exemplo n.º 3
0
    def test_allocation_over_time_distinguishes_activities(self):
        "Make sure we've covered all the types of activities."
        overview = OfficerActivityOverview(q(''))
        over_time_results = overview.to_dict()['allocation_over_time']

        self.assertEqual(
            sorted(set([k for time in over_time_results for k in over_time_results[time].keys()])),
            ['IN CALL - CITIZEN INITIATED', 'IN CALL - DIRECTED PATROL',
             'IN CALL - SELF INITIATED', 'ON DUTY', 'OUT OF SERVICE', 'PATROL'
             ])
Exemplo n.º 4
0
    def test_evaluates_one_activity(self):
        # Should return 1 busy activity (a6), 1 on_duty activity (a12)
        overview = OfficerActivityOverview(q('time__gte=2014-01-17'))
        over_time_results = overview.to_dict()['allocation_over_time']

        correct_over_time_results = {
            str(dtparse('9:00').time()):
                {
                    'IN CALL - CITIZEN INITIATED': {
                        'avg_volume': 0,
                        'total': 0,
                        'freq': 1
                    },
                    'IN CALL - SELF INITIATED': {
                        'avg_volume': 0,
                        'total': 0,
                        'freq': 1
                    },
                    'IN CALL - DIRECTED PATROL': {
                        'avg_volume': 0,
                        'total': 0,
                        'freq': 1
                    },
                    'OUT OF SERVICE': {
                        'avg_volume': 1.0,
                        'total': 1,
                        'freq': 1
                    },
                    'ON DUTY': {
                        'avg_volume': 1.0,
                        'total': 1,
                        'freq': 1
                    },
                    'PATROL': {
                        'avg_volume': 0.0,
                        'total': 0,
                        'freq': 1
                    }
                }
        }

        self.assertEqual(sorted(over_time_results.keys()),
                         sorted(correct_over_time_results.keys()))

        self.assertEqual(sorted(over_time_results.values()),
                         sorted(correct_over_time_results.values()))

        by_beat_results = overview.to_dict()['on_duty_by_beat']

        correct_by_beat_results = [
            {'beat_id': 2, 'beat': 'B2', 'on_duty': 1.0},
        ]

        by_district_results = overview.to_dict()['on_duty_by_district']

        correct_by_district_results = [
            {'district_id': 2, 'district': 'D2', 'on_duty': 1.0},
        ]

        for results, correct in (
                (by_beat_results, correct_by_beat_results),
                (by_district_results, correct_by_district_results)):
            for d in correct:
                self.assertIn(d, results)
            for d in results:
                self.assertIn(d, correct)