Properly rephrase
Docstrings and comments drop "object" where the backticked name already says it.
This commit is contained in:
parent
8a96e78533
commit
fe7510f8c2
39 changed files with 89 additions and 88 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"""Provide package-wide configuration.
|
||||
|
||||
This module provides utils to create new `Config` objects
|
||||
This module provides utils to create new `Config`s
|
||||
on the fly, mainly for testing and migrating.
|
||||
|
||||
Within this package, use the `config` proxy at the package's top level
|
||||
|
|
@ -98,7 +98,7 @@ class TestingConfig(Config):
|
|||
|
||||
|
||||
def make_config(env: str = "production") -> Config:
|
||||
"""Create a new `Config` object.
|
||||
"""Create a new `Config`.
|
||||
|
||||
Args:
|
||||
env: either "production" or "testing"
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class Address(meta.Base):
|
|||
def location(self) -> utils.Location:
|
||||
"""The location of the address.
|
||||
|
||||
The returned `Location` object relates to `.city.southwest`.
|
||||
The returned `Location` relates to `.city.southwest`.
|
||||
|
||||
`.x` and `.y` are aliases of `.location.x` and `.location.y`.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
"""Model for the `Path` relationship between two `Address` objects."""
|
||||
"""Model for the `Path` relationship between two `Address`es."""
|
||||
|
||||
import functools
|
||||
import itertools
|
||||
|
|
@ -19,9 +19,9 @@ from velofy.db import utils
|
|||
|
||||
|
||||
class Path(meta.Base):
|
||||
"""Path between two `Address` objects.
|
||||
"""Path between two `Address`es.
|
||||
|
||||
Models the path between two `Address` objects, including directions
|
||||
Models the path between two `Address`es, including directions
|
||||
for a `Courier` to get from one `Address` to another.
|
||||
|
||||
As the couriers are on bicycles, we model the paths as
|
||||
|
|
@ -74,7 +74,7 @@ class Path(meta.Base):
|
|||
# All foreign keys `RESTRICT`
|
||||
# because data of finished stages must never change through cascades
|
||||
#
|
||||
# The two `Address` objects must be in the same `.city`
|
||||
# The two `Address`es must be in the same `.city`
|
||||
sa.ForeignKeyConstraint(
|
||||
["first_address_id", "city_id"],
|
||||
["addresses.id", "addresses.city_id"],
|
||||
|
|
@ -128,16 +128,16 @@ class Path(meta.Base):
|
|||
*addresses: db.Address,
|
||||
google_maps: bool = False,
|
||||
) -> list[t.Self]:
|
||||
"""Calculate pair-wise paths for `Address` objects.
|
||||
"""Calculate pair-wise paths for `Address`es.
|
||||
|
||||
This is the main constructor method for the class.
|
||||
|
||||
It handles the "sorting" of the `Address` objects by `.id`, which is
|
||||
It handles the "sorting" of the `Address`es by `.id`, which is
|
||||
the logic that enforces the symmetric graph behind the paths.
|
||||
|
||||
Args:
|
||||
*addresses: to calculate the pair-wise paths for;
|
||||
must contain at least two `Address` objects
|
||||
must contain at least two `Address`es
|
||||
google_maps: if `.bicycle_distance` and `._directions` should be
|
||||
populated with a query to the Google Maps Directions API;
|
||||
by default, only the `.air_distance` is calculated with `geopy`
|
||||
|
|
@ -152,7 +152,7 @@ class Path(meta.Base):
|
|||
# ... which a precedence constraint for the `.id`s enforces
|
||||
first, second = sorted(pair, key=lambda address: address.id)
|
||||
|
||||
# If there is no `Path` object in the database ...
|
||||
# If there is no `Path` in the database ...
|
||||
path = db.session.scalars(
|
||||
sa.select(cls)
|
||||
.where(cls.first_address == first)
|
||||
|
|
@ -184,7 +184,7 @@ class Path(meta.Base):
|
|||
|
||||
@classmethod
|
||||
def from_order(cls, order: db.Order, *, google_maps: bool = False) -> t.Self:
|
||||
"""Calculate the path for an `Order` object.
|
||||
"""Calculate the path for an `Order`.
|
||||
|
||||
The path goes from the `Order.pickup_address` to the `Order.delivery_address`.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
"""Model for the many-to-many relationship between `Address` and `Pixel` objects."""
|
||||
"""Model for the many-to-many relationship between `Address` and `Pixel`s."""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class City(meta.Base):
|
|||
|
||||
@functools.cached_property # pragma: no cover
|
||||
def map(self) -> folium.Map:
|
||||
"""A `folium.Map` object aligned with the city's viewport.
|
||||
"""A `folium.Map` aligned with the city's viewport.
|
||||
|
||||
The map is mutable and changed from various locations in the code base.
|
||||
Use `.clear_map()` to start over with an empty map.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"""Provide connection utils for the ORM layer.
|
||||
|
||||
The `session` object is used as a global within the `velofy` package,
|
||||
The `session` is used as a global within the `velofy` package,
|
||||
like `db.session` in Flask-SQLAlchemy: It is a proxy to one session per thread.
|
||||
The engine and the session are created only on first use.
|
||||
So, importing the package does not require a database.
|
||||
|
|
|
|||
|
|
@ -197,12 +197,12 @@ class Forecast(meta.Base):
|
|||
model: str,
|
||||
data: pd.DataFrame,
|
||||
) -> list[t.Self]:
|
||||
"""Convert results from the forecasting `*Model`s into `Forecast` objects.
|
||||
"""Convert results from the forecasting `*Model`s into `Forecast`s.
|
||||
|
||||
This is an alternative constructor method.
|
||||
|
||||
Background: The functions in `velofy.forecasts.methods`
|
||||
return `pd.Dataframe`s with "start_at" (i.e., `pd.Timestamp` objects)
|
||||
return `pd.Dataframe`s with "start_at" (i.e., `pd.Timestamp`s)
|
||||
values in the index and five columns "prediction", "low80", "high80",
|
||||
"low95", and "high95" with `np.float` values. The `*Model.predict()`
|
||||
methods in `velofy.forecasts.models` then add an "actual"
|
||||
|
|
@ -219,7 +219,7 @@ class Forecast(meta.Base):
|
|||
with the six columns holding `float`s)
|
||||
|
||||
Returns:
|
||||
forecasts: the `data` as `Forecast` objects
|
||||
forecasts: the `data` as `Forecast`s
|
||||
"""
|
||||
forecasts = []
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Grid(meta.Base):
|
|||
"""Create a fully populated `Grid` for a `city`.
|
||||
|
||||
The `Grid` contains only `Pixel`s that have at least one
|
||||
`Order.pickup_address`. `Address` objects outside the `.city`'s
|
||||
`Order.pickup_address`. `Address`es outside the `.city`'s
|
||||
viewport are discarded.
|
||||
|
||||
Args:
|
||||
|
|
@ -117,7 +117,7 @@ class Grid(meta.Base):
|
|||
|
||||
# Determine which `pixel` the `address` belongs to ...
|
||||
n_x, n_y = address.x // side_length, address.y // side_length
|
||||
# ... and create a new `Pixel` object if necessary
|
||||
# ... and create a new `Pixel` if necessary
|
||||
if (n_x, n_y) not in pixels:
|
||||
pixels[(n_x, n_y)] = db.Pixel(n_x=n_x, n_y=n_y)
|
||||
grid.pixels.append(pixels[(n_x, n_y)])
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from velofy.db import utils
|
|||
class Pixel(meta.Base):
|
||||
"""A pixel in a `Grid`.
|
||||
|
||||
Square pixels aggregate `Address` objects within a `City`.
|
||||
Square pixels aggregate `Address`es within a `City`.
|
||||
Every `Address` belongs to exactly one `Pixel` in a `Grid`.
|
||||
|
||||
Every `Pixel` has a unique `n_x`-`n_y` coordinate within the `Grid`.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
This sub-package is divided into further sub-packages and modules as follows:
|
||||
|
||||
`methods` contains various time series related statistical methods, implemented
|
||||
as plain `function` objects that are used to predict into the future given a
|
||||
as plain `function`s that are used to predict into the future given a
|
||||
time series of historic order counts. The methods are context-agnostic, meaning
|
||||
that they only take and return `pd.Series/DataFrame`s holding numbers and
|
||||
are not concerned with how these numbers were generated or what they mean.
|
||||
|
|
@ -12,7 +12,7 @@ in R using the `rpy2` library. Others, like `extrapolate_season.predict()`, are
|
|||
written in plain Python.
|
||||
|
||||
`timify` defines an `OrderHistory` class that abstracts away the communication
|
||||
with the database and provides `pd.Series` objects with the order counts that
|
||||
with the database and provides `pd.Series` with the order counts that
|
||||
are fed into the `methods`. In particular, it uses SQL statements behind the
|
||||
scenes to calculate the historic order counts on a per-`Pixel` level. Once the
|
||||
data is loaded from the database, an `OrderHistory` instance provides various
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ This sub-package is organized as follows. The `base` module defines an abstract
|
|||
`ForecastingModelABC` class that unifies how the concrete `*Model`s work.
|
||||
While the abstract `.predict()` method returns a `pd.DataFrame` (= basically,
|
||||
the result of one of the forecasting `methods`, the concrete `.make_forecast()`
|
||||
method converts the results into `Forecast` (=ORM) objects.
|
||||
method converts the results into `Forecast`s, the ORM model.
|
||||
Also, `.make_forecast()` implements a caching strategy where already made
|
||||
`Forecast`s are loaded from the database instead of calculating them again,
|
||||
which could be a heavier computation.
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class ForecastingModelABC(abc.ABC):
|
|||
db.session.add_all(forecasts)
|
||||
db.session.commit()
|
||||
|
||||
# The one `Forecast` object asked for must be in `forecasts`
|
||||
# The one `Forecast` asked for must be in `forecasts`
|
||||
# if the concrete `*Model.predict()` method works correctly; ...
|
||||
for forecast in forecasts:
|
||||
if forecast.start_at == predict_at:
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class OrderHistory:
|
|||
"""
|
||||
|
||||
def __init__(self, grid: db.Grid, time_step: int) -> None:
|
||||
"""Initialize a new `OrderHistory` object.
|
||||
"""Initialize a new `OrderHistory`.
|
||||
|
||||
Args:
|
||||
grid: pixel grid used to aggregate orders spatially
|
||||
|
|
@ -52,7 +52,8 @@ class OrderHistory:
|
|||
def totals(self) -> pd.DataFrame:
|
||||
"""The order totals by `Pixel` and `.time_step`.
|
||||
|
||||
The returned object should not be mutated!
|
||||
The returned `DataFrame` is the cached data itself.
|
||||
So, it must not be mutated!
|
||||
|
||||
Returns:
|
||||
order_totals: a one-column `DataFrame` with a `MultiIndex` of the
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ 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, pkg_config.SERVICE_END, 0)
|
||||
|
||||
# Default time steps (in minutes), for example, for `OrderHistory` objects
|
||||
# Default time steps (in minutes), for example, for `OrderHistory`s
|
||||
LONG_TIME_STEP = 60
|
||||
SHORT_TIME_STEP = 30
|
||||
TIME_STEPS = (SHORT_TIME_STEP, LONG_TIME_STEP)
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ def db_session(db_connection, monkeypatch):
|
|||
# => Commits inside a test case only release a savepoint
|
||||
session = orm.Session(bind=db_connection, join_transaction_mode="create_savepoint")
|
||||
|
||||
# Monkey patch the package's global `session` object,
|
||||
# Monkey patch the package's global `session`,
|
||||
# which is used heavily in the code base
|
||||
monkeypatch.setattr(db, "session", session)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ def test_two_pixels_with_two_addresses(
|
|||
make_restaurant,
|
||||
make_order,
|
||||
):
|
||||
"""Two `Address` objects in distinct `Pixel` objects.
|
||||
"""Two `Address`es in distinct `Pixel`s.
|
||||
|
||||
This is roughly the same test case as
|
||||
`tests.db.test_grids.test_two_pixels_with_two_addresses`.
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory):
|
|||
class Params:
|
||||
"""Define flags that overwrite some attributes.
|
||||
|
||||
The `factory.Trait` objects in this class are executed after all
|
||||
The `factory.Trait`s in this class are executed after all
|
||||
the normal attributes in the `OrderFactory` classes were evaluated.
|
||||
|
||||
Flags:
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class ScheduledOrderFactory(ad_hoc.AdHocOrderFactory):
|
|||
# Attributes regarding the specialization of an `Order`: ad-hoc or scheduled
|
||||
placed_at = factory.LazyFunction(utils.early_in_the_morning)
|
||||
ad_hoc = False
|
||||
# Discrete `datetime` objects in the "core" lunch time are enough
|
||||
# Discrete `datetime`s in the "core" lunch time are enough
|
||||
scheduled_delivery_at = factory.LazyFunction(
|
||||
lambda: random.choice(
|
||||
[
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ def random_timespan(
|
|||
max_minutes=0,
|
||||
max_seconds=0,
|
||||
):
|
||||
"""A randomized `timedelta` object between the specified arguments."""
|
||||
"""A randomized `timedelta` between the specified arguments."""
|
||||
total_min_seconds = min_hours * 3600 + min_minutes * 60 + min_seconds
|
||||
total_max_seconds = max_hours * 3600 + max_minutes * 60 + max_seconds
|
||||
return dt.timedelta(
|
||||
|
|
@ -27,6 +27,6 @@ def random_timespan(
|
|||
|
||||
|
||||
def early_in_the_morning():
|
||||
"""A randomized `datetime` object early in the morning."""
|
||||
"""A randomized `datetime` early in the morning."""
|
||||
early = dt.datetime(*test_config.DATE, 3, 0)
|
||||
return early + random_timespan(max_hours=2)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ def make_address(city):
|
|||
factories.AddressFactory.reset_sequence(1)
|
||||
|
||||
def func(**kwargs):
|
||||
"""Create an `Address` object in the `city`."""
|
||||
"""Create an `Address` in the `city`."""
|
||||
address = factories.AddressFactory.build(**kwargs)
|
||||
|
||||
city.addresses.append(address)
|
||||
|
|
@ -29,7 +29,7 @@ def make_courier():
|
|||
factories.CourierFactory.reset_sequence(1)
|
||||
|
||||
def func(**kwargs):
|
||||
"""Create a new `Courier` object."""
|
||||
"""Create a new `Courier`."""
|
||||
return factories.CourierFactory.build(**kwargs)
|
||||
|
||||
return func
|
||||
|
|
@ -42,7 +42,7 @@ def make_customer():
|
|||
factories.CustomerFactory.reset_sequence(1)
|
||||
|
||||
def func(**kwargs):
|
||||
"""Create a new `Customer` object."""
|
||||
"""Create a new `Customer`."""
|
||||
return factories.CustomerFactory.build(**kwargs)
|
||||
|
||||
return func
|
||||
|
|
@ -55,7 +55,7 @@ def make_restaurant(make_address):
|
|||
factories.RestaurantFactory.reset_sequence(1)
|
||||
|
||||
def func(address=None, **kwargs):
|
||||
"""Create a new `Restaurant` object.
|
||||
"""Create a new `Restaurant`.
|
||||
|
||||
If no `address` is provided, a new `Address` is created.
|
||||
"""
|
||||
|
|
@ -78,7 +78,7 @@ def make_order(make_address, make_courier, make_customer, make_restaurant):
|
|||
factories.AdHocOrderFactory.reset_sequence(1)
|
||||
|
||||
def func(*, scheduled=False, restaurant=None, courier=None, **kwargs):
|
||||
"""Create a new `Order` object.
|
||||
"""Create a new `Order`.
|
||||
|
||||
Each `Order` is made by a new `Customer` with a unique `Address` for delivery.
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ def make_replay_order(make_order, simulation):
|
|||
factories.ReplayedOrderFactory.reset_sequence(1)
|
||||
|
||||
def func(*, scheduled=False, order=None, **kwargs):
|
||||
"""Create a new `ReplayedOrder` object.
|
||||
"""Create a new `ReplayedOrder`.
|
||||
|
||||
Each `ReplayOrder` is made by a new `Customer` with a unique `Address`.
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue