Annotate the ORM columns with orm.Mapped
Since SQLAlchemy 2.0, `orm.mapped_column()` with an annotation lets `mypy` see `pixel.id` as an `int` instead of a `Column[int]`.
This commit is contained in:
parent
a8b4bca79d
commit
c339719936
13 changed files with 588 additions and 135 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import datetime as dt
|
||||||
import functools
|
import functools
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
@ -22,17 +23,56 @@ class Address(meta.Base):
|
||||||
__tablename__ = "addresses"
|
__tablename__ = "addresses"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
primary_id = sa.Column(sa.Integer, nullable=False, index=True)
|
sa.Integer,
|
||||||
created_at = sa.Column(sa.DateTime, nullable=False)
|
primary_key=True,
|
||||||
place_id = sa.Column(sa.Unicode(length=120), nullable=False, index=True)
|
autoincrement=False,
|
||||||
latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
)
|
||||||
longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
primary_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
city_id = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
sa.Integer,
|
||||||
city_name = sa.Column("city", sa.Unicode(length=25), nullable=False)
|
nullable=False,
|
||||||
zip_code = sa.Column(sa.Integer, nullable=False, index=True)
|
index=True,
|
||||||
street = sa.Column(sa.Unicode(length=80), nullable=False)
|
)
|
||||||
floor = sa.Column(sa.SmallInteger)
|
created_at: orm.Mapped[dt.datetime] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
place_id: orm.Mapped[str] = orm.mapped_column(
|
||||||
|
sa.Unicode(length=120),
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
latitude: orm.Mapped[float] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
longitude: orm.Mapped[float] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
city_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
city_name: orm.Mapped[str] = orm.mapped_column(
|
||||||
|
"city",
|
||||||
|
sa.Unicode(length=25),
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
zip_code: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
street: orm.Mapped[str] = orm.mapped_column(
|
||||||
|
sa.Unicode(length=80),
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
floor: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -39,16 +39,38 @@ class Path(meta.Base):
|
||||||
__tablename__ = "addresses_addresses"
|
__tablename__ = "addresses_addresses"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
first_address_id = sa.Column(sa.Integer, primary_key=True)
|
first_address_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
second_address_id = sa.Column(sa.Integer, primary_key=True)
|
sa.Integer,
|
||||||
city_id = sa.Column(sa.SmallInteger, nullable=False)
|
primary_key=True,
|
||||||
|
)
|
||||||
|
second_address_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
primary_key=True,
|
||||||
|
)
|
||||||
|
city_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
# Distances are measured in meters.
|
# Distances are measured in meters.
|
||||||
air_distance = sa.Column(sa.Integer, nullable=False)
|
air_distance: orm.Mapped[int] = orm.mapped_column(
|
||||||
bicycle_distance = sa.Column(sa.Integer, nullable=True)
|
sa.Integer,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
bicycle_distance: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
# The duration is measured in seconds.
|
# The duration is measured in seconds.
|
||||||
bicycle_duration = sa.Column(sa.Integer, nullable=True)
|
bicycle_duration: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
# An array of latitude-longitude pairs approximating a courier's way.
|
# An array of latitude-longitude pairs approximating a courier's way.
|
||||||
_directions = sa.Column("directions", postgresql.JSON, nullable=True)
|
_directions: orm.Mapped[str | None] = orm.mapped_column(
|
||||||
|
"directions",
|
||||||
|
postgresql.JSON,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,22 @@ class AddressPixelAssociation(meta.Base):
|
||||||
__tablename__ = "addresses_pixels"
|
__tablename__ = "addresses_pixels"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
address_id = sa.Column(sa.Integer, primary_key=True)
|
address_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
city_id = sa.Column(sa.SmallInteger, nullable=False)
|
sa.Integer,
|
||||||
grid_id = sa.Column(sa.SmallInteger, nullable=False)
|
primary_key=True,
|
||||||
pixel_id = sa.Column(sa.Integer, primary_key=True)
|
)
|
||||||
|
city_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
grid_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
pixel_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
primary_key=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -21,22 +21,49 @@ class City(meta.Base):
|
||||||
__tablename__ = "cities"
|
__tablename__ = "cities"
|
||||||
|
|
||||||
# Generic columns
|
# Generic columns
|
||||||
id = sa.Column(
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
sa.SmallInteger,
|
sa.SmallInteger,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
autoincrement=False,
|
autoincrement=False,
|
||||||
)
|
)
|
||||||
name = sa.Column(sa.Unicode(length=10), nullable=False)
|
name: orm.Mapped[str] = orm.mapped_column(
|
||||||
kml = sa.Column(sa.UnicodeText, nullable=False)
|
sa.Unicode(length=10),
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
kml: orm.Mapped[str] = orm.mapped_column(
|
||||||
|
sa.UnicodeText,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Google Maps related columns
|
# Google Maps related columns
|
||||||
center_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
center_latitude: orm.Mapped[float] = orm.mapped_column(
|
||||||
center_longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
postgresql.DOUBLE_PRECISION,
|
||||||
northeast_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
nullable=False,
|
||||||
northeast_longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
)
|
||||||
southwest_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
center_longitude: orm.Mapped[float] = orm.mapped_column(
|
||||||
southwest_longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
postgresql.DOUBLE_PRECISION,
|
||||||
initial_zoom = sa.Column(sa.SmallInteger, nullable=False)
|
nullable=False,
|
||||||
|
)
|
||||||
|
northeast_latitude: orm.Mapped[float] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
northeast_longitude: orm.Mapped[float] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
southwest_latitude: orm.Mapped[float] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
southwest_longitude: orm.Mapped[float] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
initial_zoom: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
addresses = orm.relationship("Address", back_populates="city")
|
addresses = orm.relationship("Address", back_populates="city")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
"""Provide the ORM's `Courier` model."""
|
"""Provide the ORM's `Courier` model."""
|
||||||
|
|
||||||
|
import datetime as dt
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
from sqlalchemy.dialects import postgresql
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
@ -13,13 +15,36 @@ class Courier(meta.Base):
|
||||||
__tablename__ = "couriers"
|
__tablename__ = "couriers"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
created_at = sa.Column(sa.DateTime, nullable=False)
|
sa.Integer,
|
||||||
vehicle = sa.Column(sa.Unicode(length=10), nullable=False)
|
primary_key=True,
|
||||||
historic_speed = sa.Column("speed", postgresql.DOUBLE_PRECISION, nullable=False)
|
autoincrement=False,
|
||||||
capacity = sa.Column(sa.SmallInteger, nullable=False)
|
)
|
||||||
pay_per_hour = sa.Column(sa.SmallInteger, nullable=False)
|
created_at: orm.Mapped[dt.datetime] = orm.mapped_column(
|
||||||
pay_per_order = sa.Column(sa.SmallInteger, nullable=False)
|
sa.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
vehicle: orm.Mapped[str] = orm.mapped_column(
|
||||||
|
sa.Unicode(length=10),
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
historic_speed: orm.Mapped[float] = orm.mapped_column(
|
||||||
|
"speed",
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
capacity: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
pay_per_hour: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
pay_per_order: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,11 @@ class Customer(meta.Base):
|
||||||
__tablename__ = "customers"
|
__tablename__ = "customers"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=False,
|
||||||
|
)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
"""Non-literal text representation."""
|
"""Non-literal text representation."""
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import datetime as dt
|
||||||
import math
|
import math
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
@ -23,25 +24,63 @@ class Forecast(meta.Base):
|
||||||
__tablename__ = "forecasts"
|
__tablename__ = "forecasts"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
pixel_id = sa.Column(sa.Integer, nullable=False, index=True)
|
sa.Integer,
|
||||||
start_at = sa.Column(sa.DateTime, nullable=False)
|
primary_key=True,
|
||||||
time_step = sa.Column(sa.SmallInteger, nullable=False)
|
autoincrement=True,
|
||||||
train_horizon = sa.Column(sa.SmallInteger, nullable=False)
|
)
|
||||||
model = sa.Column(sa.Unicode(length=20), nullable=False)
|
pixel_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
start_at: orm.Mapped[dt.datetime] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
time_step: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
train_horizon: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
model: orm.Mapped[str] = orm.mapped_column(
|
||||||
|
sa.Unicode(length=20),
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
# We also store the actual order counts for convenient retrieval.
|
# We also store the actual order counts for convenient retrieval.
|
||||||
# A `UniqueConstraint` below ensures that redundant values that
|
# A `UniqueConstraint` below ensures that redundant values that
|
||||||
# are to be expected are consistent across rows.
|
# are to be expected are consistent across rows.
|
||||||
actual = sa.Column(sa.SmallInteger, nullable=False)
|
actual: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
# Raw `.prediction`s are stored as `float`s (possibly negative).
|
# Raw `.prediction`s are stored as `float`s (possibly negative).
|
||||||
# The rounding is then done on the fly if required.
|
# The rounding is then done on the fly if required.
|
||||||
prediction = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
prediction: orm.Mapped[float] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
# The confidence intervals are treated like the `.prediction`s
|
# The confidence intervals are treated like the `.prediction`s
|
||||||
# but they may be nullable as some methods do not calculate them.
|
# but they may be nullable as some methods do not calculate them.
|
||||||
low80 = sa.Column(postgresql.DOUBLE_PRECISION, nullable=True)
|
low80: orm.Mapped[float | None] = orm.mapped_column(
|
||||||
high80 = sa.Column(postgresql.DOUBLE_PRECISION, nullable=True)
|
postgresql.DOUBLE_PRECISION,
|
||||||
low95 = sa.Column(postgresql.DOUBLE_PRECISION, nullable=True)
|
nullable=True,
|
||||||
high95 = sa.Column(postgresql.DOUBLE_PRECISION, nullable=True)
|
)
|
||||||
|
high80: orm.Mapped[float | None] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
low95: orm.Mapped[float | None] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
high95: orm.Mapped[float | None] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,20 @@ class Grid(meta.Base):
|
||||||
__tablename__ = "grids"
|
__tablename__ = "grids"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
sa.SmallInteger,
|
sa.SmallInteger,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
autoincrement=True,
|
autoincrement=True,
|
||||||
)
|
)
|
||||||
city_id = sa.Column(sa.SmallInteger, nullable=False)
|
city_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
side_length = sa.Column(sa.SmallInteger, nullable=False, unique=True)
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
side_length: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
unique=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
"""Provide the ORM's `Order` model."""
|
"""Provide the ORM's `Order` model."""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import datetime as dt
|
||||||
|
|
||||||
import folium
|
import folium
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
@ -18,64 +19,228 @@ class Order(meta.Base):
|
||||||
__tablename__ = "orders"
|
__tablename__ = "orders"
|
||||||
|
|
||||||
# Generic columns
|
# Generic columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
_delivery_id = sa.Column("delivery_id", sa.Integer, index=True, unique=True)
|
sa.Integer,
|
||||||
customer_id = sa.Column(sa.Integer, nullable=False, index=True)
|
primary_key=True,
|
||||||
placed_at = sa.Column(sa.DateTime, nullable=False, index=True)
|
autoincrement=False,
|
||||||
ad_hoc = sa.Column(sa.Boolean, nullable=False)
|
)
|
||||||
scheduled_delivery_at = sa.Column(sa.DateTime, index=True)
|
_delivery_id: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
scheduled_delivery_at_corrected = sa.Column(sa.Boolean, index=True)
|
"delivery_id",
|
||||||
first_estimated_delivery_at = sa.Column(sa.DateTime)
|
sa.Integer,
|
||||||
cancelled = sa.Column(sa.Boolean, nullable=False, index=True)
|
nullable=True,
|
||||||
cancelled_at = sa.Column(sa.DateTime)
|
index=True,
|
||||||
cancelled_at_corrected = sa.Column(sa.Boolean, index=True)
|
unique=True,
|
||||||
|
)
|
||||||
|
customer_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
placed_at: orm.Mapped[dt.datetime] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
ad_hoc: orm.Mapped[bool] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
scheduled_delivery_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
scheduled_delivery_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
first_estimated_delivery_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
cancelled: orm.Mapped[bool] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
cancelled_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
cancelled_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Price-related columns
|
# Price-related columns
|
||||||
sub_total = sa.Column(sa.Integer, nullable=False)
|
sub_total: orm.Mapped[int] = orm.mapped_column(
|
||||||
delivery_fee = sa.Column(sa.SmallInteger, nullable=False)
|
sa.Integer,
|
||||||
total = sa.Column(sa.Integer, nullable=False)
|
nullable=False,
|
||||||
|
)
|
||||||
|
delivery_fee: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
total: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Restaurant-related columns
|
# Restaurant-related columns
|
||||||
restaurant_id = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
restaurant_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
restaurant_notified_at = sa.Column(sa.DateTime)
|
sa.SmallInteger,
|
||||||
restaurant_notified_at_corrected = sa.Column(sa.Boolean, index=True)
|
nullable=False,
|
||||||
restaurant_confirmed_at = sa.Column(sa.DateTime)
|
index=True,
|
||||||
restaurant_confirmed_at_corrected = sa.Column(sa.Boolean, index=True)
|
)
|
||||||
estimated_prep_duration = sa.Column(sa.Integer, index=True)
|
restaurant_notified_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
estimated_prep_duration_corrected = sa.Column(sa.Boolean, index=True)
|
sa.DateTime,
|
||||||
estimated_prep_buffer = sa.Column(sa.Integer, nullable=False, index=True)
|
nullable=True,
|
||||||
|
)
|
||||||
|
restaurant_notified_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
restaurant_confirmed_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
restaurant_confirmed_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
estimated_prep_duration: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
estimated_prep_duration_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
estimated_prep_buffer: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Dispatch-related columns
|
# Dispatch-related columns
|
||||||
courier_id = sa.Column(sa.Integer, index=True)
|
courier_id: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
dispatch_at = sa.Column(sa.DateTime)
|
sa.Integer,
|
||||||
dispatch_at_corrected = sa.Column(sa.Boolean, index=True)
|
nullable=True,
|
||||||
courier_notified_at = sa.Column(sa.DateTime)
|
index=True,
|
||||||
courier_notified_at_corrected = sa.Column(sa.Boolean, index=True)
|
)
|
||||||
courier_accepted_at = sa.Column(sa.DateTime)
|
dispatch_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
courier_accepted_at_corrected = sa.Column(sa.Boolean, index=True)
|
sa.DateTime,
|
||||||
utilization = sa.Column(sa.SmallInteger, nullable=False)
|
nullable=True,
|
||||||
|
)
|
||||||
|
dispatch_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
courier_notified_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
courier_notified_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
courier_accepted_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
courier_accepted_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
utilization: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Pickup-related columns
|
# Pickup-related columns
|
||||||
pickup_address_id = sa.Column(sa.Integer, nullable=False, index=True)
|
pickup_address_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
reached_pickup_at = sa.Column(sa.DateTime)
|
sa.Integer,
|
||||||
pickup_at = sa.Column(sa.DateTime)
|
nullable=False,
|
||||||
pickup_at_corrected = sa.Column(sa.Boolean, index=True)
|
index=True,
|
||||||
pickup_not_confirmed = sa.Column(sa.Boolean)
|
)
|
||||||
left_pickup_at = sa.Column(sa.DateTime)
|
reached_pickup_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
left_pickup_at_corrected = sa.Column(sa.Boolean, index=True)
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
pickup_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
pickup_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
pickup_not_confirmed: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
left_pickup_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
left_pickup_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Delivery-related columns
|
# Delivery-related columns
|
||||||
delivery_address_id = sa.Column(sa.Integer, nullable=False, index=True)
|
delivery_address_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
reached_delivery_at = sa.Column(sa.DateTime)
|
sa.Integer,
|
||||||
delivery_at = sa.Column(sa.DateTime)
|
nullable=False,
|
||||||
delivery_at_corrected = sa.Column(sa.Boolean, index=True)
|
index=True,
|
||||||
delivery_not_confirmed = sa.Column(sa.Boolean)
|
)
|
||||||
_courier_waited_at_delivery = sa.Column("courier_waited_at_delivery", sa.Boolean)
|
reached_delivery_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
delivery_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
delivery_at_corrected: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
delivery_not_confirmed: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
_courier_waited_at_delivery: orm.Mapped[bool | None] = orm.mapped_column(
|
||||||
|
"courier_waited_at_delivery",
|
||||||
|
sa.Boolean,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Statistical columns
|
# Statistical columns
|
||||||
logged_delivery_distance = sa.Column(sa.SmallInteger, nullable=True)
|
logged_delivery_distance: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
logged_avg_speed = sa.Column(postgresql.DOUBLE_PRECISION, nullable=True)
|
sa.SmallInteger,
|
||||||
logged_avg_speed_distance = sa.Column(sa.SmallInteger, nullable=True)
|
nullable=True,
|
||||||
|
)
|
||||||
|
logged_avg_speed: orm.Mapped[float | None] = orm.mapped_column(
|
||||||
|
postgresql.DOUBLE_PRECISION,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
logged_avg_speed_distance: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,26 @@ class Pixel(meta.Base):
|
||||||
__tablename__ = "pixels"
|
__tablename__ = "pixels"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
grid_id = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
sa.Integer,
|
||||||
n_x = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
primary_key=True,
|
||||||
n_y = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
autoincrement=True,
|
||||||
|
)
|
||||||
|
grid_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
n_x: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
n_y: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import datetime as dt
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
|
|
@ -14,43 +16,107 @@ class ReplayedOrder(meta.Base):
|
||||||
__tablename__ = "replayed_orders"
|
__tablename__ = "replayed_orders"
|
||||||
|
|
||||||
# Generic columns
|
# Generic columns
|
||||||
simulation_id = sa.Column(sa.Integer, primary_key=True)
|
simulation_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
actual_order_id = sa.Column(sa.Integer, primary_key=True)
|
sa.Integer,
|
||||||
|
primary_key=True,
|
||||||
|
)
|
||||||
|
actual_order_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
primary_key=True,
|
||||||
|
)
|
||||||
|
|
||||||
# `Order`-type related columns
|
# `Order`-type related columns
|
||||||
# `.ad_hoc` is part of a `ForeignKeyConstraint` to ensure the type
|
# `.ad_hoc` is part of a `ForeignKeyConstraint` to ensure the type
|
||||||
# of the `ReplayedOrder` (i.e., ad-hoc or scheduled) is in line
|
# of the `ReplayedOrder` (i.e., ad-hoc or scheduled) is in line
|
||||||
# with the `.actual` order.
|
# with the `.actual` order.
|
||||||
ad_hoc = sa.Column(sa.Boolean, nullable=False)
|
ad_hoc: orm.Mapped[bool] = orm.mapped_column(
|
||||||
placed_at = sa.Column(sa.DateTime, nullable=False)
|
sa.Boolean,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
placed_at: orm.Mapped[dt.datetime] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
# Depending on `.ad_hoc`, `.scheduled_delivery_at` is either filled in or not.
|
# Depending on `.ad_hoc`, `.scheduled_delivery_at` is either filled in or not.
|
||||||
scheduled_delivery_at = sa.Column(sa.DateTime)
|
scheduled_delivery_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
# If an order is cancelled in a simulation,
|
# If an order is cancelled in a simulation,
|
||||||
# some of the columns below do not apply any more.
|
# some of the columns below do not apply any more.
|
||||||
cancelled_at = sa.Column(sa.DateTime)
|
cancelled_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Restaurant-related columns
|
# Restaurant-related columns
|
||||||
estimated_prep_duration = sa.Column(sa.SmallInteger)
|
estimated_prep_duration: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
restaurant_notified_at = sa.Column(sa.DateTime)
|
sa.SmallInteger,
|
||||||
restaurant_confirmed_at = sa.Column(sa.DateTime)
|
nullable=True,
|
||||||
restaurant_ready_at = sa.Column(sa.DateTime)
|
)
|
||||||
|
restaurant_notified_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
restaurant_confirmed_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
restaurant_ready_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Dispatch-related columns
|
# Dispatch-related columns
|
||||||
dispatch_at = sa.Column(sa.DateTime)
|
dispatch_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
first_estimated_delivery_at = sa.Column(sa.DateTime)
|
sa.DateTime,
|
||||||
courier_id = sa.Column(sa.Integer, index=True)
|
nullable=True,
|
||||||
courier_notified_at = sa.Column(sa.DateTime)
|
)
|
||||||
courier_accepted_at = sa.Column(sa.DateTime)
|
first_estimated_delivery_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
utilization = sa.Column(sa.SmallInteger)
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
courier_id: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
courier_notified_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
courier_accepted_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
utilization: orm.Mapped[int | None] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Pickup-related columns
|
# Pickup-related columns
|
||||||
reached_pickup_at = sa.Column(sa.DateTime)
|
reached_pickup_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
pickup_at = sa.Column(sa.DateTime)
|
sa.DateTime,
|
||||||
left_pickup_at = sa.Column(sa.DateTime)
|
nullable=True,
|
||||||
|
)
|
||||||
|
pickup_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
left_pickup_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Delivery-related columns
|
# Delivery-related columns
|
||||||
reached_delivery_at = sa.Column(sa.DateTime)
|
reached_delivery_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
delivery_at = sa.Column(sa.DateTime)
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
delivery_at: orm.Mapped[dt.datetime | None] = orm.mapped_column(
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,26 @@ class ReplaySimulation(meta.Base):
|
||||||
__tablename__ = "replay_simulations"
|
__tablename__ = "replay_simulations"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
city_id = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
sa.Integer,
|
||||||
strategy = sa.Column(sa.Unicode(length=100), nullable=False, index=True)
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
)
|
||||||
|
city_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
strategy: orm.Mapped[str] = orm.mapped_column(
|
||||||
|
sa.Unicode(length=100),
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
# `.run` may be used as random seed.
|
# `.run` may be used as random seed.
|
||||||
run = sa.Column(sa.SmallInteger, nullable=False)
|
run: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import datetime as dt
|
||||||
|
|
||||||
import folium
|
import folium
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
@ -22,15 +24,28 @@ class Restaurant(meta.Base):
|
||||||
__tablename__ = "restaurants"
|
__tablename__ = "restaurants"
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(
|
id: orm.Mapped[int] = orm.mapped_column(
|
||||||
sa.SmallInteger,
|
sa.SmallInteger,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
autoincrement=False,
|
autoincrement=False,
|
||||||
)
|
)
|
||||||
created_at = sa.Column(sa.DateTime, nullable=False)
|
created_at: orm.Mapped[dt.datetime] = orm.mapped_column(
|
||||||
name = sa.Column(sa.Unicode(length=45), nullable=False)
|
sa.DateTime,
|
||||||
address_id = sa.Column(sa.Integer, nullable=False, index=True)
|
nullable=False,
|
||||||
estimated_prep_duration = sa.Column(sa.SmallInteger, nullable=False)
|
)
|
||||||
|
name: orm.Mapped[str] = orm.mapped_column(
|
||||||
|
sa.Unicode(length=45),
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
address_id: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.Integer,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
estimated_prep_duration: orm.Mapped[int] = orm.mapped_column(
|
||||||
|
sa.SmallInteger,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue