Remove all "WPS" codes

This commit is contained in:
Alexander Hess 2026-11-28 02:01:12 +01:00
commit 9fcb3c8c14
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
52 changed files with 171 additions and 254 deletions

View file

@ -21,9 +21,9 @@ 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 ( # noqa:WPS337
if (
type_ in {'table', 'column'}
and hasattr(obj, 'schema') # noqa:WPS421 => fix for rare edge case
and hasattr(obj, 'schema') # => fix for rare edge case
and obj.schema != velofy_config.CLEAN_SCHEMA
):
return False

View file

@ -38,7 +38,7 @@ def upgrade():
sa.Column('initial_zoom', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_cities')),
*(
[ # noqa:WPS504
[
sa.ForeignKeyConstraint(
['id'],
[f'{config.ORIGINAL_SCHEMA}.cities.id'],
@ -83,7 +83,7 @@ def upgrade():
),
sa.PrimaryKeyConstraint('id', name=op.f('pk_couriers')),
*(
[ # noqa:WPS504
[
sa.ForeignKeyConstraint(
['id'],
[f'{config.ORIGINAL_SCHEMA}.couriers.id'],
@ -148,7 +148,7 @@ def upgrade():
),
sa.PrimaryKeyConstraint('id', name=op.f('pk_addresses')),
*(
[ # noqa:WPS504
[
sa.ForeignKeyConstraint(
['id'],
[f'{config.ORIGINAL_SCHEMA}.addresses.id'],
@ -210,7 +210,7 @@ def upgrade():
),
sa.PrimaryKeyConstraint('id', name=op.f('pk_restaurants')),
*(
[ # noqa:WPS504
[
sa.ForeignKeyConstraint(
['id'],
[f'{config.ORIGINAL_SCHEMA}.businesses.id'],
@ -628,7 +628,7 @@ def upgrade():
),
sa.PrimaryKeyConstraint('id', name=op.f('pk_orders')),
*(
[ # noqa:WPS504
[
sa.ForeignKeyConstraint(
['id'],
[f'{config.ORIGINAL_SCHEMA}.orders.id'],

View file

@ -31,7 +31,7 @@ def upgrade():
TO
train_horizon;
""",
) # noqa:WPS355
)
def downgrade():
@ -45,4 +45,4 @@ def downgrade():
TO
training_horizon;
""",
) # noqa:WPS355
)

View file

@ -29,7 +29,7 @@ def upgrade():
ALTER TABLE {config.CLEAN_SCHEMA}.orders
DROP CONSTRAINT ck_orders_on_ordered_timestamps_21;
""",
) # noqa:WPS355
)
# Add forgotten check constraints to the `orders` table.
op.execute(
@ -38,7 +38,7 @@ def upgrade():
ADD CONSTRAINT check_orders_on_ordered_timestamps_placed_at_before_pickup_at
CHECK (placed_at < pickup_at);
""",
) # noqa:WPS355
)
op.execute(
f"""
ALTER TABLE {config.CLEAN_SCHEMA}.orders
@ -55,7 +55,7 @@ def upgrade():
)
);
""",
) # noqa:WPS355
)
# This `UniqueConstraint` is needed by the `replayed_orders` table below.
op.create_unique_constraint(
@ -403,17 +403,17 @@ def downgrade():
ALTER TABLE {config.CLEAN_SCHEMA}.orders
DROP CONSTRAINT check_orders_on_scheduled_orders_must_be_at_quarters_of_an_hour;
""",
) # noqa:WPS355
)
op.execute(
f"""
ALTER TABLE {config.CLEAN_SCHEMA}.orders
DROP CONSTRAINT check_orders_on_ordered_timestamps_placed_at_before_pickup_at;
""",
) # noqa:WPS355
)
op.execute(
f"""
ALTER TABLE {config.CLEAN_SCHEMA}.orders
ADD CONSTRAINT ck_orders_on_ordered_timestamps_21
CHECK (cancelled_at > delivery_at);
""",
) # noqa:WPS355
)

View file

@ -293,7 +293,7 @@ def build_docs(session: Session) -> None:
# Verify that all external links return 200 OK
session.run('sphinx-build', '-b', 'linkcheck', DOCS_LOCATION, DOCS_BUILD)
print(f'Docs are available at {os.getcwd()}/{DOCS_BUILD}index.html') # noqa:WPS421
print(f'Docs are available at {os.getcwd()}/{DOCS_BUILD}index.html')
@nox.session(name='venv', python=MAIN_PYTHON, venv_backend='none')

View file

@ -187,7 +187,6 @@ select = [
# wemake-python-styleguide
# Source: https://wemake-python-stylegui.de/en/latest/pages/usage/violations/index.html
# ========================
"WPS1", "WPS2", "WPS3", "WPS4", "WPS5", "WPS6",
# darglint => docstring matches implementation
"DAR0", "DAR1", "DAR2", "DAR3", "DAR4", "DAR5",
# flake8-bandit => common security issues
@ -234,96 +233,36 @@ ignore = []
# If --ignore is passed on the command
# line, still ignore the following:
extend-ignore = [
# TODO: New in `wemake-python-styleguide` v0.15 - v0.17, revisit in the tooling goal
"WPS110",
"WPS237",
"WPS238",
"WPS358",
"WPS456",
"WPS458",
"WPS459",
"WPS462",
"WPS469",
# Too long line => duplicate with E501.
"B950",
# Comply with black's style.
# Source: https://github.com/psf/black/blob/master/docs/compatible_configs.md#flake8
"E203", "W503", "WPS348",
"E203", "W503",
# Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`.
"PT023",
# Google's Python Style Guide is not reStructuredText
# until after being processed by Sphinx Napoleon.
# Source: https://github.com/peterjc/flake8-rst-docstrings/issues/17
"RST201", "RST203", "RST210", "RST213", "RST301",
# The "too deep nesting" violation fires off "too early" and cannot be configured.
"WPS220",
# String constant over-use is checked visually by the programmer.
"WPS226",
# Function complexity is checked by `mccabe` (=C901),
# which yields the same result in most cases.
"WPS231",
# Modules as a whole are assumed to be not "too complex".
"WPS232",
# Allow underscores in numbers.
"WPS303",
# f-strings are ok.
"WPS305",
# Classes should not have to specify a base class.
"WPS306",
# Let's be modern: The Walrus is ok.
"WPS332",
# Let's not worry about the number of noqa's.
# Multi-line loops are ok.
"WPS352",
"WPS402",
# Putting logic into __init__.py files may be justified.
"WPS412",
# Allow multiple assignment, e.g., x = y = 123
"WPS429",
# There are no magic numbers.
"WPS432",
]
per-file-ignores = [
# Top-levels of a sub-packages are intended to import a lot.
"**/__init__.py:F401,WPS201",
# Allow shadowing built-ins and reading __*__ variables.
"docs/conf.py:WPS125,WPS609",
"**/__init__.py:F401",
# Type annotations are not strictly enforced.
"migrations/env.py:ANN0,ANN2",
# - ANN0, ANN2 => Type annotations are not strictly enforced.
# - S608 => Do not worry about SQL injection here.
# - WPS114, WPS118 => File names of revisions are ok.
# - WPS204, WPS213 => Revisions may have too many expressions.
"migrations/versions/*.py:ANN0,ANN2,S608,WPS114,WPS118,WPS204,WPS213",
# - ANN0, ANN2 => Type annotations are not strictly enforced.
# - WPS202 => TODO (isort): Check if still too many module members.
# - WPS213 => TODO (isort): Remove after simplifying the nox session "lint".
"noxfile.py:ANN0,ANN2,WPS202,WPS213",
# Allow upper case class variables within classes.
"src/velofy/configuration.py:WPS115",
# The module does not have too many imports.
"src/velofy/db/addresses_addresses.py:WPS201",
# The many noqa's are ok.
"src/velofy/forecasts/models/tactical/horizontal.py:WPS403",
# - S608 => No SQL injection as the inputs come from a safe source.
# - WPS403 => The many noqa's are ok.
"src/velofy/forecasts/timify.py:S608,WPS403",
"migrations/versions/*.py:ANN0,ANN2,S608",
# Type annotations are not strictly enforced.
"noxfile.py:ANN0,ANN2",
# No SQL injection as the inputs come from a safe source.
"src/velofy/forecasts/timify.py:S608",
# - ANN0, ANN2 => Type annotations are not strictly enforced.
# - D106 => The `Meta` class inside the factory_boy models do not need a docstring.
# - S101 => `assert` statements are ok in the test suite.
# - S311 => The `random` module is not used for cryptography.
# - WPS442 => Shadowing outer scopes occurs naturally with mocks.
# - WPS100 => `utils` should be a valid module name.
# - WPS118 => Test names may be longer than 40 characters.
# - WPS202, WPS204, WPS214 => Modules may have many test cases.
# - WPS221 => Do not check for Jones complexity in the test suite.
# - WPS338 => "Private" methods are really just a convention for
# fixtures without a return value.
# - WPS402 => We do not care about the number of "# noqa"s in the test suite.
# - WPS430 => Allow closures.
# - WPS437 => When testing, it is normal to use implementation details.
"tests/*.py:ANN0,ANN2,D106,S101,S311,WPS442,WPS100,WPS118,WPS202,WPS204,WPS214,WPS221,WPS338,WPS402,WPS430,WPS437",
"tests/*.py:ANN0,ANN2,D106,S101,S311",
]
# Explicitly set mccabe's maximum complexity to 10 as recommended by
@ -331,12 +270,6 @@ per-file-ignores = [
# Source: https://en.wikipedia.org/wiki/Cyclomatic_complexity#Limiting_complexity_during_development
max-complexity = 10
# Allow more than wemake-python-styleguide's 5 local variables per function.
max-local-variables = 8
# Allow more than wemake-python-styleguide's 7 methods per class.
max-methods = 15
# Comply with black's style.
# Source: https://github.com/psf/black/blob/master/docs/the_black_code_style.md#line-length
max-line-length = 88
@ -344,18 +277,6 @@ max-line-length = 88
# Preview the code lines that cause errors.
show-source = true
# ===================================
# wemake-python-styleguide's settings
# ===================================
allowed-domain-names = [
"data",
"obj",
"param",
"result",
"results",
"value",
]
max-name-length = 40
# darglint
strictness = "long"
# flake8-docstrings

View file

@ -16,7 +16,7 @@ def db_revision(
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
@functools.wraps(func)
def ensure(*args: Any, **kwargs: Any) -> Any: # noqa:WPS430
def ensure(*args: Any, **kwargs: Any) -> Any:
"""Do not execute the `func` if the revision does not match."""
if not os.getenv('TESTING'):
result = subprocess.run( # noqa:S603,S607

View file

@ -24,7 +24,7 @@ from velofy.forecasts import timify
@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,WPS213,WPS216
def tactical_heuristic( # noqa:C901
city: str,
side_length: int,
time_step: int,
@ -68,9 +68,7 @@ def tactical_heuristic( # noqa:C901,WPS213,WPS216
# Input validation.
try:
city_obj = (
db.session.query(db.City).filter_by(name=city.title()).one() # noqa:WPS221
)
city_obj = db.session.query(db.City).filter_by(name=city.title()).one()
except orm_exc.NoResultFound:
click.echo('NAME must be one of "Paris", "Lyon", or "Bordeaux"')
sys.exit(1)
@ -97,17 +95,17 @@ def tactical_heuristic( # noqa:C901,WPS213,WPS216
)
# Load the historic order data.
order_history = timify.OrderHistory(grid=grid, time_step=time_step) # noqa:WPS441
order_history = timify.OrderHistory(grid=grid, time_step=time_step)
order_history.aggregate_orders()
# Run the tactical heuristic.
for pixel in grid.pixels: # noqa:WPS441
for pixel in grid.pixels:
# Important: this check may need to be adapted once further
# commands are added the make `Forecast`s without the heuristic!
# Continue with forecasting on the day the last prediction was made ...
last_predict_at = (
db.session.query(func.max(db.Forecast.start_at)) # noqa:WPS221
db.session.query(func.max(db.Forecast.start_at))
.join(db.Pixel, db.Forecast.pixel_id == db.Pixel.id)
.join(db.Grid, db.Pixel.grid_id == db.Grid.id)
.filter(db.Forecast.pixel == pixel)

View file

@ -16,8 +16,8 @@ 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') # noqa:WPS609
version = click.style(velofy.__version__, fg='blue') # noqa:WPS609
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}')

View file

@ -22,7 +22,7 @@ class Address(meta.Base):
__tablename__ = 'addresses'
# Columns
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False) # noqa:WPS125
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
primary_id = sa.Column(sa.Integer, nullable=False, index=True)
created_at = sa.Column(sa.DateTime, nullable=False)
place_id = sa.Column(sa.Unicode(length=120), nullable=False, index=True)
@ -116,7 +116,7 @@ class Address(meta.Base):
return location
@property
def x(self) -> int: # noqa=WPS111
def x(self) -> int:
"""The relative x-coordinate within the `.city` in meters.
On the implied x-y plane, the `.city`'s southwest corner is the origin.
@ -126,7 +126,7 @@ class Address(meta.Base):
return self.location.x
@property
def y(self) -> int: # noqa=WPS111
def y(self) -> int:
"""The relative y-coordinate within the `.city` in meters.
On the implied x-y plane, the `.city`'s southwest corner is the origin.
@ -145,7 +145,7 @@ class Address(meta.Base):
return self
@property # pragma: no cover
def map(self) -> folium.Map: # noqa:WPS125
def map(self) -> folium.Map:
"""Shortcut to the `.city.map` object."""
return self.city.map

View file

@ -128,9 +128,7 @@ class Path(meta.Base):
# We consider all 2-tuples of `Address`es. The symmetric graph is ...
for first, second in itertools.combinations(addresses, 2):
# ... implicitly enforced by a precedence constraint for the `.id`s.
first, second = ( # noqa:WPS211
(first, second) if first.id < second.id else (second, first)
)
first, second = (first, second) if first.id < second.id else (second, first)
# If there is no `Path` object in the database ...
path = (
@ -158,7 +156,7 @@ class Path(meta.Base):
paths.append(path)
if google_maps:
for path in paths: # noqa:WPS440
for path in paths:
path.sync_with_google_maps()
return paths
@ -212,8 +210,8 @@ class Path(meta.Base):
# Source: https://developers.google.com/maps/documentation/directions/get-directions#Legs # noqa:E501
route = response[0]['legs'][0]
self.bicycle_distance = route['distance']['value'] # noqa:WPS601
self.bicycle_duration = route['duration']['value'] # noqa:WPS601
self.bicycle_distance = route['distance']['value']
self.bicycle_duration = route['duration']['value']
# Each route consists of many "steps" that are instructions as to how to
# get from A to B. As a step's "start_location" may equal the previous step's
@ -221,23 +219,23 @@ class Path(meta.Base):
# pairs that make up the path from `.first_address` to `.second_address`.
steps: ordered_set.OrderedSet[Tuple[float, float]] = ordered_set.OrderedSet()
for step in route['steps']:
steps.add( # noqa:WPS221
steps.add(
(step['start_location']['lat'], step['start_location']['lng']),
)
steps.add( # noqa:WPS221
steps.add(
(step['end_location']['lat'], step['end_location']['lng']),
)
steps.discard(self.first_address.location.lat_lng)
steps.discard(self.second_address.location.lat_lng)
self._directions = json.dumps(list(steps)) # noqa:WPS601
self._directions = json.dumps(list(steps))
db.session.add(self)
db.session.commit()
@property # pragma: no cover
def map(self) -> folium.Map: # noqa:WPS125
def map(self) -> folium.Map:
"""Convenience property to obtain the underlying `City.map`."""
return self.first_address.city.map
@ -256,7 +254,7 @@ class Path(meta.Base):
return points
def draw( # noqa:WPS211
def draw(
self,
*,
reverse: bool = False,

View file

@ -21,7 +21,7 @@ class City(meta.Base):
__tablename__ = 'cities'
# Generic columns
id = sa.Column( # noqa:WPS125
id = sa.Column(
sa.SmallInteger,
primary_key=True,
autoincrement=False,
@ -110,12 +110,12 @@ class City(meta.Base):
return self
@property # pragma: no cover
def map(self) -> folium.Map: # noqa:WPS125
def map(self) -> folium.Map:
"""A `folium.Map` object aligned with the city's viewport.
See docstring for `.clear_map()` for further info.
"""
if not hasattr(self, '_map'): # noqa:WPS421 note:d334120e
if not hasattr(self, '_map'): # note:d334120e
self.clear_map()
return self._map
@ -137,7 +137,7 @@ class City(meta.Base):
db.session.query(db.Address)
.filter(
db.Address.id.in_(
db.session.query(db.Address.primary_id) # noqa:WPS221
db.session.query(db.Address.primary_id)
.join(db.Restaurant, db.Address.id == db.Restaurant.address_id)
.filter(db.Address.city == self)
.distinct()
@ -157,9 +157,9 @@ class City(meta.Base):
.all()
)
if len(restaurants) == 1:
tooltip = f'{restaurants[0].name} (#{restaurants[0].id})' # noqa:WPS221
tooltip = f'{restaurants[0].name} (#{restaurants[0].id})'
else:
tooltip = 'Restaurants ' + ', '.join( # noqa:WPS336
tooltip = 'Restaurants ' + ', '.join(
f'#{restaurant.id}' for restaurant in restaurants
)
@ -183,7 +183,7 @@ class City(meta.Base):
else:
radius = 1
tooltip += f' | n_orders={n_orders}' # noqa:WPS336
tooltip += f' | n_orders={n_orders}'
address.draw(
radius=radius,
@ -239,7 +239,7 @@ class City(meta.Base):
if not address.is_primary:
continue
marker = folium.Circle( # noqa:WPS317
marker = folium.Circle(
(address.latitude, address.longitude),
color=colors[address.zip_code],
radius=1,

View file

@ -13,7 +13,7 @@ class Courier(meta.Base):
__tablename__ = 'couriers'
# Columns
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False) # noqa:WPS125
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
created_at = sa.Column(sa.DateTime, nullable=False)
vehicle = sa.Column(sa.Unicode(length=10), nullable=False)
historic_speed = sa.Column('speed', postgresql.DOUBLE_PRECISION, nullable=False)

View file

@ -17,7 +17,7 @@ class Customer(meta.Base):
__tablename__ = 'customers'
# Columns
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False) # noqa:WPS125
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
def __repr__(self) -> str:
"""Non-literal text representation."""
@ -35,15 +35,15 @@ class Customer(meta.Base):
Returns:
self: enabling method chaining
""" # noqa:D402,DAR203
self.orders[0].pickup_address.city.clear_map() # noqa:WPS219
self.orders[0].pickup_address.city.clear_map()
return self
@property # pragma: no cover
def map(self) -> folium.Map: # noqa:WPS125
def map(self) -> folium.Map:
"""Shortcut to the `...city.map` object."""
return self.orders[0].pickup_address.city.map # noqa:WPS219
return self.orders[0].pickup_address.city.map
def draw( # noqa:C901,WPS210
def draw( # noqa:C901
self,
restaurants: bool = True,
order_counts: bool = False, # pragma: no cover
@ -72,7 +72,7 @@ class Customer(meta.Base):
db.Address.id.in_(
row.primary_id
for row in (
db.session.query(db.Address.primary_id) # noqa:WPS221
db.session.query(db.Address.primary_id)
.join(db.Order, db.Address.id == db.Order.delivery_address_id)
.filter(db.Order.customer_id == self.id)
.distinct()
@ -122,7 +122,7 @@ class Customer(meta.Base):
db.session.query(db.Address)
.filter(
db.Address.id.in_(
db.session.query(db.Address.primary_id) # noqa:WPS221
db.session.query(db.Address.primary_id)
.join(db.Order, db.Address.id == db.Order.pickup_address_id)
.filter(db.Order.customer_id == self.id)
.distinct()
@ -132,14 +132,14 @@ class Customer(meta.Base):
.all()
)
for address in pickup_addresses: # noqa:WPS440
for address in pickup_addresses:
# Show the restaurant's name if there is only one.
# Otherwise, list all the restaurants' ID's.
# We cannot show the `Order.restaurant.name` due to the aggregation.
restaurants = (
db.session.query(db.Restaurant)
.join(db.Address, db.Restaurant.address_id == db.Address.id)
.filter(db.Address.primary_id == address.id) # noqa:WPS441
.filter(db.Address.primary_id == address.id)
.all()
)
if len(restaurants) == 1: # type:ignore
@ -147,7 +147,7 @@ class Customer(meta.Base):
f'{restaurants[0].name} (#{restaurants[0].id})' # type:ignore
)
else:
tooltip = 'Restaurants ' + ', '.join( # noqa:WPS336
tooltip = 'Restaurants ' + ', '.join(
f'#{restaurant.id}' for restaurant in restaurants # type:ignore
)
@ -156,7 +156,7 @@ class Customer(meta.Base):
db.session.query(db.Order)
.join(db.Address, db.Order.pickup_address_id == db.Address.id)
.filter(db.Order.customer_id == self.id)
.filter(db.Address.primary_id == address.id) # noqa:WPS441
.filter(db.Address.primary_id == address.id)
.count()
)
if n_orders >= 25:
@ -170,9 +170,9 @@ class Customer(meta.Base):
else:
radius = 1
tooltip += f' | n_orders={n_orders}' # noqa:WPS336
tooltip += f' | n_orders={n_orders}'
address.draw( # noqa:WPS441
address.draw(
radius=radius,
color=config.RESTAURANT_COLOR,
fill_color=config.RESTAURANT_COLOR,
@ -181,7 +181,7 @@ class Customer(meta.Base):
)
else:
address.draw( # noqa:WPS441
address.draw(
radius=1,
color=config.RESTAURANT_COLOR,
tooltip=tooltip,

View file

@ -23,7 +23,7 @@ class Forecast(meta.Base):
__tablename__ = 'forecasts'
# Columns
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) # noqa:WPS125
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
pixel_id = sa.Column(sa.Integer, nullable=False, index=True)
start_at = sa.Column(sa.DateTime, nullable=False)
time_step = sa.Column(sa.SmallInteger, nullable=False)
@ -151,7 +151,7 @@ class Forecast(meta.Base):
)
@classmethod
def from_dataframe( # noqa:WPS210,WPS211
def from_dataframe(
cls,
pixel: db.Pixel,
time_step: int,

View file

@ -22,7 +22,7 @@ class Grid(meta.Base):
__tablename__ = 'grids'
# Columns
id = sa.Column( # noqa:WPS125
id = sa.Column(
sa.SmallInteger,
primary_key=True,
autoincrement=True,
@ -63,7 +63,7 @@ class Grid(meta.Base):
return round((self.side_length**2) / 1_000_000, 1)
@classmethod
def gridify(cls, city: db.City, side_length: int) -> db.Grid: # noqa:WPS210
def gridify(cls, city: db.City, side_length: int) -> db.Grid:
"""Create a fully populated `Grid` for a `city`.
The `Grid` contains only `Pixel`s that have at least one
@ -124,7 +124,7 @@ class Grid(meta.Base):
return self
@property # pragma: no cover
def map(self) -> folium.Map: # noqa:WPS125
def map(self) -> folium.Map:
"""Shortcut to the `.city.map` object."""
return self.city.map

View file

@ -12,11 +12,11 @@ Base: Any = orm.declarative_base(
metadata=sa.MetaData(
schema=velofy.config.CLEAN_SCHEMA,
naming_convention={
'pk': 'pk_%(table_name)s', # noqa:WPS323
'fk': 'fk_%(table_name)s_to_%(referred_table_name)s_via_%(column_0_N_name)s', # noqa:E501,WPS323
'uq': 'uq_%(table_name)s_on_%(column_0_N_name)s', # noqa:WPS323
'ix': 'ix_%(table_name)s_on_%(column_0_N_name)s', # noqa:WPS323
'ck': 'ck_%(table_name)s_on_%(constraint_name)s', # noqa:WPS323
'pk': 'pk_%(table_name)s',
'fk': 'fk_%(table_name)s_to_%(referred_table_name)s_via_%(column_0_N_name)s', # noqa:E501
'uq': 'uq_%(table_name)s_on_%(column_0_N_name)s',
'ix': 'ix_%(table_name)s_on_%(column_0_N_name)s',
'ck': 'ck_%(table_name)s_on_%(constraint_name)s',
},
),
)

View file

@ -12,13 +12,13 @@ from velofy import db
from velofy.db import meta
class Order(meta.Base): # noqa:WPS214
class Order(meta.Base):
"""An order by a `Customer` of the UDP."""
__tablename__ = 'orders'
# Generic columns
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False) # noqa:WPS125
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
_delivery_id = sa.Column('delivery_id', sa.Integer, index=True, unique=True)
customer_id = sa.Column(sa.Integer, nullable=False, index=True)
placed_at = sa.Column(sa.DateTime, nullable=False, index=True)
@ -364,7 +364,7 @@ class Order(meta.Base): # noqa:WPS214
def corrected(self) -> bool:
"""If any timestamp was corrected as compared to the original data."""
return (
self.scheduled_delivery_at_corrected # noqa:WPS222 => too much logic
self.scheduled_delivery_at_corrected # => too much logic
or self.cancelled_at_corrected
or self.restaurant_notified_at_corrected
or self.restaurant_confirmed_at_corrected

View file

@ -28,7 +28,7 @@ class Pixel(meta.Base):
__tablename__ = 'pixels'
# Columns
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) # noqa:WPS125
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
grid_id = sa.Column(sa.SmallInteger, nullable=False, index=True)
n_x = sa.Column(sa.SmallInteger, nullable=False, index=True)
n_y = sa.Column(sa.SmallInteger, nullable=False, index=True)
@ -141,11 +141,11 @@ class Pixel(meta.Base):
return self
@property # pragma: no cover
def map(self) -> folium.Map: # noqa:WPS125
def map(self) -> folium.Map:
"""Shortcut to the `.city.map` object."""
return self.grid.city.map
def draw( # noqa:C901,WPS210
def draw( # noqa:C901
self,
restaurants: bool = True,
order_counts: bool = False, # pragma: no cover
@ -223,7 +223,7 @@ class Pixel(meta.Base):
f'{restaurants[0].name} (#{restaurants[0].id})' # type:ignore
)
else:
tooltip = 'Restaurants ' + ', '.join( # noqa:WPS336
tooltip = 'Restaurants ' + ', '.join(
f'#{restaurant.id}' for restaurant in restaurants # type:ignore
)
@ -247,7 +247,7 @@ class Pixel(meta.Base):
else:
radius = 1
tooltip += f' | n_orders={n_orders}' # noqa:WPS336
tooltip += f' | n_orders={n_orders}'
address.draw(
radius=radius,

View file

@ -15,7 +15,7 @@ class ReplaySimulation(meta.Base):
__tablename__ = 'replay_simulations'
# Columns
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) # noqa:WPS125
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
city_id = sa.Column(sa.SmallInteger, nullable=False, index=True)
strategy = sa.Column(sa.Unicode(length=100), nullable=False, index=True)
# `.run` may be used as random seed.

Some files were not shown because too many files have changed in this diff Show more