Unify the way the imports work #9
17 changed files with 113 additions and 103 deletions
Import velofy.config as pkg_config everywhere
commit
cf2534f41e
|
|
@ -6,7 +6,7 @@ from logging import config as log_config
|
|||
import sqlalchemy as sa
|
||||
from alembic import context
|
||||
|
||||
from velofy import config as velofy_config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ def include_object(obj, _name, type_, _reflected, _compare_to):
|
|||
if (
|
||||
type_ in {"table", "column"}
|
||||
and hasattr(obj, "schema") # => fix for rare edge case
|
||||
and obj.schema != velofy_config.CLEAN_SCHEMA
|
||||
and obj.schema != pkg_config.CLEAN_SCHEMA
|
||||
):
|
||||
return False
|
||||
|
||||
|
|
@ -32,17 +32,17 @@ def include_object(obj, _name, type_, _reflected, _compare_to):
|
|||
|
||||
|
||||
# Without a `pool`, the `connection` really closes after the migrations
|
||||
engine = sa.create_engine(velofy_config.DATABASE_URI, poolclass=sa.pool.NullPool)
|
||||
engine = sa.create_engine(pkg_config.DATABASE_URI, poolclass=sa.pool.NullPool)
|
||||
|
||||
test_schema = f"_{velofy_config.CLEAN_SCHEMA}" if os.getenv("TESTING") else ""
|
||||
test_schema = f"_{pkg_config.CLEAN_SCHEMA}" if os.getenv("TESTING") else ""
|
||||
|
||||
with engine.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection,
|
||||
include_object=include_object,
|
||||
target_metadata=db.Base.metadata,
|
||||
version_table=f"{velofy_config.ALEMBIC_TABLE}{test_schema}",
|
||||
version_table_schema=velofy_config.ALEMBIC_TABLE_SCHEMA,
|
||||
version_table=f"{pkg_config.ALEMBIC_TABLE}{test_schema}",
|
||||
version_table_schema=pkg_config.ALEMBIC_TABLE_SCHEMA,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
|
|
|
|||
|
|
@ -558,6 +558,7 @@ banned-from = [
|
|||
"sqlalchemy.ext.hybrid" = "sa_hybrid"
|
||||
"statsmodels.tsa.api" = "tsa"
|
||||
"typing" = "t"
|
||||
"velofy.config" = "pkg_config"
|
||||
|
||||
|
||||
[tool.ruff.lint.isort] # aligned with [tool.isort] above
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import click
|
|||
import sqlalchemy as sa
|
||||
from sqlalchemy.orm import exc as orm_exc
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.console import decorators
|
||||
from velofy.forecasts import timify
|
||||
|
|
@ -77,15 +77,15 @@ def tactical_heuristic( # noqa:C901,D417,DOC001
|
|||
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 {pkg_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}")
|
||||
if time_step not in pkg_config.TIME_STEPS:
|
||||
click.echo(f"TIME_STEP must be in {pkg_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}")
|
||||
if train_horizon not in pkg_config.TRAIN_HORIZONS:
|
||||
click.echo(f"TRAIN_HORIZON must be in {pkg_config.TRAIN_HORIZONS}")
|
||||
sys.exit(1)
|
||||
|
||||
click.echo(
|
||||
|
|
@ -140,9 +140,9 @@ def tactical_heuristic( # noqa:C901,D417,DOC001
|
|||
predict_day.year,
|
||||
predict_day.month,
|
||||
predict_day.day,
|
||||
config.SERVICE_START,
|
||||
pkg_config.SERVICE_START,
|
||||
)
|
||||
while predict_at.hour < config.SERVICE_END:
|
||||
while predict_at.hour < pkg_config.SERVICE_END:
|
||||
model.make_forecast(
|
||||
pixel=pixel,
|
||||
predict_at=predict_at,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import click
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.console import decorators
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ def gridify() -> None: # pragma: no cover note:b1f68d24
|
|||
for city in cities:
|
||||
click.echo(f"\nCreating grids for {city.name}")
|
||||
|
||||
for side_length in config.GRID_SIDE_LENGTHS:
|
||||
for side_length in pkg_config.GRID_SIDE_LENGTHS:
|
||||
click.echo(f"Creating grid with a side length of {side_length} meters")
|
||||
|
||||
grid = db.Grid.gridify(city=city, side_length=side_length)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from sqlalchemy import orm
|
|||
from sqlalchemy.dialects import postgresql as psql
|
||||
from sqlalchemy.ext import hybrid as sa_hybrid
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy.db import meta
|
||||
from velofy.db import utils
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ class Address(meta.Base):
|
|||
`.city.map` for convenience in interactive usage
|
||||
"""
|
||||
defaults: dict[str, t.Any] = {
|
||||
"color": f"{config.NEUTRAL_COLOR}",
|
||||
"color": f"{pkg_config.NEUTRAL_COLOR}",
|
||||
"popup": f"{self.street}, {self.zip_code} {self.city_name}",
|
||||
}
|
||||
defaults.update(kwargs)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from geopy import distance as geo_distance
|
|||
from sqlalchemy import orm
|
||||
from sqlalchemy.dialects import postgresql as psql
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.db import meta
|
||||
from velofy.db import utils
|
||||
|
|
@ -219,7 +219,7 @@ class Path(meta.Base):
|
|||
if self.bicycle_distance is not None:
|
||||
return
|
||||
|
||||
client = gm.Client(config.GOOGLE_MAPS_API_KEY)
|
||||
client = gm.Client(pkg_config.GOOGLE_MAPS_API_KEY)
|
||||
response = client.directions(
|
||||
origin=self.first_address.location.lat_lng,
|
||||
destination=self.second_address.location.lat_lng,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import sqlalchemy as sa
|
|||
from sqlalchemy import orm
|
||||
from sqlalchemy.dialects import postgresql as psql
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.db import meta
|
||||
from velofy.db import utils
|
||||
|
|
@ -214,8 +214,8 @@ class City(meta.Base):
|
|||
|
||||
address.draw(
|
||||
radius=radius,
|
||||
color=config.RESTAURANT_COLOR,
|
||||
fill_color=config.RESTAURANT_COLOR,
|
||||
color=pkg_config.RESTAURANT_COLOR,
|
||||
fill_color=pkg_config.RESTAURANT_COLOR,
|
||||
fill_opacity=0.3,
|
||||
tooltip=tooltip,
|
||||
)
|
||||
|
|
@ -223,7 +223,7 @@ class City(meta.Base):
|
|||
else:
|
||||
address.draw(
|
||||
radius=1,
|
||||
color=config.RESTAURANT_COLOR,
|
||||
color=pkg_config.RESTAURANT_COLOR,
|
||||
tooltip=tooltip,
|
||||
)
|
||||
|
||||
|
|
@ -245,11 +245,11 @@ class City(meta.Base):
|
|||
sa.text(
|
||||
f"""
|
||||
SELECT DISTINCT
|
||||
{config.CLEAN_SCHEMA}.addresses.zip_code
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses.zip_code
|
||||
FROM
|
||||
{config.CLEAN_SCHEMA}.addresses AS addresses
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses AS addresses
|
||||
WHERE
|
||||
{config.CLEAN_SCHEMA}.addresses.city_id = {self.id};
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses.city_id = {self.id};
|
||||
""", # noqa:S608
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import folium
|
|||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.db import meta
|
||||
|
||||
|
|
@ -106,8 +106,8 @@ class Customer(meta.Base):
|
|||
|
||||
address.draw(
|
||||
radius=radius,
|
||||
color=config.CUSTOMER_COLOR,
|
||||
fill_color=config.CUSTOMER_COLOR,
|
||||
color=pkg_config.CUSTOMER_COLOR,
|
||||
fill_color=pkg_config.CUSTOMER_COLOR,
|
||||
fill_opacity=0.3,
|
||||
tooltip=f"n_orders={n_orders}",
|
||||
)
|
||||
|
|
@ -115,7 +115,7 @@ class Customer(meta.Base):
|
|||
else:
|
||||
address.draw(
|
||||
radius=1,
|
||||
color=config.CUSTOMER_COLOR,
|
||||
color=pkg_config.CUSTOMER_COLOR,
|
||||
)
|
||||
|
||||
if restaurants:
|
||||
|
|
@ -173,8 +173,8 @@ class Customer(meta.Base):
|
|||
|
||||
address.draw(
|
||||
radius=radius,
|
||||
color=config.RESTAURANT_COLOR,
|
||||
fill_color=config.RESTAURANT_COLOR,
|
||||
color=pkg_config.RESTAURANT_COLOR,
|
||||
fill_color=pkg_config.RESTAURANT_COLOR,
|
||||
fill_opacity=0.3,
|
||||
tooltip=tooltip,
|
||||
)
|
||||
|
|
@ -182,7 +182,7 @@ class Customer(meta.Base):
|
|||
else:
|
||||
address.draw(
|
||||
radius=1,
|
||||
color=config.RESTAURANT_COLOR,
|
||||
color=pkg_config.RESTAURANT_COLOR,
|
||||
tooltip=tooltip,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import sqlalchemy as sa
|
|||
from sqlalchemy import orm
|
||||
from sqlalchemy.dialects import postgresql as psql
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.db import meta
|
||||
|
||||
|
|
@ -766,7 +766,7 @@ class Order(meta.Base):
|
|||
reverse=reverse,
|
||||
start_tooltip=start_tooltip,
|
||||
end_tooltip=end_tooltip,
|
||||
start_color=config.RESTAURANT_COLOR,
|
||||
end_color=config.CUSTOMER_COLOR,
|
||||
path_color=config.NEUTRAL_COLOR,
|
||||
start_color=pkg_config.RESTAURANT_COLOR,
|
||||
end_color=pkg_config.CUSTOMER_COLOR,
|
||||
path_color=pkg_config.NEUTRAL_COLOR,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import sqlalchemy as sa
|
|||
import utm
|
||||
from sqlalchemy import orm
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.db import meta
|
||||
from velofy.db import utils
|
||||
|
|
@ -260,8 +260,8 @@ class Pixel(meta.Base):
|
|||
|
||||
address.draw(
|
||||
radius=radius,
|
||||
color=config.RESTAURANT_COLOR,
|
||||
fill_color=config.RESTAURANT_COLOR,
|
||||
color=pkg_config.RESTAURANT_COLOR,
|
||||
fill_color=pkg_config.RESTAURANT_COLOR,
|
||||
fill_opacity=0.3,
|
||||
tooltip=tooltip,
|
||||
)
|
||||
|
|
@ -269,7 +269,7 @@ class Pixel(meta.Base):
|
|||
else:
|
||||
address.draw(
|
||||
radius=1,
|
||||
color=config.RESTAURANT_COLOR,
|
||||
color=pkg_config.RESTAURANT_COLOR,
|
||||
tooltip=tooltip,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import folium
|
|||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.db import meta
|
||||
|
||||
|
|
@ -151,8 +151,8 @@ class Restaurant(meta.Base):
|
|||
|
||||
address.draw(
|
||||
radius=radius,
|
||||
color=config.CUSTOMER_COLOR,
|
||||
fill_color=config.CUSTOMER_COLOR,
|
||||
color=pkg_config.CUSTOMER_COLOR,
|
||||
fill_color=pkg_config.CUSTOMER_COLOR,
|
||||
fill_opacity=0.3,
|
||||
tooltip=f"n_orders={n_orders}",
|
||||
)
|
||||
|
|
@ -160,13 +160,13 @@ class Restaurant(meta.Base):
|
|||
else:
|
||||
address.draw(
|
||||
radius=1,
|
||||
color=config.CUSTOMER_COLOR,
|
||||
color=pkg_config.CUSTOMER_COLOR,
|
||||
)
|
||||
|
||||
self.address.draw(
|
||||
radius=20,
|
||||
color=config.RESTAURANT_COLOR,
|
||||
fill_color=config.RESTAURANT_COLOR,
|
||||
color=pkg_config.RESTAURANT_COLOR,
|
||||
fill_color=pkg_config.RESTAURANT_COLOR,
|
||||
fill_opacity=0.3,
|
||||
tooltip=f"{self.name} (#{self.id}) | n_orders={len(self.orders)}",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import datetime as dt
|
|||
import pandas as pd
|
||||
import sqlalchemy as sa
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
from velofy.forecasts import models
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ class OrderHistory:
|
|||
|
||||
# Number of daily time steps must be a whole multiple of `time_step` length.
|
||||
n_daily_time_steps = (
|
||||
60 * (config.SERVICE_END - config.SERVICE_START) / time_step
|
||||
60 * (pkg_config.SERVICE_END - pkg_config.SERVICE_START) / time_step
|
||||
)
|
||||
if n_daily_time_steps != int(n_daily_time_steps): # pragma: no cover
|
||||
raise RuntimeError("Internal error: configuration has invalid TIME_STEPS")
|
||||
|
|
@ -96,37 +96,37 @@ class OrderHistory:
|
|||
) AS minutes_to_be_cut
|
||||
FROM (
|
||||
SELECT
|
||||
{config.CLEAN_SCHEMA}.orders.id,
|
||||
{config.CLEAN_SCHEMA}.orders.placed_at,
|
||||
{config.CLEAN_SCHEMA}.orders.pickup_address_id
|
||||
{pkg_config.CLEAN_SCHEMA}.orders.id,
|
||||
{pkg_config.CLEAN_SCHEMA}.orders.placed_at,
|
||||
{pkg_config.CLEAN_SCHEMA}.orders.pickup_address_id
|
||||
FROM
|
||||
{config.CLEAN_SCHEMA}.orders
|
||||
{pkg_config.CLEAN_SCHEMA}.orders
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
{config.CLEAN_SCHEMA}.addresses.id AS address_id
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses.id AS address_id
|
||||
FROM
|
||||
{config.CLEAN_SCHEMA}.addresses
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses
|
||||
WHERE
|
||||
{config.CLEAN_SCHEMA}.addresses.city_id
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses.city_id
|
||||
= {self._grid.city.id}
|
||||
) AS in_city
|
||||
ON {config.CLEAN_SCHEMA}.orders.pickup_address_id
|
||||
ON {pkg_config.CLEAN_SCHEMA}.orders.pickup_address_id
|
||||
= in_city.address_id
|
||||
WHERE
|
||||
{config.CLEAN_SCHEMA}.orders.ad_hoc IS TRUE
|
||||
{pkg_config.CLEAN_SCHEMA}.orders.ad_hoc IS TRUE
|
||||
) AS
|
||||
orders
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
{config.CLEAN_SCHEMA}.addresses_pixels.address_id,
|
||||
{config.CLEAN_SCHEMA}.addresses_pixels.pixel_id
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses_pixels.address_id,
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses_pixels.pixel_id
|
||||
FROM
|
||||
{config.CLEAN_SCHEMA}.addresses_pixels
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses_pixels
|
||||
WHERE
|
||||
{config.CLEAN_SCHEMA}.addresses_pixels.grid_id
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses_pixels.grid_id
|
||||
= {self._grid.id}
|
||||
AND
|
||||
{config.CLEAN_SCHEMA}.addresses_pixels.city_id
|
||||
{pkg_config.CLEAN_SCHEMA}.addresses_pixels.city_id
|
||||
= {self._grid.city.id} -- -> sanity check
|
||||
) AS pixels
|
||||
ON orders.pickup_address_id = pixels.address_id
|
||||
|
|
@ -153,17 +153,22 @@ class OrderHistory:
|
|||
start_day.year,
|
||||
start_day.month,
|
||||
start_day.day,
|
||||
config.SERVICE_START,
|
||||
pkg_config.SERVICE_START,
|
||||
)
|
||||
end_day = data.index.levels[1].max().date()
|
||||
end = dt.datetime(end_day.year, end_day.month, end_day.day, config.SERVICE_END)
|
||||
end = dt.datetime(
|
||||
end_day.year,
|
||||
end_day.month,
|
||||
end_day.day,
|
||||
pkg_config.SERVICE_END,
|
||||
)
|
||||
# ... and all possible `tuple`s of "pixel_id"-"start_at" combinations.
|
||||
# The "start_at" values must lie within the operating hours.
|
||||
gen = (
|
||||
(pixel_id, start_at)
|
||||
for pixel_id in sorted(data.index.levels[0])
|
||||
for start_at in pd.date_range(start, end, freq=f"{self._time_step}min")
|
||||
if config.SERVICE_START <= start_at.hour < config.SERVICE_END
|
||||
if pkg_config.SERVICE_START <= start_at.hour < pkg_config.SERVICE_END
|
||||
)
|
||||
|
||||
# Re-index `data` filling in `0`s where there is no demand.
|
||||
|
|
@ -270,7 +275,7 @@ class OrderHistory:
|
|||
except KeyError:
|
||||
raise LookupError("The `pixel_id` is not in the `grid`") from None
|
||||
|
||||
if predict_at >= config.CUTOFF_DAY: # pragma: no cover
|
||||
if predict_at >= pkg_config.CUTOFF_DAY: # pragma: no cover
|
||||
raise RuntimeError("Internal error: cannot predict beyond the given data")
|
||||
|
||||
# The first and last training day are just before the `predict_at` day
|
||||
|
|
@ -342,7 +347,7 @@ class OrderHistory:
|
|||
except KeyError:
|
||||
raise LookupError("The `pixel_id` is not in the `grid`") from None
|
||||
|
||||
if predict_day >= config.CUTOFF_DAY.date(): # pragma: no cover
|
||||
if predict_day >= pkg_config.CUTOFF_DAY.date(): # pragma: no cover
|
||||
raise RuntimeError("Internal error: cannot predict beyond the given data")
|
||||
|
||||
# The first and last training day are just before the `predict_day`
|
||||
|
|
@ -352,7 +357,7 @@ class OrderHistory:
|
|||
first_train_day.year,
|
||||
first_train_day.month,
|
||||
first_train_day.day,
|
||||
config.SERVICE_START,
|
||||
pkg_config.SERVICE_START,
|
||||
0,
|
||||
)
|
||||
last_train_day = predict_day - dt.timedelta(days=1)
|
||||
|
|
@ -360,7 +365,7 @@ class OrderHistory:
|
|||
last_train_day.year,
|
||||
last_train_day.month,
|
||||
last_train_day.day,
|
||||
config.SERVICE_END, # subtract one `time_step` below
|
||||
pkg_config.SERVICE_END, # subtract one `time_step` below
|
||||
0,
|
||||
) - dt.timedelta(minutes=self._time_step)
|
||||
|
||||
|
|
@ -379,14 +384,14 @@ class OrderHistory:
|
|||
predict_day.year,
|
||||
predict_day.month,
|
||||
predict_day.day,
|
||||
config.SERVICE_START,
|
||||
pkg_config.SERVICE_START,
|
||||
0,
|
||||
)
|
||||
last_prediction_at = dt.datetime(
|
||||
predict_day.year,
|
||||
predict_day.month,
|
||||
predict_day.day,
|
||||
config.SERVICE_END, # subtract one `time_step` below
|
||||
pkg_config.SERVICE_END, # subtract one `time_step` below
|
||||
0,
|
||||
) - dt.timedelta(minutes=self._time_step)
|
||||
|
||||
|
|
@ -431,7 +436,7 @@ class OrderHistory:
|
|||
except KeyError:
|
||||
raise LookupError("The `pixel_id` is not in the `grid`") from None
|
||||
|
||||
if predict_at >= config.CUTOFF_DAY: # pragma: no cover
|
||||
if predict_at >= pkg_config.CUTOFF_DAY: # pragma: no cover
|
||||
raise RuntimeError("Internal error: cannot predict beyond the given data")
|
||||
|
||||
# The first and last training day are just before the `predict_at` day
|
||||
|
|
@ -442,16 +447,16 @@ class OrderHistory:
|
|||
first_train_day.year,
|
||||
first_train_day.month,
|
||||
first_train_day.day,
|
||||
config.SERVICE_START,
|
||||
pkg_config.SERVICE_START,
|
||||
0,
|
||||
)
|
||||
# Predicting the first time step on the `predict_at` day is a corner case.
|
||||
# Then, the previous day is indeed the `last_train_day`. Predicting any
|
||||
# other time step implies that the `predict_at` day is the `last_train_day`.
|
||||
# `last_train_time` is the last "start_at" before the one being predicted.
|
||||
if predict_at.hour == config.SERVICE_START:
|
||||
if predict_at.hour == pkg_config.SERVICE_START:
|
||||
last_train_day = predict_at.date() - dt.timedelta(days=1)
|
||||
last_train_time = dt.time(config.SERVICE_END, 0)
|
||||
last_train_time = dt.time(pkg_config.SERVICE_END, 0)
|
||||
else:
|
||||
last_train_day = predict_at.date()
|
||||
last_train_time = predict_at.time()
|
||||
|
|
@ -479,7 +484,7 @@ class OrderHistory:
|
|||
predict_at.year,
|
||||
predict_at.month,
|
||||
predict_at.day,
|
||||
config.SERVICE_START,
|
||||
pkg_config.SERVICE_START,
|
||||
0,
|
||||
)
|
||||
).seconds
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import datetime as dt
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
|
||||
|
||||
# The day on which most test cases take place.
|
||||
|
|
@ -15,9 +15,9 @@ NOON = 12
|
|||
|
||||
# `START` and `END` constitute a 57-day time span, 8 full weeks plus 1 day.
|
||||
# That implies a maximum `train_horizon` of `8` as that needs full 7-day weeks.
|
||||
START = dt.datetime(YEAR, MONTH, DAY, config.SERVICE_START, 0)
|
||||
START = dt.datetime(YEAR, MONTH, DAY, pkg_config.SERVICE_START, 0)
|
||||
_end = START + dt.timedelta(days=56) # `56` as `START` is not included
|
||||
END = dt.datetime(_end.year, _end.month, _end.day, config.SERVICE_END, 0)
|
||||
END = dt.datetime(_end.year, _end.month, _end.day, pkg_config.SERVICE_END, 0)
|
||||
|
||||
# Default time steps (in minutes), for example, for `OrderHistory` objects.
|
||||
LONG_TIME_STEP = 60
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from alembic import command as alembic_cmd
|
|||
from alembic import config as alembic_config
|
||||
from sqlalchemy import orm
|
||||
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy import db
|
||||
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ pytest_plugins = [
|
|||
if not os.getenv("TESTING"):
|
||||
raise RuntimeError("Tests must be executed with TESTING set in the environment")
|
||||
|
||||
if not config.TESTING:
|
||||
if not pkg_config.TESTING:
|
||||
raise RuntimeError("The testing configuration was not loaded")
|
||||
|
||||
|
||||
|
|
@ -51,12 +51,12 @@ def db_connection(request):
|
|||
"""
|
||||
# We need a fresh database connection for each of the two `params`.
|
||||
# Otherwise, the first test of the parameter run second will fail.
|
||||
engine = sa.create_engine(config.DATABASE_URI)
|
||||
engine = sa.create_engine(pkg_config.DATABASE_URI)
|
||||
connection = engine.connect()
|
||||
|
||||
if request.param == "all_at_once":
|
||||
with connection.begin():
|
||||
connection.execute(sa.text(f"CREATE SCHEMA {config.CLEAN_SCHEMA};"))
|
||||
connection.execute(sa.text(f"CREATE SCHEMA {pkg_config.CLEAN_SCHEMA};"))
|
||||
db.Base.metadata.create_all(connection)
|
||||
else:
|
||||
cfg = alembic_config.Config("alembic.ini")
|
||||
|
|
@ -71,13 +71,15 @@ def db_connection(request):
|
|||
connection.close()
|
||||
|
||||
with engine.begin() as cleanup:
|
||||
cleanup.execute(sa.text(f"DROP SCHEMA {config.CLEAN_SCHEMA} CASCADE;"))
|
||||
cleanup.execute(sa.text(f"DROP SCHEMA {pkg_config.CLEAN_SCHEMA} CASCADE;"))
|
||||
|
||||
if request.param == "sequentially":
|
||||
tmp_alembic_version = f"{config.ALEMBIC_TABLE}_{config.CLEAN_SCHEMA}"
|
||||
tmp_alembic_version = (
|
||||
f"{pkg_config.ALEMBIC_TABLE}_{pkg_config.CLEAN_SCHEMA}"
|
||||
)
|
||||
cleanup.execute(
|
||||
sa.text(
|
||||
f"DROP TABLE {config.ALEMBIC_TABLE_SCHEMA}.{tmp_alembic_version};", # noqa:E501
|
||||
f"DROP TABLE {pkg_config.ALEMBIC_TABLE_SCHEMA}.{tmp_alembic_version};", # noqa:E501
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import pandas as pd
|
|||
import pytest
|
||||
|
||||
from tests import config as test_config
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy.forecasts import timify
|
||||
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ def vertical_datetime_index():
|
|||
gen = (
|
||||
start_at
|
||||
for start_at in start_ats
|
||||
if config.SERVICE_START <= start_at.hour < config.SERVICE_END
|
||||
if pkg_config.SERVICE_START <= start_at.hour < pkg_config.SERVICE_END
|
||||
)
|
||||
|
||||
index = pd.Index(gen)
|
||||
|
|
@ -113,7 +113,7 @@ def order_totals(good_pixel_id):
|
|||
(pixel_id, start_at)
|
||||
for pixel_id in pixel_ids
|
||||
for start_at in start_ats
|
||||
if config.SERVICE_START <= start_at.hour < config.SERVICE_END
|
||||
if pkg_config.SERVICE_START <= start_at.hour < pkg_config.SERVICE_END
|
||||
)
|
||||
|
||||
# Re-index `data` filling in `0`s where there is no demand.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import pandas as pd
|
|||
import pytest
|
||||
|
||||
from tests import config as test_config
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
from velofy.forecasts.methods import arima
|
||||
from velofy.forecasts.methods import ets
|
||||
from velofy.forecasts.methods import extrapolate_season
|
||||
|
|
@ -24,14 +24,14 @@ def forecast_interval():
|
|||
future_day.year,
|
||||
future_day.month,
|
||||
future_day.day,
|
||||
config.SERVICE_START,
|
||||
pkg_config.SERVICE_START,
|
||||
0,
|
||||
)
|
||||
end_of_day = dt.datetime(
|
||||
future_day.year,
|
||||
future_day.month,
|
||||
future_day.day,
|
||||
config.SERVICE_END,
|
||||
pkg_config.SERVICE_END,
|
||||
0,
|
||||
)
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ def forecast_interval():
|
|||
gen = (
|
||||
start_at
|
||||
for start_at in start_ats
|
||||
if config.SERVICE_START <= start_at.hour < config.SERVICE_END
|
||||
if pkg_config.SERVICE_START <= start_at.hour < pkg_config.SERVICE_END
|
||||
)
|
||||
|
||||
index = pd.Index(gen)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import pandas as pd
|
|||
import pytest
|
||||
|
||||
from tests import config as test_config
|
||||
from velofy import config
|
||||
from velofy import config as pkg_config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -221,7 +221,7 @@ class TestMakeVerticalTimeSeries:
|
|||
|
||||
n_daily_time_steps = (
|
||||
60
|
||||
* (config.SERVICE_END - config.SERVICE_START)
|
||||
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
|
||||
// test_config.LONG_TIME_STEP
|
||||
)
|
||||
|
||||
|
|
@ -247,7 +247,7 @@ class TestMakeVerticalTimeSeries:
|
|||
|
||||
n_daily_time_steps = (
|
||||
60
|
||||
* (config.SERVICE_END - config.SERVICE_START)
|
||||
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
|
||||
// test_config.LONG_TIME_STEP
|
||||
)
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ class TestMakeRealTimeTimeSeries:
|
|||
good_predict_at.year,
|
||||
good_predict_at.month,
|
||||
good_predict_at.day,
|
||||
config.SERVICE_START,
|
||||
pkg_config.SERVICE_START,
|
||||
0,
|
||||
)
|
||||
result = order_history.make_realtime_ts(
|
||||
|
|
@ -358,7 +358,7 @@ class TestMakeRealTimeTimeSeries:
|
|||
|
||||
n_daily_time_steps = (
|
||||
60
|
||||
* (config.SERVICE_END - config.SERVICE_START)
|
||||
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
|
||||
// test_config.LONG_TIME_STEP
|
||||
)
|
||||
|
||||
|
|
@ -395,11 +395,13 @@ class TestMakeRealTimeTimeSeries:
|
|||
|
||||
n_daily_time_steps = (
|
||||
60
|
||||
* (config.SERVICE_END - config.SERVICE_START)
|
||||
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
|
||||
// test_config.LONG_TIME_STEP
|
||||
)
|
||||
n_time_steps_before = (
|
||||
60 * (test_config.NOON - config.SERVICE_START) // test_config.LONG_TIME_STEP
|
||||
60
|
||||
* (test_config.NOON - pkg_config.SERVICE_START)
|
||||
// test_config.LONG_TIME_STEP
|
||||
)
|
||||
|
||||
assert (
|
||||
|
|
@ -427,7 +429,7 @@ class TestMakeRealTimeTimeSeries:
|
|||
|
||||
n_daily_time_steps = (
|
||||
60
|
||||
* (config.SERVICE_END - config.SERVICE_START)
|
||||
* (pkg_config.SERVICE_END - pkg_config.SERVICE_START)
|
||||
// test_config.LONG_TIME_STEP
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue