Add OrderHistory.avg_daily_demand()
- the method calculates the number of daily `Order`s in a `Pixel` withing the `train_horizon` preceding the `predict_day`
This commit is contained in:
parent
67cd58cf16
commit
cb7611d587
4 changed files with 83 additions and 11 deletions
|
|
@ -82,6 +82,17 @@ def good_pixel_id(pixel):
|
|||
return pixel.id # `== 1`
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def predict_at() -> dt.datetime:
|
||||
"""`NOON` on the day to be predicted."""
|
||||
return dt.datetime(
|
||||
test_config.END.year,
|
||||
test_config.END.month,
|
||||
test_config.END.day,
|
||||
test_config.NOON,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def order_totals(good_pixel_id):
|
||||
"""A mock for `OrderHistory.totals`.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
"""Tests for the `urban_meal_delivery.forecasts.models` sub-package."""
|
||||
|
||||
import datetime as dt
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
|
@ -59,16 +58,6 @@ class TestGenericForecastingModelProperties:
|
|||
|
||||
self.unique_model_names.add(model.name)
|
||||
|
||||
@pytest.fixture
|
||||
def predict_at(self) -> dt.datetime:
|
||||
"""`NOON` on the day to be predicted."""
|
||||
return dt.datetime(
|
||||
test_config.END.year,
|
||||
test_config.END.month,
|
||||
test_config.END.day,
|
||||
test_config.NOON,
|
||||
)
|
||||
|
||||
@pytest.mark.r
|
||||
def test_make_prediction_structure(
|
||||
self, model_cls, order_history, pixel, predict_at,
|
||||
|
|
|
|||
37
tests/forecasts/timify/test_avg_daily_demand.py
Normal file
37
tests/forecasts/timify/test_avg_daily_demand.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"""Tests for the `OrderHistory.avg_daily_demand()` method."""
|
||||
|
||||
from tests import config as test_config
|
||||
|
||||
|
||||
def test_avg_daily_demand_with_constant_demand(
|
||||
order_history, good_pixel_id, predict_at,
|
||||
):
|
||||
"""The average daily demand must be the number of time steps ...
|
||||
|
||||
... if the demand is `1` at each time step.
|
||||
|
||||
Note: The `order_history` fixture assumes `12` time steps per day as it
|
||||
uses `LONG_TIME_STEP=60` as the length of a time step.
|
||||
"""
|
||||
result = order_history.avg_daily_demand(
|
||||
pixel_id=good_pixel_id,
|
||||
predict_day=predict_at.date(),
|
||||
train_horizon=test_config.LONG_TRAIN_HORIZON,
|
||||
)
|
||||
|
||||
assert result == 12.0
|
||||
|
||||
|
||||
def test_avg_daily_demand_with_no_demand(
|
||||
order_history, good_pixel_id, predict_at,
|
||||
):
|
||||
"""Without demand, the average daily demand must be `0.0`."""
|
||||
order_history._data.loc[:, 'n_orders'] = 0
|
||||
|
||||
result = order_history.avg_daily_demand(
|
||||
pixel_id=good_pixel_id,
|
||||
predict_day=predict_at.date(),
|
||||
train_horizon=test_config.LONG_TRAIN_HORIZON,
|
||||
)
|
||||
|
||||
assert result == 0.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue