Import velofy.config as pkg_config everywhere
This commit is contained in:
parent
de5e49b497
commit
cf2534f41e
10 changed files with 113 additions and 103 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue