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())
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 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_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 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)
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 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)
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_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)
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)
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)
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)
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)
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_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)
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)
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)
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())
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())
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())
def stops(self, request, pk=None): results = GroupedData(by='year', defaults=GROUP_DEFAULTS) self.query(results, group_by=('year', 'ethnicity')) return Response(results.flatten())
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())
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())