def test_several_inspections_several_parcels_same_tract(self): crimes = [("16Sep2014", "tract567", 3), ("18Oct2014", "tract567", 1)] parcels = [("parcelA", "01Dec2014", "tract567"), ("parcelB", "18Nov2014", "tract567"),] population = [("tract567", 1234)] window = datetime.timedelta(days=365) expected = [("parcelA", timestamp("01Dec2014"), 4 / float(1234)), ("parcelB", timestamp("18Nov2014"), 4 / float(1234))] actual =crime.crimerate_in_aggregation_area(self.make_parcels_df(parcels), self.make_crimerate_df(crimes), self.make_population_df(population), window) actual = actual.reset_index()[["parcel_id", "inspection_date", "crime_rate"]].values self.assert_array_almost_equal(expected, actual)
def test_several_inspections_same_parcel_one_crime_in_range(self): crimes = [("16Sep2014", "tract567", 3), ("18Dec2014", "tract567", 1)] parcels = [("parcelA", "01Dec2014", "tract567"), ("parcelA", "18Nov2014", "tract567")] population = [("tract567", 1234)] window = datetime.timedelta(days=365) expected = [("parcelA", timestamp("01Dec2014"), 3 / float(1234)), ("parcelA", timestamp("18Nov2014"), 3 / float(1234))] actual = crime.crimerate_in_aggregation_area( self.make_parcels_df(parcels), self.make_crimerate_df(crimes), self.make_population_df(population), window) actual = actual.reset_index()[[ "parcel_id", "inspection_date", "crime_rate" ]].values self.assert_array_almost_equal(expected, actual)
def test_six_month_window(self): crimes = [("16Sep2014", "tract567", 3), ("18Sep2014", "tract568", 1), ("14Mar2014", "tract568", 6)] parcels = [("parcelA", "01Dec2014", "tract567"), ("parcelB", "18Apr2014", "tract568"),] population = [("tract567", 1234), ("tract568", 234)] window = datetime.timedelta(days=180) expected = [("parcelA", timestamp("01Dec2014"), 3 / float(1234)), ("parcelB", timestamp("18Apr2014"), 6 / float(234))] actual =crime.crimerate_in_aggregation_area(self.make_parcels_df(parcels), self.make_crimerate_df(crimes), self.make_population_df(population), window) actual = actual.reset_index()[["parcel_id", "inspection_date", "crime_rate"]].values self.assert_array_almost_equal(expected, actual) assert_array_equal(expected, actual)
def test_six_month_window(self): crimes = [("16Sep2014", "tract567", 3), ("18Sep2014", "tract568", 1), ("14Mar2014", "tract568", 6)] parcels = [ ("parcelA", "01Dec2014", "tract567"), ("parcelB", "18Apr2014", "tract568"), ] population = [("tract567", 1234), ("tract568", 234)] window = datetime.timedelta(days=180) expected = [("parcelA", timestamp("01Dec2014"), 3 / float(1234)), ("parcelB", timestamp("18Apr2014"), 6 / float(234))] actual = crime.crimerate_in_aggregation_area( self.make_parcels_df(parcels), self.make_crimerate_df(crimes), self.make_population_df(population), window) actual = actual.reset_index()[[ "parcel_id", "inspection_date", "crime_rate" ]].values self.assert_array_almost_equal(expected, actual) assert_array_equal(expected, actual)
def test_one_inspection_empty_crimes(self): crimes = [] parcels = [("parcelA", "01Dec2014", "tract567")] population = [("tract567", 1234)] window = datetime.timedelta(days=365) expected = [("parcelA", timestamp("01Dec2014"), 0.0)] actual =crime.crimerate_in_aggregation_area(self.make_parcels_df(parcels), self.make_crimerate_df(crimes), self.make_population_df(population), window) actual = actual.reset_index()[["parcel_id", "inspection_date", "crime_rate"]].values self.assert_array_almost_equal(expected, actual)
def test_one_inspection_empty_crimes(self): crimes = [] parcels = [("parcelA", "01Dec2014", "tract567")] population = [("tract567", 1234)] window = datetime.timedelta(days=365) expected = [("parcelA", timestamp("01Dec2014"), 0.0)] actual = crime.crimerate_in_aggregation_area( self.make_parcels_df(parcels), self.make_crimerate_df(crimes), self.make_population_df(population), window) actual = actual.reset_index()[[ "parcel_id", "inspection_date", "crime_rate" ]].values self.assert_array_almost_equal(expected, actual)