def test_mayoral_rollup(self): today = datetime(2020, 4, 12) rollup = aggregations.asset_rollup_legacy( today - timedelta(days=27), today, rollup_fn=lambda row: row.to_mayoral_category(), ) self.assertEqual(len(rollup), len(dc.MayoralCategory)) self.assertEqual( rollup[dc.MayoralCategory.iso_gowns].asset, dc.MayoralCategory.iso_gowns )
def test_only_aggregate_active_items(self): today = datetime(2020, 4, 12) self.data_import.status = ImportStatus.replaced self.data_import.save() try: self.assertEqual(aggregations.known_recent_demand(), {}) rollup = aggregations.asset_rollup_legacy(today - timedelta(days=28), today) self.assertEqual( rollup[dc.Item.gown], AssetRollup( asset=dc.Item.gown, total_cols=AggColumn.all(), demand=0, ordered=0 ), ) finally: self.data_import.status = ImportStatus.active self.data_import.save()
def test_rollup(self): today = datetime(2020, 4, 12) rollup = aggregations.asset_rollup_legacy(today - timedelta(days=27), today) self.assertEqual(len(rollup), len(dc.Item)) # demand of 20 = 5 in the last week * 4 weeks in the period self.assertEqual( rollup[dc.Item.gown], AssetRollup( asset=dc.Item.gown, total_cols=AggColumn.all(), inventory=100, demand_src={DemandSrc.real_demand}, demand=7654622, ordered=5, ), ) # Turn off use of hospitalization projection rollup = aggregations.asset_rollup_legacy( today - timedelta(days=27), today, use_hospitalization_projection=False, ) self.assertEqual( rollup[dc.Item.gown], AssetRollup( asset=dc.Item.gown, total_cols=AggColumn.all(), inventory=100, demand_src={DemandSrc.real_demand}, demand=2457000 * 4, ordered=5, ), ) # should fallback to past deliveries self.assertEqual( rollup[dc.Item.faceshield], AssetRollup( asset=dc.Item.faceshield, total_cols=AggColumn.all(), inventory=0, demand_src={DemandSrc.past_deliveries}, demand=123 * 4, ordered=0, ), ) # Turn of use off hospitalization projection & real demand future_rollup = aggregations.asset_rollup_legacy( today, today + timedelta(days=27), use_hospitalization_projection=False, use_real_demand=False, ) # Fallback to delivery self.assertEqual( future_rollup[dc.Item.gown], AssetRollup( asset=dc.Item.gown, total_cols=AggColumn.all(), demand=1234 * 4, ordered=1000, demand_src={DemandSrc.past_deliveries}, inventory=100, ), )