Add ORM models for the simulation data

- add new ORM models `ReplaySimulation` and `ReplayedOrder`
  to store the data generated by the routing simulations
- add migrations script to create the corresponding database tables
  + create "replay_simulations" and "replayed_orders" tables
  + add missing check constraints to "orders" table
  + add unique constraint to "orders" table to enable compound key
  + drop unnecessary check constraints from the "orders" table
- add tests for the new ORM models
  + add `simulation`, `replayed_order`, `make_replay_order()`, and
    `pre_order` fixtures
  + add `ReplayedOrderFactor` faker class
- fix some typos
This commit is contained in:
Alexander Hess 2021-09-16 11:58:55 +02:00
commit e4e543bd40
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
19 changed files with 1677 additions and 10 deletions

View file

@ -54,10 +54,22 @@ def restaurant(address, make_restaurant):
@pytest.fixture
def order(make_order, restaurant):
"""An `Order` object for the `restaurant`."""
"""An ad-hoc `Order` object for the `restaurant`."""
return make_order(restaurant=restaurant)
@pytest.fixture
def pre_order(make_order, restaurant):
"""A scheduled `Order` object for the `restaurant`."""
return make_order(restaurant=restaurant, scheduled=True)
@pytest.fixture
def replayed_order(make_replay_order, order):
"""A `ReplayedOrder` object for the `restaurant`."""
return make_replay_order(order=order)
@pytest.fixture
def grid(city):
"""A `Grid` with a pixel area of 1 square kilometer."""
@ -68,3 +80,20 @@ def grid(city):
def pixel(grid):
"""The `Pixel` in the lower-left corner of the `grid`."""
return db.Pixel(id=1, grid=grid, n_x=0, n_y=0)
@pytest.fixture
def simulation_data(city):
"""The data for the one and only `ReplaySimulation` object as a `dict`."""
return {
'id': 1,
'city': city,
'strategy': 'best_possible_routing',
'run': 0,
}
@pytest.fixture
def simulation(simulation_data):
"""The one and only `ReplaySimulation` object."""
return db.ReplaySimulation(**simulation_data)