Use double quotes
This commit is contained in:
parent
7b32ffc599
commit
ea8f1a13e3
83 changed files with 2464 additions and 2466 deletions
|
|
@ -5,11 +5,11 @@ import velofy
|
|||
|
||||
project = velofy.__pkg_name__
|
||||
author = velofy.__author__
|
||||
copyright = f'2020, {author}'
|
||||
copyright = f"2020, {author}"
|
||||
version = release = velofy.__version__
|
||||
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.napoleon',
|
||||
'sphinx_autodoc_typehints',
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx.ext.napoleon",
|
||||
"sphinx_autodoc_typehints",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from velofy import db
|
|||
|
||||
# Disable the --sql option, a.k.a, the "offline mode".
|
||||
if context.is_offline_mode():
|
||||
raise NotImplementedError('The --sql option is not implemented in this project')
|
||||
raise NotImplementedError("The --sql option is not implemented in this project")
|
||||
|
||||
|
||||
# Set up the default Python logger from the alembic.ini file.
|
||||
|
|
@ -22,8 +22,8 @@ log_config.fileConfig(context.config.config_file_name)
|
|||
def include_object(obj, _name, type_, _reflected, _compare_to):
|
||||
"""Only include the clean schema into --autogenerate migrations."""
|
||||
if (
|
||||
type_ in {'table', 'column'}
|
||||
and hasattr(obj, 'schema') # => fix for rare edge case
|
||||
type_ in {"table", "column"}
|
||||
and hasattr(obj, "schema") # => fix for rare edge case
|
||||
and obj.schema != velofy_config.CLEAN_SCHEMA
|
||||
):
|
||||
return False
|
||||
|
|
@ -38,10 +38,10 @@ with engine.connect() as connection:
|
|||
connection=connection,
|
||||
include_object=include_object,
|
||||
target_metadata=db.Base.metadata,
|
||||
version_table='{alembic_table}{test_schema}'.format(
|
||||
version_table="{alembic_table}{test_schema}".format(
|
||||
alembic_table=velofy_config.ALEMBIC_TABLE,
|
||||
test_schema=(
|
||||
f'_{velofy_config.CLEAN_SCHEMA}' if os.getenv('TESTING') else ''
|
||||
f"_{velofy_config.CLEAN_SCHEMA}" if os.getenv("TESTING") else ""
|
||||
),
|
||||
),
|
||||
version_table_schema=velofy_config.ALEMBIC_TABLE_SCHEMA,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -12,141 +12,141 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = '888e352d7526'
|
||||
down_revision = 'f11cd76d2f45'
|
||||
revision = "888e352d7526"
|
||||
down_revision = "f11cd76d2f45"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision 888e352d7526."""
|
||||
op.create_table(
|
||||
'grids',
|
||||
sa.Column('id', sa.SmallInteger(), autoincrement=True, nullable=False),
|
||||
sa.Column('city_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('side_length', sa.SmallInteger(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_grids')),
|
||||
"grids",
|
||||
sa.Column("id", sa.SmallInteger(), autoincrement=True, nullable=False),
|
||||
sa.Column("city_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("side_length", sa.SmallInteger(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_grids")),
|
||||
sa.ForeignKeyConstraint(
|
||||
['city_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.cities.id'],
|
||||
name=op.f('fk_grids_to_cities_via_city_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["city_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.cities.id"],
|
||||
name=op.f("fk_grids_to_cities_via_city_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'city_id',
|
||||
'side_length',
|
||||
name=op.f('uq_grids_on_city_id_side_length'),
|
||||
"city_id",
|
||||
"side_length",
|
||||
name=op.f("uq_grids_on_city_id_side_length"),
|
||||
),
|
||||
# This `UniqueConstraint` is needed by the `addresses_pixels` table below.
|
||||
sa.UniqueConstraint('id', 'city_id', name=op.f('uq_grids_on_id_city_id')),
|
||||
sa.UniqueConstraint("id", "city_id", name=op.f("uq_grids_on_id_city_id")),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'pixels',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('grid_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('n_x', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('n_y', sa.SmallInteger(), nullable=False),
|
||||
sa.CheckConstraint('0 <= n_x', name=op.f('ck_pixels_on_n_x_is_positive')),
|
||||
sa.CheckConstraint('0 <= n_y', name=op.f('ck_pixels_on_n_y_is_positive')),
|
||||
"pixels",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("grid_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("n_x", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("n_y", sa.SmallInteger(), nullable=False),
|
||||
sa.CheckConstraint("0 <= n_x", name=op.f("ck_pixels_on_n_x_is_positive")),
|
||||
sa.CheckConstraint("0 <= n_y", name=op.f("ck_pixels_on_n_y_is_positive")),
|
||||
sa.ForeignKeyConstraint(
|
||||
['grid_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.grids.id'],
|
||||
name=op.f('fk_pixels_to_grids_via_grid_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["grid_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.grids.id"],
|
||||
name=op.f("fk_pixels_to_grids_via_grid_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_pixels')),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_pixels")),
|
||||
sa.UniqueConstraint(
|
||||
'grid_id',
|
||||
'n_x',
|
||||
'n_y',
|
||||
name=op.f('uq_pixels_on_grid_id_n_x_n_y'),
|
||||
"grid_id",
|
||||
"n_x",
|
||||
"n_y",
|
||||
name=op.f("uq_pixels_on_grid_id_n_x_n_y"),
|
||||
),
|
||||
sa.UniqueConstraint('id', 'grid_id', name=op.f('uq_pixels_on_id_grid_id')),
|
||||
sa.UniqueConstraint("id", "grid_id", name=op.f("uq_pixels_on_id_grid_id")),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
op.f('ix_pixels_on_grid_id'),
|
||||
'pixels',
|
||||
['grid_id'],
|
||||
op.f("ix_pixels_on_grid_id"),
|
||||
"pixels",
|
||||
["grid_id"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_pixels_on_n_x'),
|
||||
'pixels',
|
||||
['n_x'],
|
||||
op.f("ix_pixels_on_n_x"),
|
||||
"pixels",
|
||||
["n_x"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_pixels_on_n_y'),
|
||||
'pixels',
|
||||
['n_y'],
|
||||
op.f("ix_pixels_on_n_y"),
|
||||
"pixels",
|
||||
["n_y"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
# This `UniqueConstraint` is needed by the `addresses_pixels` table below.
|
||||
op.create_unique_constraint(
|
||||
'uq_addresses_on_id_city_id',
|
||||
'addresses',
|
||||
['id', 'city_id'],
|
||||
"uq_addresses_on_id_city_id",
|
||||
"addresses",
|
||||
["id", "city_id"],
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'addresses_pixels',
|
||||
sa.Column('address_id', sa.Integer(), nullable=False),
|
||||
sa.Column('city_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('grid_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('pixel_id', sa.Integer(), nullable=False),
|
||||
"addresses_pixels",
|
||||
sa.Column("address_id", sa.Integer(), nullable=False),
|
||||
sa.Column("city_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("grid_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("pixel_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
['address_id', 'city_id'],
|
||||
["address_id", "city_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.addresses.id',
|
||||
f'{config.CLEAN_SCHEMA}.addresses.city_id',
|
||||
f"{config.CLEAN_SCHEMA}.addresses.id",
|
||||
f"{config.CLEAN_SCHEMA}.addresses.city_id",
|
||||
],
|
||||
name=op.f('fk_addresses_pixels_to_addresses_via_address_id_city_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
name=op.f("fk_addresses_pixels_to_addresses_via_address_id_city_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['grid_id', 'city_id'],
|
||||
["grid_id", "city_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.grids.id',
|
||||
f'{config.CLEAN_SCHEMA}.grids.city_id',
|
||||
f"{config.CLEAN_SCHEMA}.grids.id",
|
||||
f"{config.CLEAN_SCHEMA}.grids.city_id",
|
||||
],
|
||||
name=op.f('fk_addresses_pixels_to_grids_via_grid_id_city_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
name=op.f("fk_addresses_pixels_to_grids_via_grid_id_city_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['pixel_id', 'grid_id'],
|
||||
["pixel_id", "grid_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.pixels.id',
|
||||
f'{config.CLEAN_SCHEMA}.pixels.grid_id',
|
||||
f"{config.CLEAN_SCHEMA}.pixels.id",
|
||||
f"{config.CLEAN_SCHEMA}.pixels.grid_id",
|
||||
],
|
||||
name=op.f('fk_addresses_pixels_to_pixels_via_pixel_id_grid_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
name=op.f("fk_addresses_pixels_to_pixels_via_pixel_id_grid_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.PrimaryKeyConstraint(
|
||||
'address_id',
|
||||
'pixel_id',
|
||||
name=op.f('pk_addresses_pixels'),
|
||||
"address_id",
|
||||
"pixel_id",
|
||||
name=op.f("pk_addresses_pixels"),
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'address_id',
|
||||
'grid_id',
|
||||
name=op.f('uq_addresses_pixels_on_address_id_grid_id'),
|
||||
"address_id",
|
||||
"grid_id",
|
||||
name=op.f("uq_addresses_pixels_on_address_id_grid_id"),
|
||||
),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
@ -154,27 +154,27 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
"""Downgrade to revision f11cd76d2f45."""
|
||||
op.drop_table('addresses_pixels', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("addresses_pixels", schema=config.CLEAN_SCHEMA)
|
||||
op.drop_constraint(
|
||||
'uq_addresses_on_id_city_id',
|
||||
'addresses',
|
||||
"uq_addresses_on_id_city_id",
|
||||
"addresses",
|
||||
type_=None,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_index(
|
||||
op.f('ix_pixels_on_n_y'),
|
||||
table_name='pixels',
|
||||
op.f("ix_pixels_on_n_y"),
|
||||
table_name="pixels",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_index(
|
||||
op.f('ix_pixels_on_n_x'),
|
||||
table_name='pixels',
|
||||
op.f("ix_pixels_on_n_x"),
|
||||
table_name="pixels",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_index(
|
||||
op.f('ix_pixels_on_grid_id'),
|
||||
table_name='pixels',
|
||||
op.f("ix_pixels_on_grid_id"),
|
||||
table_name="pixels",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_table('pixels', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table('grids', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("pixels", schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("grids", schema=config.CLEAN_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -13,33 +13,33 @@ from sqlalchemy.dialects import postgresql
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = 'e40623e10405'
|
||||
down_revision = '888e352d7526'
|
||||
revision = "e40623e10405"
|
||||
down_revision = "888e352d7526"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision e40623e10405."""
|
||||
op.create_table(
|
||||
'forecasts',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('pixel_id', sa.Integer(), nullable=False),
|
||||
sa.Column('start_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('time_step', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('training_horizon', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('method', sa.Unicode(length=20), nullable=False),
|
||||
sa.Column('prediction', postgresql.DOUBLE_PRECISION(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_forecasts')),
|
||||
"forecasts",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("pixel_id", sa.Integer(), nullable=False),
|
||||
sa.Column("start_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("time_step", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("training_horizon", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("method", sa.Unicode(length=20), nullable=False),
|
||||
sa.Column("prediction", postgresql.DOUBLE_PRECISION(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_forecasts")),
|
||||
sa.ForeignKeyConstraint(
|
||||
['pixel_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.pixels.id'],
|
||||
name=op.f('fk_forecasts_to_pixels_via_pixel_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["pixel_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.pixels.id"],
|
||||
name=op.f("fk_forecasts_to_pixels_via_pixel_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -49,44 +49,44 @@ def upgrade():
|
|||
EXTRACT(HOUR FROM start_at) > 22
|
||||
)
|
||||
""",
|
||||
name=op.f('ck_forecasts_on_start_at_must_be_within_operating_hours'),
|
||||
name=op.f("ck_forecasts_on_start_at_must_be_within_operating_hours"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'CAST(EXTRACT(MINUTES FROM start_at) AS INTEGER) % 15 = 0',
|
||||
name=op.f('ck_forecasts_on_start_at_minutes_must_be_quarters_of_the_hour'),
|
||||
"CAST(EXTRACT(MINUTES FROM start_at) AS INTEGER) % 15 = 0",
|
||||
name=op.f("ck_forecasts_on_start_at_minutes_must_be_quarters_of_the_hour"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'CAST(EXTRACT(MICROSECONDS FROM start_at) AS INTEGER) % 1000000 = 0',
|
||||
name=op.f('ck_forecasts_on_start_at_allows_no_microseconds'),
|
||||
"CAST(EXTRACT(MICROSECONDS FROM start_at) AS INTEGER) % 1000000 = 0",
|
||||
name=op.f("ck_forecasts_on_start_at_allows_no_microseconds"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'EXTRACT(SECONDS FROM start_at) = 0',
|
||||
name=op.f('ck_forecasts_on_start_at_allows_no_seconds'),
|
||||
"EXTRACT(SECONDS FROM start_at) = 0",
|
||||
name=op.f("ck_forecasts_on_start_at_allows_no_seconds"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'time_step > 0',
|
||||
name=op.f('ck_forecasts_on_time_step_must_be_positive'),
|
||||
"time_step > 0",
|
||||
name=op.f("ck_forecasts_on_time_step_must_be_positive"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'training_horizon > 0',
|
||||
name=op.f('ck_forecasts_on_training_horizon_must_be_positive'),
|
||||
"training_horizon > 0",
|
||||
name=op.f("ck_forecasts_on_training_horizon_must_be_positive"),
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'pixel_id',
|
||||
'start_at',
|
||||
'time_step',
|
||||
'training_horizon',
|
||||
'method',
|
||||
"pixel_id",
|
||||
"start_at",
|
||||
"time_step",
|
||||
"training_horizon",
|
||||
"method",
|
||||
name=op.f(
|
||||
'uq_forecasts_on_pixel_id_start_at_time_step_training_horizon_method',
|
||||
"uq_forecasts_on_pixel_id_start_at_time_step_training_horizon_method",
|
||||
),
|
||||
),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_forecasts_on_pixel_id'),
|
||||
'forecasts',
|
||||
['pixel_id'],
|
||||
op.f("ix_forecasts_on_pixel_id"),
|
||||
"forecasts",
|
||||
["pixel_id"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
@ -94,4 +94,4 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
"""Downgrade to revision 888e352d7526."""
|
||||
op.drop_table('forecasts', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("forecasts", schema=config.CLEAN_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -13,46 +13,46 @@ from sqlalchemy.dialects import postgresql
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = '26711cd3f9b9'
|
||||
down_revision = 'e40623e10405'
|
||||
revision = "26711cd3f9b9"
|
||||
down_revision = "e40623e10405"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision 26711cd3f9b9."""
|
||||
op.alter_column(
|
||||
'forecasts',
|
||||
'method',
|
||||
new_column_name='model',
|
||||
"forecasts",
|
||||
"method",
|
||||
new_column_name="model",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('low80', postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
"forecasts",
|
||||
sa.Column("low80", postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('high80', postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
"forecasts",
|
||||
sa.Column("high80", postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('low95', postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
"forecasts",
|
||||
sa.Column("low95", postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('high95', postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
"forecasts",
|
||||
sa.Column("high95", postgresql.DOUBLE_PRECISION(), nullable=True),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('ck_forecasts_on_ci_upper_and_lower_bounds'),
|
||||
'forecasts',
|
||||
op.f("ck_forecasts_on_ci_upper_and_lower_bounds"),
|
||||
"forecasts",
|
||||
"""
|
||||
NOT (
|
||||
low80 IS NULL AND high80 IS NOT NULL
|
||||
|
|
@ -67,8 +67,8 @@ def upgrade():
|
|||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('prediction_must_be_within_ci'),
|
||||
'forecasts',
|
||||
op.f("prediction_must_be_within_ci"),
|
||||
"forecasts",
|
||||
"""
|
||||
NOT (
|
||||
prediction < low80
|
||||
|
|
@ -83,8 +83,8 @@ def upgrade():
|
|||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('ci_upper_bound_greater_than_lower_bound'),
|
||||
'forecasts',
|
||||
op.f("ci_upper_bound_greater_than_lower_bound"),
|
||||
"forecasts",
|
||||
"""
|
||||
NOT (
|
||||
low80 > high80
|
||||
|
|
@ -95,8 +95,8 @@ def upgrade():
|
|||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('ci95_must_be_wider_than_ci80'),
|
||||
'forecasts',
|
||||
op.f("ci95_must_be_wider_than_ci80"),
|
||||
"forecasts",
|
||||
"""
|
||||
NOT (
|
||||
low80 < low95
|
||||
|
|
@ -111,28 +111,28 @@ def upgrade():
|
|||
def downgrade():
|
||||
"""Downgrade to revision e40623e10405."""
|
||||
op.alter_column(
|
||||
'forecasts',
|
||||
'model',
|
||||
new_column_name='method',
|
||||
"forecasts",
|
||||
"model",
|
||||
new_column_name="method",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_column(
|
||||
'forecasts',
|
||||
'low80',
|
||||
"forecasts",
|
||||
"low80",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_column(
|
||||
'forecasts',
|
||||
'high80',
|
||||
"forecasts",
|
||||
"high80",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_column(
|
||||
'forecasts',
|
||||
'low95',
|
||||
"forecasts",
|
||||
"low95",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_column(
|
||||
'forecasts',
|
||||
'high95',
|
||||
"forecasts",
|
||||
"high95",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -129,13 +129,13 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = 'e86290e7305e'
|
||||
down_revision = '26711cd3f9b9'
|
||||
revision = "e86290e7305e"
|
||||
down_revision = "26711cd3f9b9"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
|
@ -347,26 +347,26 @@ def upgrade():
|
|||
""",
|
||||
)
|
||||
op.create_unique_constraint(
|
||||
'uq_restaurants_on_id_address_id',
|
||||
'restaurants',
|
||||
['id', 'address_id'],
|
||||
"uq_restaurants_on_id_address_id",
|
||||
"restaurants",
|
||||
["id", "address_id"],
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_foreign_key(
|
||||
op.f('fk_orders_to_restaurants_via_restaurant_id_pickup_address_id'),
|
||||
'orders',
|
||||
'restaurants',
|
||||
['restaurant_id', 'pickup_address_id'],
|
||||
['id', 'address_id'],
|
||||
op.f("fk_orders_to_restaurants_via_restaurant_id_pickup_address_id"),
|
||||
"orders",
|
||||
"restaurants",
|
||||
["restaurant_id", "pickup_address_id"],
|
||||
["id", "address_id"],
|
||||
source_schema=config.CLEAN_SCHEMA,
|
||||
referent_schema=config.CLEAN_SCHEMA,
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
)
|
||||
op.drop_constraint(
|
||||
'fk_orders_to_restaurants_via_restaurant_id',
|
||||
'orders',
|
||||
type_='foreignkey',
|
||||
"fk_orders_to_restaurants_via_restaurant_id",
|
||||
"orders",
|
||||
type_="foreignkey",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
|
|
@ -374,25 +374,25 @@ def upgrade():
|
|||
def downgrade():
|
||||
"""Downgrade to revision 26711cd3f9b9."""
|
||||
op.create_foreign_key(
|
||||
op.f('fk_orders_to_restaurants_via_restaurant_id'),
|
||||
'orders',
|
||||
'restaurants',
|
||||
['restaurant_id'],
|
||||
['id'],
|
||||
op.f("fk_orders_to_restaurants_via_restaurant_id"),
|
||||
"orders",
|
||||
"restaurants",
|
||||
["restaurant_id"],
|
||||
["id"],
|
||||
source_schema=config.CLEAN_SCHEMA,
|
||||
referent_schema=config.CLEAN_SCHEMA,
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
)
|
||||
op.drop_constraint(
|
||||
'fk_orders_to_restaurants_via_restaurant_id_pickup_address_id',
|
||||
'orders',
|
||||
type_='foreignkey',
|
||||
"fk_orders_to_restaurants_via_restaurant_id_pickup_address_id",
|
||||
"orders",
|
||||
type_="foreignkey",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.drop_constraint(
|
||||
'uq_restaurants_on_id_address_id',
|
||||
'restaurants',
|
||||
type_='unique',
|
||||
"uq_restaurants_on_id_address_id",
|
||||
"restaurants",
|
||||
type_="unique",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,30 +12,30 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = 'c2af85bada01'
|
||||
down_revision = 'e86290e7305e'
|
||||
revision = "c2af85bada01"
|
||||
down_revision = "e86290e7305e"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision c2af85bada01."""
|
||||
op.add_column(
|
||||
'forecasts',
|
||||
sa.Column('actual', sa.SmallInteger(), nullable=False),
|
||||
"forecasts",
|
||||
sa.Column("actual", sa.SmallInteger(), nullable=False),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_check_constraint(
|
||||
op.f('ck_forecasts_on_actuals_must_be_non_negative'),
|
||||
'forecasts',
|
||||
'actual >= 0',
|
||||
op.f("ck_forecasts_on_actuals_must_be_non_negative"),
|
||||
"forecasts",
|
||||
"actual >= 0",
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Downgrade to revision e86290e7305e."""
|
||||
op.drop_column('forecasts', 'actual', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_column("forecasts", "actual", schema=config.CLEAN_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = '8bfb928a31f8'
|
||||
down_revision = 'c2af85bada01'
|
||||
revision = "8bfb928a31f8"
|
||||
down_revision = "c2af85bada01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
|
|
|||
|
|
@ -13,79 +13,79 @@ from sqlalchemy.dialects import postgresql
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = 'b4dd0b8903a5'
|
||||
down_revision = '8bfb928a31f8'
|
||||
revision = "b4dd0b8903a5"
|
||||
down_revision = "8bfb928a31f8"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrade to revision b4dd0b8903a5."""
|
||||
op.create_table(
|
||||
'addresses_addresses',
|
||||
sa.Column('first_address_id', sa.Integer(), nullable=False),
|
||||
sa.Column('second_address_id', sa.Integer(), nullable=False),
|
||||
sa.Column('city_id', sa.SmallInteger(), nullable=False),
|
||||
sa.Column('air_distance', sa.Integer(), nullable=False),
|
||||
sa.Column('bicycle_distance', sa.Integer(), nullable=True),
|
||||
sa.Column('bicycle_duration', sa.Integer(), nullable=True),
|
||||
sa.Column('directions', postgresql.JSON(), nullable=True),
|
||||
"addresses_addresses",
|
||||
sa.Column("first_address_id", sa.Integer(), nullable=False),
|
||||
sa.Column("second_address_id", sa.Integer(), nullable=False),
|
||||
sa.Column("city_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("air_distance", sa.Integer(), nullable=False),
|
||||
sa.Column("bicycle_distance", sa.Integer(), nullable=True),
|
||||
sa.Column("bicycle_duration", sa.Integer(), nullable=True),
|
||||
sa.Column("directions", postgresql.JSON(), nullable=True),
|
||||
sa.PrimaryKeyConstraint(
|
||||
'first_address_id',
|
||||
'second_address_id',
|
||||
name=op.f('pk_addresses_addresses'),
|
||||
"first_address_id",
|
||||
"second_address_id",
|
||||
name=op.f("pk_addresses_addresses"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['first_address_id', 'city_id'],
|
||||
["first_address_id", "city_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.addresses.id',
|
||||
f'{config.CLEAN_SCHEMA}.addresses.city_id',
|
||||
f"{config.CLEAN_SCHEMA}.addresses.id",
|
||||
f"{config.CLEAN_SCHEMA}.addresses.city_id",
|
||||
],
|
||||
name=op.f(
|
||||
'fk_addresses_addresses_to_addresses_via_first_address_id_city_id',
|
||||
"fk_addresses_addresses_to_addresses_via_first_address_id_city_id",
|
||||
),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['second_address_id', 'city_id'],
|
||||
["second_address_id", "city_id"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.addresses.id',
|
||||
f'{config.CLEAN_SCHEMA}.addresses.city_id',
|
||||
f"{config.CLEAN_SCHEMA}.addresses.id",
|
||||
f"{config.CLEAN_SCHEMA}.addresses.city_id",
|
||||
],
|
||||
name=op.f(
|
||||
'fk_addresses_addresses_to_addresses_via_second_address_id_city_id',
|
||||
"fk_addresses_addresses_to_addresses_via_second_address_id_city_id",
|
||||
),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'first_address_id',
|
||||
'second_address_id',
|
||||
name=op.f('uq_addresses_addresses_on_first_address_id_second_address_id'),
|
||||
"first_address_id",
|
||||
"second_address_id",
|
||||
name=op.f("uq_addresses_addresses_on_first_address_id_second_address_id"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'first_address_id < second_address_id',
|
||||
name=op.f('ck_addresses_addresses_on_distances_are_symmetric_for_bicycles'),
|
||||
"first_address_id < second_address_id",
|
||||
name=op.f("ck_addresses_addresses_on_distances_are_symmetric_for_bicycles"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'0 <= air_distance AND air_distance < 20000',
|
||||
name=op.f('ck_addresses_addresses_on_realistic_air_distance'),
|
||||
"0 <= air_distance AND air_distance < 20000",
|
||||
name=op.f("ck_addresses_addresses_on_realistic_air_distance"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'bicycle_distance < 25000',
|
||||
name=op.f('ck_addresses_addresses_on_realistic_bicycle_distance'),
|
||||
"bicycle_distance < 25000",
|
||||
name=op.f("ck_addresses_addresses_on_realistic_bicycle_distance"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'air_distance <= bicycle_distance',
|
||||
name=op.f('ck_addresses_addresses_on_air_distance_is_shortest'),
|
||||
"air_distance <= bicycle_distance",
|
||||
name=op.f("ck_addresses_addresses_on_air_distance_is_shortest"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'0 <= bicycle_duration AND bicycle_duration <= 3600',
|
||||
name=op.f('ck_addresses_addresses_on_realistic_bicycle_travel_time'),
|
||||
"0 <= bicycle_duration AND bicycle_duration <= 3600",
|
||||
name=op.f("ck_addresses_addresses_on_realistic_bicycle_travel_time"),
|
||||
),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
@ -93,4 +93,4 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
"""Downgrade to revision 8bfb928a31f8."""
|
||||
op.drop_table('addresses_addresses', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("addresses_addresses", schema=config.CLEAN_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ from alembic import op
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
revision = '81aa304d7a6e'
|
||||
down_revision = 'b4dd0b8903a5'
|
||||
revision = "81aa304d7a6e"
|
||||
down_revision = "b4dd0b8903a5"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
|
@ -59,88 +59,88 @@ def upgrade():
|
|||
|
||||
# This `UniqueConstraint` is needed by the `replayed_orders` table below.
|
||||
op.create_unique_constraint(
|
||||
'uq_orders_on_id_ad_hoc',
|
||||
'orders',
|
||||
['id', 'ad_hoc'],
|
||||
"uq_orders_on_id_ad_hoc",
|
||||
"orders",
|
||||
["id", "ad_hoc"],
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'replay_simulations',
|
||||
sa.Column('id', sa.Integer, autoincrement=True),
|
||||
sa.Column('city_id', sa.SmallInteger, nullable=False),
|
||||
sa.Column('strategy', sa.Unicode(length=100), nullable=False),
|
||||
sa.Column('run', sa.SmallInteger, nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_replay_simulations')),
|
||||
"replay_simulations",
|
||||
sa.Column("id", sa.Integer, autoincrement=True),
|
||||
sa.Column("city_id", sa.SmallInteger, nullable=False),
|
||||
sa.Column("strategy", sa.Unicode(length=100), nullable=False),
|
||||
sa.Column("run", sa.SmallInteger, nullable=False),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_replay_simulations")),
|
||||
sa.ForeignKeyConstraint(
|
||||
['city_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.cities.id'],
|
||||
name=op.f('fk_replay_simulations_to_cities_via_city_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["city_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.cities.id"],
|
||||
name=op.f("fk_replay_simulations_to_cities_via_city_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
'city_id',
|
||||
'strategy',
|
||||
'run',
|
||||
name=op.f('uq_replay_simulations_on_city_id_strategy_run'),
|
||||
"city_id",
|
||||
"strategy",
|
||||
"run",
|
||||
name=op.f("uq_replay_simulations_on_city_id_strategy_run"),
|
||||
),
|
||||
sa.CheckConstraint('run >= 0', name=op.f('run_is_a_count')),
|
||||
sa.CheckConstraint("run >= 0", name=op.f("run_is_a_count")),
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'replayed_orders',
|
||||
sa.Column('simulation_id', sa.Integer, primary_key=True),
|
||||
sa.Column('actual_order_id', sa.Integer, primary_key=True),
|
||||
sa.Column('ad_hoc', sa.Boolean, nullable=False),
|
||||
sa.Column('placed_at', sa.DateTime, nullable=False),
|
||||
sa.Column('scheduled_delivery_at', sa.DateTime),
|
||||
sa.Column('cancelled_at', sa.DateTime),
|
||||
sa.Column('estimated_prep_duration', sa.SmallInteger),
|
||||
sa.Column('restaurant_notified_at', sa.DateTime),
|
||||
sa.Column('restaurant_confirmed_at', sa.DateTime),
|
||||
sa.Column('restaurant_ready_at', sa.DateTime),
|
||||
sa.Column('dispatch_at', sa.DateTime),
|
||||
sa.Column('first_estimated_delivery_at', sa.DateTime),
|
||||
sa.Column('courier_id', sa.Integer),
|
||||
sa.Column('courier_notified_at', sa.DateTime),
|
||||
sa.Column('courier_accepted_at', sa.DateTime),
|
||||
sa.Column('utilization', sa.SmallInteger),
|
||||
sa.Column('reached_pickup_at', sa.DateTime),
|
||||
sa.Column('pickup_at', sa.DateTime),
|
||||
sa.Column('left_pickup_at', sa.DateTime),
|
||||
sa.Column('reached_delivery_at', sa.DateTime),
|
||||
sa.Column('delivery_at', sa.DateTime),
|
||||
"replayed_orders",
|
||||
sa.Column("simulation_id", sa.Integer, primary_key=True),
|
||||
sa.Column("actual_order_id", sa.Integer, primary_key=True),
|
||||
sa.Column("ad_hoc", sa.Boolean, nullable=False),
|
||||
sa.Column("placed_at", sa.DateTime, nullable=False),
|
||||
sa.Column("scheduled_delivery_at", sa.DateTime),
|
||||
sa.Column("cancelled_at", sa.DateTime),
|
||||
sa.Column("estimated_prep_duration", sa.SmallInteger),
|
||||
sa.Column("restaurant_notified_at", sa.DateTime),
|
||||
sa.Column("restaurant_confirmed_at", sa.DateTime),
|
||||
sa.Column("restaurant_ready_at", sa.DateTime),
|
||||
sa.Column("dispatch_at", sa.DateTime),
|
||||
sa.Column("first_estimated_delivery_at", sa.DateTime),
|
||||
sa.Column("courier_id", sa.Integer),
|
||||
sa.Column("courier_notified_at", sa.DateTime),
|
||||
sa.Column("courier_accepted_at", sa.DateTime),
|
||||
sa.Column("utilization", sa.SmallInteger),
|
||||
sa.Column("reached_pickup_at", sa.DateTime),
|
||||
sa.Column("pickup_at", sa.DateTime),
|
||||
sa.Column("left_pickup_at", sa.DateTime),
|
||||
sa.Column("reached_delivery_at", sa.DateTime),
|
||||
sa.Column("delivery_at", sa.DateTime),
|
||||
sa.PrimaryKeyConstraint(
|
||||
'simulation_id',
|
||||
'actual_order_id',
|
||||
name=op.f('pk_replayed_orders'),
|
||||
"simulation_id",
|
||||
"actual_order_id",
|
||||
name=op.f("pk_replayed_orders"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['simulation_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.replay_simulations.id'],
|
||||
name=op.f('fk_replayed_orders_to_replay_simulations_via_simulation_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["simulation_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.replay_simulations.id"],
|
||||
name=op.f("fk_replayed_orders_to_replay_simulations_via_simulation_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
# Needs the `UniqueConstraint` from above.
|
||||
['actual_order_id', 'ad_hoc'],
|
||||
["actual_order_id", "ad_hoc"],
|
||||
[
|
||||
f'{config.CLEAN_SCHEMA}.orders.id',
|
||||
f'{config.CLEAN_SCHEMA}.orders.ad_hoc',
|
||||
f"{config.CLEAN_SCHEMA}.orders.id",
|
||||
f"{config.CLEAN_SCHEMA}.orders.ad_hoc",
|
||||
],
|
||||
name=op.f('fk_replayed_orders_to_orders_via_actual_order_id_ad_hoc'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
name=op.f("fk_replayed_orders_to_orders_via_actual_order_id_ad_hoc"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['courier_id'],
|
||||
[f'{config.CLEAN_SCHEMA}.couriers.id'],
|
||||
name=op.f('fk_replayed_orders_to_couriers_via_courier_id'),
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
["courier_id"],
|
||||
[f"{config.CLEAN_SCHEMA}.couriers.id"],
|
||||
name=op.f("fk_replayed_orders_to_couriers_via_courier_id"),
|
||||
onupdate="RESTRICT",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -156,7 +156,7 @@ def upgrade():
|
|||
scheduled_delivery_at IS NOT NULL
|
||||
)
|
||||
""",
|
||||
name=op.f('either_ad_hoc_or_scheduled_order'),
|
||||
name=op.f("either_ad_hoc_or_scheduled_order"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -169,7 +169,7 @@ def upgrade():
|
|||
)
|
||||
)
|
||||
""",
|
||||
name=op.f('ad_hoc_orders_within_business_hours'),
|
||||
name=op.f("ad_hoc_orders_within_business_hours"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -190,7 +190,7 @@ def upgrade():
|
|||
)
|
||||
)
|
||||
""",
|
||||
name=op.f('scheduled_orders_within_business_hours'),
|
||||
name=op.f("scheduled_orders_within_business_hours"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -204,7 +204,7 @@ def upgrade():
|
|||
= 0
|
||||
)
|
||||
""",
|
||||
name=op.f('scheduled_orders_must_be_at_quarters_of_an_hour'),
|
||||
name=op.f("scheduled_orders_must_be_at_quarters_of_an_hour"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -212,7 +212,7 @@ def upgrade():
|
|||
EXTRACT(EPOCH FROM scheduled_delivery_at - placed_at) < 1800
|
||||
)
|
||||
""",
|
||||
name=op.f('scheduled_orders_not_within_30_minutes'),
|
||||
name=op.f("scheduled_orders_not_within_30_minutes"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -244,7 +244,7 @@ def upgrade():
|
|||
delivery_at IS NOT NULL
|
||||
)
|
||||
""",
|
||||
name=op.f('orders_must_be_either_cancelled_or_fully_simulated'),
|
||||
name=op.f("orders_must_be_either_cancelled_or_fully_simulated"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -272,19 +272,19 @@ def upgrade():
|
|||
delivery_at IS NOT NULL
|
||||
)
|
||||
""",
|
||||
name=op.f('cancellations_may_only_occur_before_pickup'),
|
||||
name=op.f("cancellations_may_only_occur_before_pickup"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'0 <= estimated_prep_duration AND estimated_prep_duration <= 3600',
|
||||
name=op.f('estimated_prep_duration_between_0_and_3600'),
|
||||
"0 <= estimated_prep_duration AND estimated_prep_duration <= 3600",
|
||||
name=op.f("estimated_prep_duration_between_0_and_3600"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'estimated_prep_duration % 60 = 0',
|
||||
name=op.f('estimated_prep_duration_must_be_whole_minutes'),
|
||||
"estimated_prep_duration % 60 = 0",
|
||||
name=op.f("estimated_prep_duration_must_be_whole_minutes"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
'0 <= utilization AND utilization <= 100',
|
||||
name=op.f('utilization_between_0_and_100'),
|
||||
"0 <= utilization AND utilization <= 100",
|
||||
name=op.f("utilization_between_0_and_100"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"""
|
||||
|
|
@ -294,71 +294,71 @@ def upgrade():
|
|||
EXTRACT(HOUR FROM dispatch_at) < 11
|
||||
)
|
||||
""",
|
||||
name=op.f('orders_dispatched_in_business_hours'),
|
||||
name=op.f("orders_dispatched_in_business_hours"),
|
||||
),
|
||||
*(
|
||||
sa.CheckConstraint(
|
||||
constraint,
|
||||
name='ordered_timestamps_{index}'.format(index=index),
|
||||
name="ordered_timestamps_{index}".format(index=index),
|
||||
)
|
||||
for index, constraint in enumerate(
|
||||
(
|
||||
'placed_at < scheduled_delivery_at',
|
||||
'placed_at < cancelled_at',
|
||||
'placed_at < restaurant_notified_at',
|
||||
'placed_at < restaurant_confirmed_at',
|
||||
'placed_at < restaurant_ready_at',
|
||||
'placed_at < dispatch_at',
|
||||
'placed_at < first_estimated_delivery_at',
|
||||
'placed_at < courier_notified_at',
|
||||
'placed_at < courier_accepted_at',
|
||||
'placed_at < reached_pickup_at',
|
||||
'placed_at < pickup_at',
|
||||
'placed_at < left_pickup_at',
|
||||
'placed_at < reached_delivery_at',
|
||||
'placed_at < delivery_at',
|
||||
'cancelled_at > restaurant_notified_at',
|
||||
'cancelled_at > restaurant_confirmed_at',
|
||||
'cancelled_at > restaurant_ready_at',
|
||||
'cancelled_at > dispatch_at',
|
||||
'cancelled_at > courier_notified_at',
|
||||
'cancelled_at > courier_accepted_at',
|
||||
'cancelled_at > reached_pickup_at',
|
||||
'restaurant_notified_at < restaurant_confirmed_at',
|
||||
'restaurant_notified_at < restaurant_ready_at',
|
||||
'restaurant_notified_at < pickup_at',
|
||||
'restaurant_confirmed_at < restaurant_ready_at',
|
||||
'restaurant_confirmed_at < pickup_at',
|
||||
'restaurant_ready_at < pickup_at',
|
||||
'dispatch_at < first_estimated_delivery_at',
|
||||
'dispatch_at < courier_notified_at',
|
||||
'dispatch_at < courier_accepted_at',
|
||||
'dispatch_at < reached_pickup_at',
|
||||
'dispatch_at < pickup_at',
|
||||
'dispatch_at < left_pickup_at',
|
||||
'dispatch_at < reached_delivery_at',
|
||||
'dispatch_at < delivery_at',
|
||||
'courier_notified_at < courier_accepted_at',
|
||||
'courier_notified_at < reached_pickup_at',
|
||||
'courier_notified_at < pickup_at',
|
||||
'courier_notified_at < left_pickup_at',
|
||||
'courier_notified_at < reached_delivery_at',
|
||||
'courier_notified_at < delivery_at',
|
||||
'courier_accepted_at < reached_pickup_at',
|
||||
'courier_accepted_at < pickup_at',
|
||||
'courier_accepted_at < left_pickup_at',
|
||||
'courier_accepted_at < reached_delivery_at',
|
||||
'courier_accepted_at < delivery_at',
|
||||
'reached_pickup_at < pickup_at',
|
||||
'reached_pickup_at < left_pickup_at',
|
||||
'reached_pickup_at < reached_delivery_at',
|
||||
'reached_pickup_at < delivery_at',
|
||||
'pickup_at < left_pickup_at',
|
||||
'pickup_at < reached_delivery_at',
|
||||
'pickup_at < delivery_at',
|
||||
'left_pickup_at < reached_delivery_at',
|
||||
'left_pickup_at < delivery_at',
|
||||
'reached_delivery_at < delivery_at',
|
||||
"placed_at < scheduled_delivery_at",
|
||||
"placed_at < cancelled_at",
|
||||
"placed_at < restaurant_notified_at",
|
||||
"placed_at < restaurant_confirmed_at",
|
||||
"placed_at < restaurant_ready_at",
|
||||
"placed_at < dispatch_at",
|
||||
"placed_at < first_estimated_delivery_at",
|
||||
"placed_at < courier_notified_at",
|
||||
"placed_at < courier_accepted_at",
|
||||
"placed_at < reached_pickup_at",
|
||||
"placed_at < pickup_at",
|
||||
"placed_at < left_pickup_at",
|
||||
"placed_at < reached_delivery_at",
|
||||
"placed_at < delivery_at",
|
||||
"cancelled_at > restaurant_notified_at",
|
||||
"cancelled_at > restaurant_confirmed_at",
|
||||
"cancelled_at > restaurant_ready_at",
|
||||
"cancelled_at > dispatch_at",
|
||||
"cancelled_at > courier_notified_at",
|
||||
"cancelled_at > courier_accepted_at",
|
||||
"cancelled_at > reached_pickup_at",
|
||||
"restaurant_notified_at < restaurant_confirmed_at",
|
||||
"restaurant_notified_at < restaurant_ready_at",
|
||||
"restaurant_notified_at < pickup_at",
|
||||
"restaurant_confirmed_at < restaurant_ready_at",
|
||||
"restaurant_confirmed_at < pickup_at",
|
||||
"restaurant_ready_at < pickup_at",
|
||||
"dispatch_at < first_estimated_delivery_at",
|
||||
"dispatch_at < courier_notified_at",
|
||||
"dispatch_at < courier_accepted_at",
|
||||
"dispatch_at < reached_pickup_at",
|
||||
"dispatch_at < pickup_at",
|
||||
"dispatch_at < left_pickup_at",
|
||||
"dispatch_at < reached_delivery_at",
|
||||
"dispatch_at < delivery_at",
|
||||
"courier_notified_at < courier_accepted_at",
|
||||
"courier_notified_at < reached_pickup_at",
|
||||
"courier_notified_at < pickup_at",
|
||||
"courier_notified_at < left_pickup_at",
|
||||
"courier_notified_at < reached_delivery_at",
|
||||
"courier_notified_at < delivery_at",
|
||||
"courier_accepted_at < reached_pickup_at",
|
||||
"courier_accepted_at < pickup_at",
|
||||
"courier_accepted_at < left_pickup_at",
|
||||
"courier_accepted_at < reached_delivery_at",
|
||||
"courier_accepted_at < delivery_at",
|
||||
"reached_pickup_at < pickup_at",
|
||||
"reached_pickup_at < left_pickup_at",
|
||||
"reached_pickup_at < reached_delivery_at",
|
||||
"reached_pickup_at < delivery_at",
|
||||
"pickup_at < left_pickup_at",
|
||||
"pickup_at < reached_delivery_at",
|
||||
"pickup_at < delivery_at",
|
||||
"left_pickup_at < reached_delivery_at",
|
||||
"left_pickup_at < delivery_at",
|
||||
"reached_delivery_at < delivery_at",
|
||||
),
|
||||
)
|
||||
),
|
||||
|
|
@ -366,23 +366,23 @@ def upgrade():
|
|||
)
|
||||
|
||||
op.create_index(
|
||||
op.f('ix_replay_simulations_on_city_id'),
|
||||
'replay_simulations',
|
||||
['city_id'],
|
||||
op.f("ix_replay_simulations_on_city_id"),
|
||||
"replay_simulations",
|
||||
["city_id"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_replay_simulations_on_strategy'),
|
||||
'replay_simulations',
|
||||
['strategy'],
|
||||
op.f("ix_replay_simulations_on_strategy"),
|
||||
"replay_simulations",
|
||||
["strategy"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_replayed_orders_on_courier_id'),
|
||||
'replayed_orders',
|
||||
['courier_id'],
|
||||
op.f("ix_replayed_orders_on_courier_id"),
|
||||
"replayed_orders",
|
||||
["courier_id"],
|
||||
unique=False,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
@ -390,11 +390,11 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
"""Downgrade to revision b4dd0b8903a5."""
|
||||
op.drop_table('replayed_orders', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table('replay_simulations', schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("replayed_orders", schema=config.CLEAN_SCHEMA)
|
||||
op.drop_table("replay_simulations", schema=config.CLEAN_SCHEMA)
|
||||
op.drop_constraint(
|
||||
'uq_orders_on_id_ad_hoc',
|
||||
'orders',
|
||||
"uq_orders_on_id_ad_hoc",
|
||||
"orders",
|
||||
type_=None,
|
||||
schema=config.CLEAN_SCHEMA,
|
||||
)
|
||||
|
|
|
|||
326
noxfile.py
326
noxfile.py
|
|
@ -64,35 +64,35 @@ def load_pyproject_toml() -> collections.defaultdict[str, Any]:
|
|||
so, missing keys and tables (i.e., "sections" in the .ini format)
|
||||
do not result in `KeyError`s but return empty `nested_defaultdict`s.
|
||||
"""
|
||||
return defaultify(nox.project.load_toml('pyproject.toml'))
|
||||
return defaultify(nox.project.load_toml("pyproject.toml"))
|
||||
|
||||
|
||||
def load_supported_python_versions(*, reverse: bool = False) -> list[str]:
|
||||
"""Parse the Python versions from the pyproject.toml file."""
|
||||
pyproject = load_pyproject_toml()
|
||||
version_names = {
|
||||
classifier.rsplit(' ')[-1]
|
||||
for classifier in pyproject['project']['classifiers']
|
||||
if classifier.startswith('Programming Language :: Python :: ')
|
||||
classifier.rsplit(" ")[-1]
|
||||
for classifier in pyproject["project"]["classifiers"]
|
||||
if classifier.startswith("Programming Language :: Python :: ")
|
||||
}
|
||||
return sorted(version_names, key=pkg_version.Version, reverse=reverse)
|
||||
|
||||
|
||||
PACKAGE = 'velofy'
|
||||
PACKAGE_LOCATION = 'src/'
|
||||
PACKAGE = "velofy"
|
||||
PACKAGE_LOCATION = "src/"
|
||||
|
||||
DOCS_BUILD = '.cache/docs/'
|
||||
DOCS_LOCATION = 'docs/'
|
||||
DOCS_BUILD = ".cache/docs/"
|
||||
DOCS_LOCATION = "docs/"
|
||||
|
||||
TESTS_LOCATION = 'tests/'
|
||||
TESTS_LOCATION = "tests/"
|
||||
|
||||
# Locations of all *.py files
|
||||
SRC_LOCATIONS = (
|
||||
f'{DOCS_LOCATION}conf.py',
|
||||
'migrations/env.py',
|
||||
'migrations/versions/',
|
||||
'noxfile.py',
|
||||
'scripts/',
|
||||
f"{DOCS_LOCATION}conf.py",
|
||||
"migrations/env.py",
|
||||
"migrations/versions/",
|
||||
"noxfile.py",
|
||||
"scripts/",
|
||||
PACKAGE_LOCATION,
|
||||
TESTS_LOCATION,
|
||||
)
|
||||
|
|
@ -102,13 +102,13 @@ SUPPORTED_PYTHONS = load_supported_python_versions()
|
|||
|
||||
# Must be listed in the "classifiers", which is checked at the bottom
|
||||
# of this file, and satisfy "requires-python" in pyproject.toml
|
||||
MAIN_PYTHON = '3.13'
|
||||
MAIN_PYTHON = "3.13"
|
||||
|
||||
|
||||
nox.options.default_venv_backend = 'uv'
|
||||
nox.options.default_venv_backend = "uv"
|
||||
|
||||
# Use a unified .cache/ folder for all tools
|
||||
nox.options.envdir = '.cache/nox'
|
||||
nox.options.envdir = ".cache/nox"
|
||||
|
||||
# All tools except `git` and `uv` are project dependencies
|
||||
# => Avoid accidental successes if the environment is not set up properly
|
||||
|
|
@ -116,30 +116,30 @@ nox.options.error_on_external_run = True
|
|||
|
||||
# Always start with fresh virtual environments
|
||||
# unless the "-r" or "-R" flags are passed in
|
||||
nox.options.reuse_venv = 'no'
|
||||
nox.options.reuse_venv = "no"
|
||||
|
||||
# Do not run further sessions once one fails
|
||||
nox.options.stop_on_first_error = True
|
||||
|
||||
# Run only the code quality checks by default
|
||||
nox.options.sessions = (
|
||||
'format',
|
||||
'lint',
|
||||
'test',
|
||||
'doctest',
|
||||
"format",
|
||||
"lint",
|
||||
"test",
|
||||
"doctest",
|
||||
)
|
||||
|
||||
|
||||
# Make `uv` use its own `python`
|
||||
# because only then are the headers needed to build `rpy2` from source included
|
||||
os.environ.setdefault('UV_PYTHON_PREFERENCE', 'only-managed')
|
||||
os.environ.setdefault("UV_PYTHON_PREFERENCE", "only-managed")
|
||||
|
||||
# Where to keep temporary files (e.g., the constraints file in `install_pinned()`)
|
||||
tempfile.tempdir = '.cache/tmp'
|
||||
tempfile.tempdir = ".cache/tmp"
|
||||
os.makedirs(tempfile.tempdir, exist_ok=True)
|
||||
|
||||
|
||||
@nox.session(name='format', python=MAIN_PYTHON)
|
||||
@nox.session(name="format", python=MAIN_PYTHON)
|
||||
def format_code(session: Session) -> None:
|
||||
"""Format source files with `autoflake`, `black`, and `isort`.
|
||||
|
||||
|
|
@ -150,24 +150,24 @@ def format_code(session: Session) -> None:
|
|||
|
||||
# The formatters do not need `velofy` installed
|
||||
# because they work on the source files directly
|
||||
install_pinned(session, 'autoflake', 'black', 'isort')
|
||||
install_pinned(session, "autoflake", "black", "isort")
|
||||
|
||||
# Interpret extra arguments as `locations` of source files
|
||||
locations = session.posargs or SRC_LOCATIONS
|
||||
|
||||
# `autoflake` changes files only with the "in-place = true"
|
||||
# in the "[tool.autoflake]" section in pyproject.toml
|
||||
session.run('autoflake', '--version')
|
||||
session.run('autoflake', *locations)
|
||||
session.run("autoflake", "--version")
|
||||
session.run("autoflake", *locations)
|
||||
|
||||
session.run('black', '--version')
|
||||
session.run('black', *locations)
|
||||
session.run("black", "--version")
|
||||
session.run("black", *locations)
|
||||
|
||||
session.run('isort', '--version')
|
||||
session.run('isort', *locations)
|
||||
session.run("isort", "--version")
|
||||
session.run("isort", *locations)
|
||||
|
||||
|
||||
@nox.session(name='lint', python=MAIN_PYTHON)
|
||||
@nox.session(name="lint", python=MAIN_PYTHON)
|
||||
def lint_code(session: Session) -> None:
|
||||
"""Lint source files with `flake8` and `isort`.
|
||||
|
||||
|
|
@ -180,19 +180,19 @@ def lint_code(session: Session) -> None:
|
|||
# because they work on the source files directly
|
||||
install_pinned(
|
||||
session,
|
||||
'flake8',
|
||||
'flake8-annotations',
|
||||
'flake8-bandit',
|
||||
'flake8-black',
|
||||
'flake8-broken-line',
|
||||
'flake8-bugbear',
|
||||
'flake8-commas',
|
||||
'flake8-comprehensions',
|
||||
'flake8-debugger',
|
||||
'flake8-docstrings',
|
||||
'flake8-pyproject',
|
||||
'flake8-pytest-style',
|
||||
'isort',
|
||||
"flake8",
|
||||
"flake8-annotations",
|
||||
"flake8-bandit",
|
||||
"flake8-black",
|
||||
"flake8-broken-line",
|
||||
"flake8-bugbear",
|
||||
"flake8-commas",
|
||||
"flake8-comprehensions",
|
||||
"flake8-debugger",
|
||||
"flake8-docstrings",
|
||||
"flake8-pyproject",
|
||||
"flake8-pytest-style",
|
||||
"isort",
|
||||
# TODO: See comment on `mypy` below
|
||||
# 'mypy',
|
||||
)
|
||||
|
|
@ -202,11 +202,11 @@ def lint_code(session: Session) -> None:
|
|||
|
||||
# `flake8` reads the "[tool.flake8]" section in pyproject.toml
|
||||
# only with the `flake8-pyproject` plugin installed
|
||||
session.run('flake8', '--version')
|
||||
session.run('flake8', *locations)
|
||||
session.run("flake8", "--version")
|
||||
session.run("flake8", *locations)
|
||||
|
||||
session.run('isort', '--version')
|
||||
session.run('isort', '--check-only', *locations)
|
||||
session.run("isort", "--version")
|
||||
session.run("isort", "--check-only", *locations)
|
||||
|
||||
# TODO: Include `mypy` once it passes
|
||||
# - Only for the *.py files to be packaged
|
||||
|
|
@ -216,7 +216,7 @@ def lint_code(session: Session) -> None:
|
|||
# session.run('mypy', PACKAGE_LOCATION)
|
||||
|
||||
|
||||
@nox.session(name='test', python=MAIN_PYTHON)
|
||||
@nox.session(name="test", python=MAIN_PYTHON)
|
||||
def test_code(session: Session) -> None:
|
||||
"""Run the unit and integration tests with `pytest`.
|
||||
|
||||
|
|
@ -229,32 +229,32 @@ def test_code(session: Session) -> None:
|
|||
install_pinned(
|
||||
session,
|
||||
# The tests import `velofy`, so it and its dependencies must be installed
|
||||
'.', # => A non-editable copy as it would really be installed
|
||||
'factory-boy',
|
||||
'Faker',
|
||||
'packaging',
|
||||
'pytest',
|
||||
'pytest-cov',
|
||||
'pytest-env',
|
||||
'pytest-mock',
|
||||
".", # => A non-editable copy as it would really be installed
|
||||
"factory-boy",
|
||||
"Faker",
|
||||
"packaging",
|
||||
"pytest",
|
||||
"pytest-cov",
|
||||
"pytest-env",
|
||||
"pytest-mock",
|
||||
)
|
||||
|
||||
session.run('pytest', '--version')
|
||||
session.run("pytest", "--version")
|
||||
|
||||
pytest_default_args = (
|
||||
# See "[tool.coverage]" in pyproject.toml for `coverage` settings,
|
||||
# for example, branch coverage and report format,
|
||||
# and "[tool.coverage.paths]" mapping `coverage` to src/
|
||||
'--cov',
|
||||
'--no-cov-on-fail',
|
||||
'--cov-fail-under=100',
|
||||
"--cov",
|
||||
"--no-cov-on-fail",
|
||||
"--cov-fail-under=100",
|
||||
TESTS_LOCATION,
|
||||
)
|
||||
|
||||
session.run('pytest', *(session.posargs or pytest_default_args))
|
||||
session.run("pytest", *(session.posargs or pytest_default_args))
|
||||
|
||||
|
||||
@nox.session(name='doctest', python=MAIN_PYTHON)
|
||||
@nox.session(name="doctest", python=MAIN_PYTHON)
|
||||
def test_docstrings(session: Session) -> None:
|
||||
"""Test the code snippets in the docstrings with `xdoctest`.
|
||||
|
||||
|
|
@ -264,22 +264,22 @@ def test_docstrings(session: Session) -> None:
|
|||
"""
|
||||
start(session)
|
||||
|
||||
install_pinned(session, '.', 'xdoctest[colors]')
|
||||
install_pinned(session, ".", "xdoctest[colors]")
|
||||
|
||||
# As `pytest-env` does for `pytest`,
|
||||
# keep `velofy` from connecting to the production database
|
||||
session.env['TESTING'] = 'true'
|
||||
session.env["TESTING"] = "true"
|
||||
|
||||
session.run(
|
||||
'python',
|
||||
'-m',
|
||||
'xdoctest',
|
||||
"python",
|
||||
"-m",
|
||||
"xdoctest",
|
||||
PACKAGE,
|
||||
*(session.posargs or ('all',)),
|
||||
*(session.posargs or ("all",)),
|
||||
)
|
||||
|
||||
|
||||
@nox.session(name='docs', python=MAIN_PYTHON)
|
||||
@nox.session(name="docs", python=MAIN_PYTHON)
|
||||
def build_docs(session: Session) -> None:
|
||||
"""Build the documentation with `sphinx`.
|
||||
|
||||
|
|
@ -289,21 +289,21 @@ def build_docs(session: Session) -> None:
|
|||
|
||||
# The `sphinx-autodoc` extension imports `velofy` to read the docstrings
|
||||
# => `velofy` and its dependencies must be installed
|
||||
install_pinned(session, '.', 'sphinx', 'sphinx-autodoc-typehints')
|
||||
install_pinned(session, ".", "sphinx", "sphinx-autodoc-typehints")
|
||||
|
||||
# As `pytest-env` does for `pytest`,
|
||||
# keep `velofy` from connecting to the production database
|
||||
session.env['TESTING'] = 'true'
|
||||
session.env["TESTING"] = "true"
|
||||
|
||||
session.run('sphinx-build', DOCS_LOCATION, DOCS_BUILD)
|
||||
session.run("sphinx-build", DOCS_LOCATION, DOCS_BUILD)
|
||||
|
||||
# Verify that all external links return 200 OK
|
||||
session.run('sphinx-build', '-b', 'linkcheck', DOCS_LOCATION, DOCS_BUILD)
|
||||
session.run("sphinx-build", "-b", "linkcheck", DOCS_LOCATION, DOCS_BUILD)
|
||||
|
||||
print(f'Docs are available at {os.getcwd()}/{DOCS_BUILD}index.html')
|
||||
print(f"Docs are available at {os.getcwd()}/{DOCS_BUILD}index.html")
|
||||
|
||||
|
||||
@nox.session(name='venv', python=MAIN_PYTHON, venv_backend='none')
|
||||
@nox.session(name="venv", python=MAIN_PYTHON, venv_backend="none")
|
||||
def create_develop_environment(session: Session) -> None:
|
||||
"""Set up the local develop environment in ".venv".
|
||||
|
||||
|
|
@ -316,24 +316,24 @@ def create_develop_environment(session: Session) -> None:
|
|||
Then, `uv run` only uses that environment
|
||||
with "UV_PROJECT_ENVIRONMENT" set to the same location.
|
||||
"""
|
||||
location, *further_args = session.posargs or ('.venv',)
|
||||
location, *further_args = session.posargs or (".venv",)
|
||||
|
||||
if further_args:
|
||||
session.error('Must provide exactly one location')
|
||||
session.error("Must provide exactly one location")
|
||||
|
||||
# All dependency groups are installed because of "default-groups = 'all'"
|
||||
# in the "[tool.uv]" section in pyproject.toml
|
||||
session.run(
|
||||
'uv',
|
||||
'sync',
|
||||
'--all-extras',
|
||||
'--locked',
|
||||
env={'UV_PROJECT_ENVIRONMENT': location},
|
||||
"uv",
|
||||
"sync",
|
||||
"--all-extras",
|
||||
"--locked",
|
||||
env={"UV_PROJECT_ENVIRONMENT": location},
|
||||
external=True,
|
||||
)
|
||||
|
||||
|
||||
@nox.session(name='deps-audit', python=MAIN_PYTHON, reuse_venv=False)
|
||||
@nox.session(name="deps-audit", python=MAIN_PYTHON, reuse_venv=False)
|
||||
def audit_pinned_dependencies(session: Session) -> None:
|
||||
"""Check dependencies for vulnerabilities with `pip-audit`.
|
||||
|
||||
|
|
@ -348,36 +348,36 @@ def audit_pinned_dependencies(session: Session) -> None:
|
|||
start(session)
|
||||
|
||||
# `pip-audit` is not pinned to always check with its latest version
|
||||
session.install('pip-audit')
|
||||
session.install("pip-audit")
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix='.txt') as requirements_txt:
|
||||
with tempfile.NamedTemporaryFile(suffix=".txt") as requirements_txt:
|
||||
session.run(
|
||||
'uv',
|
||||
'export',
|
||||
'--all-extras',
|
||||
'--all-groups',
|
||||
'--locked',
|
||||
'--no-emit-project',
|
||||
'--quiet',
|
||||
f'--output-file={requirements_txt.name}',
|
||||
"uv",
|
||||
"export",
|
||||
"--all-extras",
|
||||
"--all-groups",
|
||||
"--locked",
|
||||
"--no-emit-project",
|
||||
"--quiet",
|
||||
f"--output-file={requirements_txt.name}",
|
||||
)
|
||||
|
||||
session.run('pip-audit', '--version')
|
||||
session.run("pip-audit", "--version")
|
||||
session.run(
|
||||
'pip-audit',
|
||||
'--cache-dir=.cache/pip-audit',
|
||||
'--disable-pip',
|
||||
'--progress-spinner=off',
|
||||
f'--requirement={requirements_txt.name}',
|
||||
'--strict',
|
||||
"pip-audit",
|
||||
"--cache-dir=.cache/pip-audit",
|
||||
"--disable-pip",
|
||||
"--progress-spinner=off",
|
||||
f"--requirement={requirements_txt.name}",
|
||||
"--strict",
|
||||
# TODO: Remove these ignores once we upgrade to `black` v26
|
||||
'--ignore-vuln=PYSEC-2026-2120',
|
||||
'--ignore-vuln=PYSEC-2026-2121',
|
||||
'--ignore-vuln=CVE-2026-114134',
|
||||
"--ignore-vuln=PYSEC-2026-2120",
|
||||
"--ignore-vuln=PYSEC-2026-2121",
|
||||
"--ignore-vuln=CVE-2026-114134",
|
||||
)
|
||||
|
||||
|
||||
@nox.session(name='deps-lock', python=MAIN_PYTHON, venv_backend='none')
|
||||
@nox.session(name="deps-lock", python=MAIN_PYTHON, venv_backend="none")
|
||||
def lock_dependencies(session: Session) -> None:
|
||||
"""Lock dependencies in pyproject.toml into uv.lock.
|
||||
|
||||
|
|
@ -392,12 +392,12 @@ def lock_dependencies(session: Session) -> None:
|
|||
# and call `upgrade_dependencies()` directly
|
||||
# because `session.notify()` starts sessions with a new
|
||||
# `nox.Session` object that does not have the flag set
|
||||
session.env['_lock_only'] = 'true'
|
||||
session.env["_lock_only"] = "true"
|
||||
|
||||
upgrade_dependencies(session)
|
||||
|
||||
|
||||
@nox.session(name='deps-upgrade', python=MAIN_PYTHON, venv_backend='none')
|
||||
@nox.session(name="deps-upgrade", python=MAIN_PYTHON, venv_backend="none")
|
||||
def upgrade_dependencies(session: Session) -> None:
|
||||
"""Pin dependencies in uv.lock to their latest MINOR/PATCH versions.
|
||||
|
||||
|
|
@ -417,20 +417,20 @@ def upgrade_dependencies(session: Session) -> None:
|
|||
So, the obtained upgrades must still be manually
|
||||
`git commit`ed into the repository.
|
||||
"""
|
||||
if session.env.get('_lock_only'):
|
||||
if session.env.get("_lock_only"):
|
||||
upgrade = []
|
||||
elif session.posargs:
|
||||
upgrade = [f'--upgrade-package={pkg_name}' for pkg_name in session.posargs]
|
||||
upgrade = [f"--upgrade-package={pkg_name}" for pkg_name in session.posargs]
|
||||
else:
|
||||
upgrade = ['--upgrade']
|
||||
upgrade = ["--upgrade"]
|
||||
|
||||
session.run('uv', '--version', external=True)
|
||||
session.run('uv', 'lock', *upgrade, external=True)
|
||||
session.run("uv", "--version", external=True)
|
||||
session.run("uv", "lock", *upgrade, external=True)
|
||||
|
||||
session.run('git', 'diff', '--stat', 'uv.lock', external=True)
|
||||
session.run("git", "diff", "--stat", "uv.lock", external=True)
|
||||
|
||||
|
||||
@nox.session(name='deps-upgrade-check', python=MAIN_PYTHON)
|
||||
@nox.session(name="deps-upgrade-check", python=MAIN_PYTHON)
|
||||
def check_dependency_upgrades(session: Session) -> None:
|
||||
"""Check the dependencies in uv.lock for upgrades.
|
||||
|
||||
|
|
@ -445,17 +445,17 @@ def check_dependency_upgrades(session: Session) -> None:
|
|||
start(session)
|
||||
|
||||
# The script only uses the standard library => Nothing to install
|
||||
session.run('python', 'scripts/get_update_info_for_dependencies.py')
|
||||
session.run("python", "scripts/get_update_info_for_dependencies.py")
|
||||
|
||||
|
||||
@nox.session(name='init-project', python=MAIN_PYTHON, venv_backend='none')
|
||||
@nox.session(name="init-project", python=MAIN_PYTHON, venv_backend="none")
|
||||
def initialize_project(session: Session) -> None:
|
||||
"""Install the `pre-commit` hooks."""
|
||||
# .pre-commit-config.yaml sets the hook types via "default_install_hook_types"
|
||||
session.run('uv', 'run', 'pre-commit', 'install')
|
||||
session.run("uv", "run", "pre-commit", "install")
|
||||
|
||||
|
||||
@nox.session(name='clean-cwd', python=MAIN_PYTHON, venv_backend='none')
|
||||
@nox.session(name="clean-cwd", python=MAIN_PYTHON, venv_backend="none")
|
||||
def clean_cwd(session: Session) -> None:
|
||||
"""Remove (almost) all glob patterns listed in git's ignore file.
|
||||
|
||||
|
|
@ -468,19 +468,19 @@ def clean_cwd(session: Session) -> None:
|
|||
do_not_accept_arguments(session)
|
||||
|
||||
do_not_remove = {
|
||||
'.env',
|
||||
'.envrc',
|
||||
'.python-version',
|
||||
'.venv',
|
||||
".env",
|
||||
".envrc",
|
||||
".python-version",
|
||||
".venv",
|
||||
}
|
||||
|
||||
with pathlib.Path('.gitignore').open() as fp:
|
||||
with pathlib.Path(".gitignore").open() as fp:
|
||||
ignored_patterns = {
|
||||
pattern for pattern in fp if pattern and not pattern.startswith(('#', '!'))
|
||||
pattern for pattern in fp if pattern and not pattern.startswith(("#", "!"))
|
||||
}
|
||||
|
||||
with pathlib.Path('.gitignore').open() as fp:
|
||||
excluded_patterns = {pattern[1:] for pattern in fp if pattern.startswith('!')}
|
||||
with pathlib.Path(".gitignore").open() as fp:
|
||||
excluded_patterns = {pattern[1:] for pattern in fp if pattern.startswith("!")}
|
||||
|
||||
# Paths are resolved into absolute ones to avoid accidental matches
|
||||
excluded_paths = {
|
||||
|
|
@ -488,12 +488,12 @@ def clean_cwd(session: Session) -> None:
|
|||
for path in do_not_remove | set(_expand(*excluded_patterns))
|
||||
}
|
||||
|
||||
for path in itertools.chain([pathlib.Path('.cache')], _expand(*ignored_patterns)):
|
||||
for path in itertools.chain([pathlib.Path(".cache")], _expand(*ignored_patterns)):
|
||||
# The `path` must not be a sub-path of an `excluded_path`
|
||||
if {path, *path.parents} & excluded_paths:
|
||||
continue
|
||||
|
||||
session.run('rm', '-rf', path)
|
||||
session.run("rm", "-rf", path)
|
||||
|
||||
|
||||
def _expand(*patterns: str) -> Generator[pathlib.Path, None, None]:
|
||||
|
|
@ -521,9 +521,9 @@ def do_not_accept_arguments(session: Session, *, raise_error: bool = True) -> No
|
|||
msg = 'be run without any positional arguments behind the "--"'
|
||||
|
||||
if raise_error:
|
||||
session.error(f'Must {msg}')
|
||||
session.error(f"Must {msg}")
|
||||
else:
|
||||
session.warn(f'Should {msg}')
|
||||
session.warn(f"Should {msg}")
|
||||
|
||||
|
||||
def do_not_reuse(session: Session, *, raise_error: bool = True) -> None:
|
||||
|
|
@ -532,38 +532,38 @@ def do_not_reuse(session: Session, *, raise_error: bool = True) -> None:
|
|||
msg = 'be run without the "-r" and "-R" flags'
|
||||
|
||||
if raise_error:
|
||||
session.error(f'Must {msg}')
|
||||
session.error(f"Must {msg}")
|
||||
else:
|
||||
session.warn(f'Should {msg}')
|
||||
session.warn(f"Should {msg}")
|
||||
|
||||
|
||||
def start(session: Session) -> None:
|
||||
"""Show generic info about a session."""
|
||||
if session.posargs:
|
||||
session.debug(f'Received extra arguments: {session.posargs}')
|
||||
session.debug(f"Received extra arguments: {session.posargs}")
|
||||
|
||||
session.debug('Some generic information about the environment')
|
||||
session.debug("Some generic information about the environment")
|
||||
|
||||
session.run('python', '--version')
|
||||
session.run('python', '-c', 'import sys; print(sys.executable)')
|
||||
session.run('python', '-c', 'import sys; print(sys.path)')
|
||||
session.run('python', '-c', 'import os; print(os.getcwd())')
|
||||
session.run('python', '-c', 'import os; print(os.environ["PATH"])')
|
||||
session.run("python", "--version")
|
||||
session.run("python", "-c", "import sys; print(sys.executable)")
|
||||
session.run("python", "-c", "import sys; print(sys.path)")
|
||||
session.run("python", "-c", "import os; print(os.getcwd())")
|
||||
session.run("python", "-c", 'import os; print(os.environ["PATH"])')
|
||||
|
||||
session.env['BLACK_CACHE_DIR'] = '.cache/black'
|
||||
session.env["BLACK_CACHE_DIR"] = ".cache/black"
|
||||
|
||||
session.run(
|
||||
'mkdir',
|
||||
'-p',
|
||||
"mkdir",
|
||||
"-p",
|
||||
*(
|
||||
f'.cache/{dir_}'
|
||||
f".cache/{dir_}"
|
||||
for dir_ in (
|
||||
'black',
|
||||
'coverage',
|
||||
'mypy',
|
||||
'nox',
|
||||
'pytest',
|
||||
'tmp',
|
||||
"black",
|
||||
"coverage",
|
||||
"mypy",
|
||||
"nox",
|
||||
"pytest",
|
||||
"tmp",
|
||||
)
|
||||
),
|
||||
external=True,
|
||||
|
|
@ -590,20 +590,20 @@ def install_pinned(
|
|||
if skip_install(session):
|
||||
return
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix='.txt') as constraints_txt:
|
||||
with tempfile.NamedTemporaryFile(suffix=".txt") as constraints_txt:
|
||||
session.run(
|
||||
'uv',
|
||||
'export',
|
||||
'--all-extras',
|
||||
'--all-groups',
|
||||
'--locked',
|
||||
'--no-emit-project',
|
||||
'--no-hashes',
|
||||
'--quiet',
|
||||
f'--output-file={constraints_txt.name}',
|
||||
"uv",
|
||||
"export",
|
||||
"--all-extras",
|
||||
"--all-groups",
|
||||
"--locked",
|
||||
"--no-emit-project",
|
||||
"--no-hashes",
|
||||
"--quiet",
|
||||
f"--output-file={constraints_txt.name}",
|
||||
)
|
||||
session.install(
|
||||
f'--constraint={constraints_txt.name}',
|
||||
f"--constraint={constraints_txt.name}",
|
||||
*packages_or_pip_args,
|
||||
**kwargs,
|
||||
)
|
||||
|
|
@ -623,5 +623,5 @@ def skip_install(session: Session) -> bool:
|
|||
|
||||
|
||||
if MAIN_PYTHON not in SUPPORTED_PYTHONS:
|
||||
msg = f'MAIN_PYTHON version, v{MAIN_PYTHON}, is not in SUPPORTED_PYTHONS'
|
||||
msg = f"MAIN_PYTHON version, v{MAIN_PYTHON}, is not in SUPPORTED_PYTHONS"
|
||||
raise RuntimeError(msg)
|
||||
|
|
|
|||
|
|
@ -141,8 +141,6 @@ target-version = ["py313"]
|
|||
|
||||
line-length = 88
|
||||
|
||||
skip-string-normalization = true # `wemake-python-styleguide` enforces single quotes
|
||||
|
||||
|
||||
|
||||
[tool.coverage]
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ try:
|
|||
_pkg_info = _metadata.metadata(__name__)
|
||||
|
||||
except _metadata.PackageNotFoundError: # pragma: no cover
|
||||
__author__ = 'unknown'
|
||||
__pkg_name__ = 'unknown'
|
||||
__version__ = 'unknown'
|
||||
__author__ = "unknown"
|
||||
__pkg_name__ = "unknown"
|
||||
__version__ = "unknown"
|
||||
|
||||
else:
|
||||
__author__ = _pkg_info['author']
|
||||
__pkg_name__ = _pkg_info['name']
|
||||
__version__ = _pkg_info['version']
|
||||
__author__ = _pkg_info["author"]
|
||||
__pkg_name__ = _pkg_info["name"]
|
||||
__version__ = _pkg_info["version"]
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ import warnings
|
|||
|
||||
def random_schema_name() -> str:
|
||||
"""Generate a random PostgreSQL schema name for testing."""
|
||||
return 'temp_{name}'.format(
|
||||
name=''.join(
|
||||
return "temp_{name}".format(
|
||||
name="".join(
|
||||
(random.choice(string.ascii_lowercase) for _ in range(10)), # noqa:S311
|
||||
),
|
||||
)
|
||||
|
|
@ -54,33 +54,33 @@ class Config:
|
|||
TRAIN_HORIZONS = [7, 8]
|
||||
|
||||
# The demand forecasting methods used in the simulations.
|
||||
FORECASTING_METHODS = ['hets', 'rtarima']
|
||||
FORECASTING_METHODS = ["hets", "rtarima"]
|
||||
|
||||
# Colors for the visualizations ins `folium`.
|
||||
RESTAURANT_COLOR = 'red'
|
||||
CUSTOMER_COLOR = 'blue'
|
||||
NEUTRAL_COLOR = 'black'
|
||||
RESTAURANT_COLOR = "red"
|
||||
CUSTOMER_COLOR = "blue"
|
||||
NEUTRAL_COLOR = "black"
|
||||
|
||||
# Implementation-specific settings
|
||||
# --------------------------------
|
||||
|
||||
DATABASE_URI = os.getenv('DATABASE_URI')
|
||||
GOOGLE_MAPS_API_KEY = os.getenv('GOOGLE_MAPS_API_KEY')
|
||||
DATABASE_URI = os.getenv("DATABASE_URI")
|
||||
GOOGLE_MAPS_API_KEY = os.getenv("GOOGLE_MAPS_API_KEY")
|
||||
|
||||
# The PostgreSQL schema that holds the tables with the original data.
|
||||
ORIGINAL_SCHEMA = os.getenv('ORIGINAL_SCHEMA') or 'public'
|
||||
ORIGINAL_SCHEMA = os.getenv("ORIGINAL_SCHEMA") or "public"
|
||||
|
||||
# The PostgreSQL schema that holds the tables with the cleaned data.
|
||||
CLEAN_SCHEMA = os.getenv('CLEAN_SCHEMA') or 'clean'
|
||||
CLEAN_SCHEMA = os.getenv("CLEAN_SCHEMA") or "clean"
|
||||
|
||||
ALEMBIC_TABLE = 'alembic_version'
|
||||
ALEMBIC_TABLE_SCHEMA = 'public'
|
||||
ALEMBIC_TABLE = "alembic_version"
|
||||
ALEMBIC_TABLE_SCHEMA = "public"
|
||||
|
||||
R_LIBS_PATH = os.getenv('R_LIBS')
|
||||
R_LIBS_PATH = os.getenv("R_LIBS")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""Non-literal text representation."""
|
||||
return '<configuration>'
|
||||
return "<configuration>"
|
||||
|
||||
|
||||
class ProductionConfig(Config):
|
||||
|
|
@ -94,11 +94,11 @@ class TestingConfig(Config):
|
|||
|
||||
TESTING = True
|
||||
|
||||
DATABASE_URI = os.getenv('DATABASE_URI_TESTING') or Config.DATABASE_URI
|
||||
CLEAN_SCHEMA = os.getenv('CLEAN_SCHEMA_TESTING') or random_schema_name()
|
||||
DATABASE_URI = os.getenv("DATABASE_URI_TESTING") or Config.DATABASE_URI
|
||||
CLEAN_SCHEMA = os.getenv("CLEAN_SCHEMA_TESTING") or random_schema_name()
|
||||
|
||||
|
||||
def make_config(env: str = 'production') -> Config:
|
||||
def make_config(env: str = "production") -> Config:
|
||||
"""Create a new `Config` object.
|
||||
|
||||
Args:
|
||||
|
|
@ -112,9 +112,9 @@ def make_config(env: str = 'production') -> Config:
|
|||
""" # noqa:DAR203
|
||||
config: Config # otherwise mypy is confused
|
||||
|
||||
if env.strip().lower() == 'production':
|
||||
if env.strip().lower() == "production":
|
||||
config = ProductionConfig()
|
||||
elif env.strip().lower() == 'testing':
|
||||
elif env.strip().lower() == "testing":
|
||||
config = TestingConfig()
|
||||
else:
|
||||
raise ValueError("Must be either 'production' or 'testing'")
|
||||
|
|
@ -123,22 +123,22 @@ def make_config(env: str = 'production') -> Config:
|
|||
# As pytest sets the "TESTING" environment variable explicitly,
|
||||
# the warning is only emitted if the code is not run by pytest.
|
||||
# We see the bad configuration immediately as all "db" tests fail.
|
||||
if config.DATABASE_URI is None and not os.getenv('TESTING'):
|
||||
if config.DATABASE_URI is None and not os.getenv("TESTING"):
|
||||
warnings.warn(
|
||||
'Bad configuration: no DATABASE_URI set in the environment',
|
||||
"Bad configuration: no DATABASE_URI set in the environment",
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
# Some functionalities require R and some packages installed.
|
||||
# To ensure isolation and reproducibility, the projects keeps the R dependencies
|
||||
# in a project-local folder that must be set in the environment.
|
||||
if config.R_LIBS_PATH is None and not os.getenv('TESTING'):
|
||||
if config.R_LIBS_PATH is None and not os.getenv("TESTING"):
|
||||
warnings.warn(
|
||||
'Bad configuration: no R_LIBS set in the environment',
|
||||
"Bad configuration: no R_LIBS set in the environment",
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
config = make_config('testing' if os.getenv('TESTING') else 'production')
|
||||
config = make_config("testing" if os.getenv("TESTING") else "production")
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ from velofy.console import main
|
|||
|
||||
cli = main.entry_point
|
||||
|
||||
cli.add_command(forecasts.tactical_heuristic, name='tactical-forecasts')
|
||||
cli.add_command(forecasts.tactical_heuristic, name="tactical-forecasts")
|
||||
cli.add_command(gridify.gridify)
|
||||
|
|
|
|||
|
|
@ -18,17 +18,17 @@ def db_revision(
|
|||
@functools.wraps(func)
|
||||
def ensure(*args: Any, **kwargs: Any) -> Any:
|
||||
"""Do not execute the `func` if the revision does not match."""
|
||||
if not os.getenv('TESTING'):
|
||||
if not os.getenv("TESTING"):
|
||||
result = subprocess.run( # noqa:S603,S607
|
||||
['alembic', 'current'],
|
||||
["alembic", "current"],
|
||||
capture_output=True,
|
||||
check=False,
|
||||
encoding='utf8',
|
||||
encoding="utf8",
|
||||
)
|
||||
|
||||
if not result.stdout.startswith(rev):
|
||||
click.echo(
|
||||
click.style(f'Database is not at revision {rev}', fg='red'),
|
||||
click.style(f"Database is not at revision {rev}", fg="red"),
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ from velofy.forecasts import timify
|
|||
|
||||
|
||||
@click.command()
|
||||
@click.argument('city', default='Paris', type=str)
|
||||
@click.argument('side_length', default=1000, type=int)
|
||||
@click.argument('time_step', default=60, type=int)
|
||||
@click.argument('train_horizon', default=8, type=int)
|
||||
@decorators.db_revision('8bfb928a31f8')
|
||||
@click.argument("city", default="Paris", type=str)
|
||||
@click.argument("side_length", default=1000, type=int)
|
||||
@click.argument("time_step", default=60, type=int)
|
||||
@click.argument("train_horizon", default=8, type=int)
|
||||
@decorators.db_revision("8bfb928a31f8")
|
||||
def tactical_heuristic( # noqa:C901
|
||||
city: str,
|
||||
side_length: int,
|
||||
|
|
@ -77,21 +77,21 @@ def tactical_heuristic( # noqa:C901
|
|||
if grid.side_length == side_length:
|
||||
break
|
||||
else:
|
||||
click.echo(f'SIDE_LENGTH must be in {config.GRID_SIDE_LENGTHS}')
|
||||
click.echo(f"SIDE_LENGTH must be in {config.GRID_SIDE_LENGTHS}")
|
||||
sys.exit(1)
|
||||
|
||||
if time_step not in config.TIME_STEPS:
|
||||
click.echo(f'TIME_STEP must be in {config.TIME_STEPS}')
|
||||
click.echo(f"TIME_STEP must be in {config.TIME_STEPS}")
|
||||
sys.exit(1)
|
||||
|
||||
if train_horizon not in config.TRAIN_HORIZONS:
|
||||
click.echo(f'TRAIN_HORIZON must be in {config.TRAIN_HORIZONS}')
|
||||
click.echo(f"TRAIN_HORIZON must be in {config.TRAIN_HORIZONS}")
|
||||
sys.exit(1)
|
||||
|
||||
click.echo(
|
||||
'Parameters: '
|
||||
+ f'city={city}, grid.side_length={side_length}, '
|
||||
+ f'time_step={time_step}, train_horizon={train_horizon}',
|
||||
"Parameters: "
|
||||
+ f"city={city}, grid.side_length={side_length}, "
|
||||
+ f"time_step={time_step}, train_horizon={train_horizon}",
|
||||
)
|
||||
|
||||
# Load the historic order data.
|
||||
|
|
@ -131,8 +131,8 @@ def tactical_heuristic( # noqa:C901
|
|||
train_horizon=train_horizon,
|
||||
)
|
||||
click.echo(
|
||||
f'Predicting pixel #{pixel.id} in {city} '
|
||||
+ f'for {predict_day} with {model.name}',
|
||||
f"Predicting pixel #{pixel.id} in {city} "
|
||||
+ f"for {predict_day} with {model.name}",
|
||||
)
|
||||
|
||||
# Only loop over the time steps corresponding to working hours.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from velofy.console import decorators
|
|||
|
||||
|
||||
@click.command()
|
||||
@decorators.db_revision('e86290e7305e')
|
||||
@decorators.db_revision("e86290e7305e")
|
||||
def gridify() -> None: # pragma: no cover note:b1f68d24
|
||||
"""Create grids for all cities.
|
||||
|
||||
|
|
@ -21,18 +21,18 @@ def gridify() -> None: # pragma: no cover note:b1f68d24
|
|||
All data are persisted to the database.
|
||||
"""
|
||||
cities = db.session.query(db.City).all()
|
||||
click.echo(f'{len(cities)} cities retrieved from the database')
|
||||
click.echo(f"{len(cities)} cities retrieved from the database")
|
||||
|
||||
for city in cities:
|
||||
click.echo(f'\nCreating grids for {city.name}')
|
||||
click.echo(f"\nCreating grids for {city.name}")
|
||||
|
||||
for side_length in config.GRID_SIDE_LENGTHS:
|
||||
click.echo(f'Creating grid with a side length of {side_length} meters')
|
||||
click.echo(f"Creating grid with a side length of {side_length} meters")
|
||||
|
||||
grid = db.Grid.gridify(city=city, side_length=side_length)
|
||||
db.session.add(grid)
|
||||
|
||||
click.echo(f' -> created {len(grid.pixels)} pixels')
|
||||
click.echo(f" -> created {len(grid.pixels)} pixels")
|
||||
|
||||
# Because the number of assigned addresses is the same across
|
||||
# different `side_length`s, we can take any `grid` from the `city`.
|
||||
|
|
@ -43,7 +43,7 @@ def gridify() -> None: # pragma: no cover note:b1f68d24
|
|||
.count()
|
||||
)
|
||||
click.echo(
|
||||
f'=> assigned {n_assigned} out of {len(city.addresses)} addresses in {city.name}', # noqa:E501
|
||||
f"=> assigned {n_assigned} out of {len(city.addresses)} addresses in {city.name}", # noqa:E501
|
||||
)
|
||||
|
||||
db.session.commit()
|
||||
|
|
|
|||
|
|
@ -16,18 +16,18 @@ def show_version(ctx: cli_core.Context, _param: Any, value: bool) -> None:
|
|||
return
|
||||
|
||||
# Mimic the colors of `poetry version`.
|
||||
pkg_name = click.style(velofy.__pkg_name__, fg='green')
|
||||
version = click.style(velofy.__version__, fg='blue')
|
||||
pkg_name = click.style(velofy.__pkg_name__, fg="green")
|
||||
version = click.style(velofy.__version__, fg="blue")
|
||||
# Include a warning for development versions.
|
||||
warning = click.style(' (development)', fg='red') if '.dev' in version else ''
|
||||
click.echo(f'{pkg_name}, version {version}{warning}')
|
||||
warning = click.style(" (development)", fg="red") if ".dev" in version else ""
|
||||
click.echo(f"{pkg_name}, version {version}{warning}")
|
||||
ctx.exit()
|
||||
|
||||
|
||||
@click.group()
|
||||
@click.option(
|
||||
'--version',
|
||||
'-V',
|
||||
"--version",
|
||||
"-V",
|
||||
is_flag=True,
|
||||
callback=show_version,
|
||||
is_eager=True,
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue