Пример #1
0
 def stops_by_reason(self, request, pk=None):
     response = {}
     # stops
     results = GroupedData(by=('purpose', 'year'), defaults=GROUP_DEFAULTS)
     self.query(results, group_by=('purpose', 'year', 'person__race', 'person__ethnicity'))
     response['stops'] = results.flatten()
     # searches
     results = GroupedData(by=('purpose', 'year'), defaults=GROUP_DEFAULTS)
     self.query(results, group_by=('purpose', 'year', 'person__race', 'person__ethnicity'),
                filter_=Q(search__isnull=False))
     response['searches'] = results.flatten()
     return Response(response)
Пример #2
0
 def stops_by_reason(self, request, pk=None):
     response = {}
     # stops
     results = GroupedData(by=('purpose', 'year'), defaults=GROUP_DEFAULTS)
     self.query(results, group_by=('purpose', 'year', 'ethnicity'))
     response['stops'] = results.flatten()
     # searches
     results = GroupedData(by=('purpose', 'year'), defaults=GROUP_DEFAULTS)
     self.query(results, group_by=('purpose', 'year', 'ethnicity'),
                filter_=Q(search_conducted='Y'))
     response['searches'] = results.flatten()
     return Response(response)
Пример #3
0
 def contraband_hit_rate(self, request, pk=None):
     response = {}
     # searches
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search_conducted='Y')
     self.query(results, group_by=('year', 'ethnicity'), filter_=q)
     response['searches'] = results.flatten()
     # contraband
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(seized='Y')
     self.query(results, group_by=('year', 'ethnicity'), filter_=q)
     response['contraband'] = results.flatten()
     return Response(response)
Пример #4
0
 def contraband_hit_rate(self, request, pk=None):
     response = {}
     # searches
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search_conducted='Y')
     self.query(results, group_by=('year', 'ethnicity'), filter_=q)
     response['searches'] = results.flatten()
     # contraband
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(seized='Y')
     self.query(results, group_by=('year', 'ethnicity'), filter_=q)
     response['contraband'] = results.flatten()
     return Response(response)
Пример #5
0
 def contraband_hit_rate(self, request, pk=None):
     response = {}
     # searches
     results = GroupedData(by="year", defaults=GROUP_DEFAULTS)
     q = Q(search__isnull=False)
     self.query(results, group_by=("year", "person__race", "person__ethnicity"), filter_=q)
     response["searches"] = results.flatten()
     # searches
     results = GroupedData(by="year", defaults=GROUP_DEFAULTS)
     q = Q(search__contraband__isnull=False)
     self.query(results, group_by=("year", "person__race", "person__ethnicity"), filter_=q)
     response["contraband"] = results.flatten()
     return Response(response)
Пример #6
0
 def contraband_hit_rate(self, request, pk=None):
     response = {}
     # searches
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search__isnull=False)
     self.query(results, group_by=('year', 'person__race', 'person__ethnicity'), filter_=q)
     response['searches'] = results.flatten()
     # searches
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search__contraband__isnull=False)
     self.query(results, group_by=('year', 'person__race', 'person__ethnicity'), filter_=q)
     response['contraband'] = results.flatten()
     return Response(response)
Пример #7
0
 def stops_by_reason(self, request, pk=None):
     response = {}
     # stops
     results = GroupedData(by=("purpose", "year"), defaults=GROUP_DEFAULTS)
     self.query(results, group_by=("purpose", "year", "person__race", "person__ethnicity"))
     response["stops"] = results.flatten()
     # searches
     results = GroupedData(by=("purpose", "year"), defaults=GROUP_DEFAULTS)
     self.query(
         results,
         group_by=("purpose", "year", "person__race", "person__ethnicity"),
         filter_=Q(search__isnull=False),
     )
     response["searches"] = results.flatten()
     return Response(response)
Пример #8
0
 def searches(self, request, pk=None):
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search__isnull=False)
     self.query(results,
                group_by=('year', 'person__race', 'person__ethnicity'),
                filter_=q)
     return Response(results.flatten())
Пример #9
0
 def contraband_hit_rate(self, request, pk=None):
     response = {}
     # searches
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search__isnull=False)
     self.query(results,
                group_by=('year', 'person__race', 'person__ethnicity'),
                filter_=q)
     response['searches'] = results.flatten()
     # searches
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search__contraband__isnull=False)
     self.query(results,
                group_by=('year', 'person__race', 'person__ethnicity'),
                filter_=q)
     response['contraband'] = results.flatten()
     return Response(response)
 def test_default_values(self):
     """Verify group by with two items"""
     stops = GroupedData('year', defaults={'race1': 0, 'race2': 0})
     stops.add(year=2010, race1=10)
     stops.add(year=2011, race2=10)
     expected = [{'year': 2010, 'race1': 10, 'race2': 0},
                 {'year': 2011, 'race1': 0, 'race2': 10}]
     self.assertEqual(stops.flatten(), expected)
Пример #11
0
 def searches_by_type(self, request, pk=None):
     results = GroupedData(by=("search_type", "year"), defaults=GROUP_DEFAULTS)
     q = Q(search__isnull=False)
     self.query(
         results,
         group_by=("search__type", "year", "person__race", "person__ethnicity",),
         filter_=q,
     )
     return Response(results.flatten())
 def test_single_item_group(self):
     """Verify group by with single item"""
     stops = GroupedData(by='year')
     stops.add(year=2010, race1=10)
     stops.add(year=2010, race2=10)
     stops.add(year=2011, race1=5)
     stops.add(year=2011, race2=5)
     expected = [{'year': 2010, 'race1': 10, 'race2': 10},
                 {'year': 2011, 'race1': 5, 'race2': 5}]
     self.assertEqual(stops.flatten(), expected)
Пример #13
0
 def test_default_values(self):
     """Verify group by with two items"""
     stops = GroupedData("year", defaults={"race1": 0, "race2": 0})
     stops.add(year=2010, race1=10)
     stops.add(year=2011, race2=10)
     expected = [
         {"year": 2010, "race1": 10, "race2": 0},
         {"year": 2011, "race1": 0, "race2": 10},
     ]
     self.assertEqual(stops.flatten(), expected)
 def test_pair_item_group(self):
     """Verify group by with two items"""
     stops = GroupedData(by=('purpose', 'year'))
     stops.add(purpose='Checkpoint', year=2010, race1=10)
     stops.add(purpose='Checkpoint', year=2010, race2=10)
     stops.add(purpose='Checkpoint', year=2011, race1=5)
     stops.add(purpose='Checkpoint', year=2011, race2=5)
     expected = [{'purpose': 'Checkpoint', 'year': 2010, 'race1': 10, 'race2': 10},
                 {'purpose': 'Checkpoint', 'year': 2011, 'race1': 5, 'race2': 5}]
     self.assertEqual(stops.flatten(), expected)
Пример #15
0
 def test_single_item_group(self):
     """Verify group by with single item"""
     stops = GroupedData(by="year")
     stops.add(year=2010, race1=10)
     stops.add(year=2010, race2=10)
     stops.add(year=2011, race1=5)
     stops.add(year=2011, race2=5)
     expected = [
         {"year": 2010, "race1": 10, "race2": 10},
         {"year": 2011, "race1": 5, "race2": 5},
     ]
     self.assertEqual(stops.flatten(), expected)
Пример #16
0
 def test_pair_item_group(self):
     """Verify group by with two items"""
     stops = GroupedData(by=("purpose", "year"))
     stops.add(purpose="Checkpoint", year=2010, race1=10)
     stops.add(purpose="Checkpoint", year=2010, race2=10)
     stops.add(purpose="Checkpoint", year=2011, race1=5)
     stops.add(purpose="Checkpoint", year=2011, race2=5)
     expected = [
         {"purpose": "Checkpoint", "year": 2010, "race1": 10, "race2": 10},
         {"purpose": "Checkpoint", "year": 2011, "race1": 5, "race2": 5},
     ]
     self.assertEqual(stops.flatten(), expected)
Пример #17
0
 def searches_by_type(self, request, pk=None):
     results = GroupedData(by=('search_type', 'year'), defaults=GROUP_DEFAULTS)
     q = Q(search__isnull=False)
     self.query(
         results,
         group_by=(
             'search__type',
             'year',
             'person__race',
             'person__ethnicity',
         ),
         filter_=q,
     )
     return Response(results.flatten())
Пример #18
0
 def test_default_values(self):
     """Verify group by with two items"""
     stops = GroupedData('year', defaults={'race1': 0, 'race2': 0})
     stops.add(year=2010, race1=10)
     stops.add(year=2011, race2=10)
     expected = [{
         'year': 2010,
         'race1': 10,
         'race2': 0
     }, {
         'year': 2011,
         'race1': 0,
         'race2': 10
     }]
     self.assertEqual(stops.flatten(), expected)
Пример #19
0
 def test_single_item_group(self):
     """Verify group by with single item"""
     stops = GroupedData(by='year')
     stops.add(year=2010, race1=10)
     stops.add(year=2010, race2=10)
     stops.add(year=2011, race1=5)
     stops.add(year=2011, race2=5)
     expected = [{
         'year': 2010,
         'race1': 10,
         'race2': 10
     }, {
         'year': 2011,
         'race1': 5,
         'race2': 5
     }]
     self.assertEqual(stops.flatten(), expected)
Пример #20
0
 def test_pair_item_group(self):
     """Verify group by with two items"""
     stops = GroupedData(by=('purpose', 'year'))
     stops.add(purpose='Checkpoint', year=2010, race1=10)
     stops.add(purpose='Checkpoint', year=2010, race2=10)
     stops.add(purpose='Checkpoint', year=2011, race1=5)
     stops.add(purpose='Checkpoint', year=2011, race2=5)
     expected = [{
         'purpose': 'Checkpoint',
         'year': 2010,
         'race1': 10,
         'race2': 10
     }, {
         'purpose': 'Checkpoint',
         'year': 2011,
         'race1': 5,
         'race2': 5
     }]
     self.assertEqual(stops.flatten(), expected)
Пример #21
0
 def stops(self, request, pk=None):
     results = GroupedData(by="year", defaults=GROUP_DEFAULTS)
     self.query(results, group_by=("year", "person__race", "person__ethnicity"))
     return Response(results.flatten())
Пример #22
0
 def use_of_force(self, request, pk=None):
     results = GroupedData(by="year", defaults=GROUP_DEFAULTS)
     q = Q(search__isnull=False) & Q(engage_force="t")
     self.query(results, group_by=("year", "person__race", "person__ethnicity"), filter_=q)
     return Response(results.flatten())
Пример #23
0
 def searches(self, request, pk=None):
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search_conducted='Y')
     self.query(results, group_by=('year', 'ethnicity'), filter_=q)
     return Response(results.flatten())
Пример #24
0
 def searches(self, request, pk=None):
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search_conducted='Y')
     self.query(results, group_by=('year', 'ethnicity'), filter_=q)
     return Response(results.flatten())
Пример #25
0
 def stops(self, request, pk=None):
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     self.query(results, group_by=('year', 'ethnicity'))
     return Response(results.flatten())
Пример #26
0
 def stops(self, request, pk=None):
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     self.query(results, group_by=('year', 'person__race', 'person__ethnicity'))
     return Response(results.flatten())
Пример #27
0
 def use_of_force(self, request, pk=None):
     results = GroupedData(by='year', defaults=GROUP_DEFAULTS)
     q = Q(search__isnull=False) & Q(engage_force='t')
     self.query(results, group_by=('year', 'person__race', 'person__ethnicity'), filter_=q)
     return Response(results.flatten())