Commit graph velofy/src
Author SHA1 Message Date
c18fc2ba59
Refer to sources with "See:" in comments 2026-12-03 11:09:38 +01:00
f90f263dab
Explain the "why" in a few more comments
Comments that only repeated the code are removed.
2026-12-03 11:06:36 +01:00
0f69709226
Reword the comments in the rest of velofy
Each comment is one sentence or two short ones
joined by "=>", without a final period.
2026-12-03 10:46:42 +01:00
9b8fe8b8fd
Reword the comments in velofy.forecasts
Each comment is one sentence or two short ones
joined by "=>", without a final period.
2026-12-03 10:43:55 +01:00
1413d08ed9
Reword the comments in velofy.db
Each comment is one sentence or two short ones joined by "=>", without a final period.
2026-12-03 10:38:28 +01:00
2f1afd459f
Break multi-line comments before conjunctions 2026-12-03 10:13:13 +01:00
049a5f6f62
Remove periods from one-sentence comments 2026-12-03 10:04:43 +01:00
732a74be1c
Declare __all__ in all re-exporting packages
Then, the linters know the imports are re-exports and not unused.
2026-12-03 09:44:07 +01:00
35d0c7b409
Test reading the database revision
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m50s
In the "sequentially" variant of the test database,
`current_db_revision()` must return the head of the migrations;
in the "all_at_once" variant, there is no version table.
2026-12-02 13:56:04 +01:00
2add322a25
Test the revision lock of the CLI stages
The `@db_revision` decorator no longer skips its check under `TESTING`.

The tests replace `current_db_revision()` with the revision they need.
2026-12-02 13:42:04 +01:00
eb059c1ea5
Read the database revision with the Alembic API
The `@db_revision` decorator no longer runs `alembic current` in a subprocess,
which only worked from the project folder and reported any failure as a wrong revision.

Also, its docstring now explains that it locks completed stages of the data pipeline.
2026-12-02 13:35:37 +01:00
bbd7d6a279
Store Path._directions as a JSON array
The column is of type `JSON`,
but the code stored a JSON-encoded string in it;
so, the data was encoded twice.

A later data migration converts the existing rows.
2026-12-02 09:03:49 +01:00
fc185fa3c0
Create the engine and the session on first use
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
The global `db.session` is now a `scoped_session`,
like, for example, in Flask-SQLAlchemy.

Importing the package no longer creates an engine;
so, the placeholder for the tests is obsolete.

The `db_session` fixture replaces `db.session` with `monkeypatch`
such that it is reset after each test.

Tests without the fixture get a placeholder that fails loudly
instead of opening a real session,
which would block the `DROP SCHEMA` at the end of the test run.
2026-12-02 00:23:41 +01:00
bc2e3f439d
Count with .scalar_one() in velofy.console.gridify
A `COUNT` always returns exactly one row; `.scalar_one()`
is typed as `int` and is used for all other counts as well.
2026-12-01 23:51:00 +01:00
185a37f7d4
Query with select() in the forecasting models
`Session.query()` is the legacy API in SQLAlchemy 2.x.

`.one_or_none()` expresses that the unique constraint
on the five filtered columns allows at most one cached `Forecast`.
2026-12-01 23:48:36 +01:00
2eb6b5769f
Query with select() in Pixel
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The addresses with restaurants are now selected with a subquery in one statement.

The `_restaurants_mock` fixture mocks the new call chain.
2026-12-01 23:45:35 +01:00
0dc3e11a63
Query with select() in Customer
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The delivery and pickup addresses are now selected with subqueries in one statement each.
2026-12-01 23:39:44 +01:00
54e21109e7
Query with select() in Restaurant
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The delivery addresses are now selected with a subquery in one statement.
2026-12-01 23:37:57 +01:00
9d2a4139b7
Query with select() in City
`Session.query()` is the legacy API in SQLAlchemy 2.x.

The addresses with restaurants are now selected with a subquery in one statement.
2026-12-01 23:35:21 +01:00
53e1859ee8
Query with select() in Grid and Path
`Session.query()` is the legacy API in SQLAlchemy 2.x.

Unlike `Query`, `select()` does not deduplicate single entities from a `JOIN`;
so, `Grid.gridify()` calls `.unique()` explicitly.

The `addresses_mock` fixtures mock the new call chain.
2026-12-01 23:29:39 +01:00
1f5a39f83a
Query with select() in velofy.console
`Session.query()` is the legacy API in SQLAlchemy 2.x.
2026-12-01 23:21:00 +01:00
7d53abc057
Avoid lazy loads in .__repr__()
`ReplaySimulation`, `ReplayedOrder`, and `Forecast` accessed
relationships in their `.__repr__()`, which emits queries
or fails for detached instances.

They now use the foreign key columns.
2026-12-01 22:34:38 +01:00
1f9d0effae
Cache City.map with functools.cached_property
This replaces the manual caching in the uninitialized
`._map` attribute with a `hasattr()` check.

`.clear_map()` now only discards the cached map.
2026-12-01 22:27:28 +01:00
b36a3d1cd6
Allow the same Grid.side_length across cities
The `unique=True` on `Grid.side_length`
made the side length unique across all cities.

The intended rule is the `UniqueConstraint("city_id", "side_length")`,
which the migrations already implement; so, no migration is needed.
2026-12-01 21:58:29 +01:00
f92fd35ce3
Revert to bare pd.Series in OrderHistory
`typeguard` evaluates the annotations at runtime where `pd.Series[int]` raises a `TypeError`
2026-12-01 15:31:58 +01:00
8abc93987e
Generate the fake coordinates as floats
Also, remove the misleading comment in `Location`
2026-12-01 15:27:53 +01:00
66265c8808
Pass an explicit empty list to OrderedSet() 2026-12-01 14:50:16 +01:00
804a4a0966
Iterate over the rows in Forecast.from_dataframe() 2026-12-01 14:49:15 +01:00
77806b14b9
Declare the name of the forecasting models as a class variable 2026-12-01 14:45:37 +01:00
081d6f7fd9
Type the time series of OrderHistory as pd.Series[int]
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m55s
2026-12-01 14:23:14 +01:00
7190724260
Enable the "possibly-undefined" error code 2026-12-01 13:11:32 +01:00
784d5c8ca0
Enable "warn_unreachable"
Also, remove the dead `isinstance()` check in `Location.relate_to()`
2026-12-01 13:07:53 +01:00
0a5f8f6c55
Enable "warn_return_any" 2026-12-01 12:39:45 +01:00
0d2aab4211
Use t.Self for methods returning their own class 2026-12-01 12:38:04 +01:00
76982126f4
Type the relationships of Restaurant 2026-12-01 12:38:04 +01:00
5ad3fb538d
Type the relationships of ReplaySimulation 2026-12-01 12:38:04 +01:00
4be6078327
Type the relationships of ReplayedOrder
Also, move the `db` import to the top, which makes some quotes unnecessary
2026-12-01 12:38:03 +01:00
699e7f0443
Type the relationships of Pixel 2026-12-01 12:38:03 +01:00
af0e3cf1a1
Type the relationships of Path 2026-12-01 12:38:03 +01:00
f45a444f83
Type the relationships of Order 2026-12-01 12:38:02 +01:00
9a2ec3d86b
Type the relationships of Grid 2026-12-01 12:38:02 +01:00
90c0597193
Type the relationships of Forecast
Also, move the `db` import to the top
2026-12-01 12:38:02 +01:00
bda9cf69ed
Type the relationships of Customer 2026-12-01 12:38:01 +01:00
99c8c2ac2e
Type the relationships of Courier 2026-12-01 12:38:01 +01:00
8f5d11db7f
Type the relationships of City 2026-12-01 12:38:01 +01:00
de86c2e64d
Type the relationships of AddressPixelAssociation 2026-12-01 12:38:01 +01:00
2e03e58716
Type the relationships of Address 2026-12-01 12:38:00 +01:00
6633067563
Turn the ORM Base into a real class 2026-12-01 12:38:00 +01:00
cd74b343bc
Replace the __future__ imports ...
... with quoted annotations where needed
2026-12-01 12:38:00 +01:00
e4016db9fe
Enable "no_implicit_reexport"
Also, remove the unused `orm_exc` import alias
2026-12-01 12:37:46 +01:00