Compare commits

...
Author SHA1 Message Date
753eaf23e4
Merge branch 'unquoted-annotations' into develop
All checks were successful
CI / Tests (test-types) (push) Successful in 1m45s
CI / Tests (test) (push) Successful in 1m47s
CI / Lint (push) Successful in 1m50s
CI / Tests (test-with-3.15) (push) Successful in 1m51s
Reviewed-on: #23
2026-12-03 13:10:48 +01:00
3b52ee0525
Remove the quotes from the type annotations
All checks were successful
CI / Tests (test-types) (push) Successful in 1m46s
CI / Tests (test) (push) Successful in 1m47s
CI / Tests (test-with-3.15) (push) Successful in 1m51s
CI / Lint (push) Successful in 2m8s
PEP 649 makes them unnecessary,
and `sqlalchemy` v2.1 resolves the lazy annotations of the models.
2026-12-03 13:04:17 +01:00
ed739ed756
Drop support for Python 3.13
Python 3.14 evaluates annotations lazily (PEP 649),
so forward references need no quotes.

We make the tool targets, the lock files,
and the CI matrix follow the new minimum.

In order to use the new features,
we must drop support for Python 3.13
2026-12-03 13:03:11 +01:00
2bfd936087
Merge branch 'lint-cleanups' into develop
All checks were successful
CI / Tests (test-types) (push) Successful in 2m4s
CI / Tests (test) (push) Successful in 2m8s
CI / Tests (test-with-3.15) (push) Successful in 2m12s
CI / Tests (test-with-3.13) (push) Successful in 2m21s
CI / Lint (push) Successful in 2m25s
Reviewed-on: #22
2026-12-03 12:26:18 +01:00
f9fce093d1
Skip the per-file ignores reformatting in git blame
All checks were successful
CI / Tests (test-types) (push) Successful in 2m8s
CI / Tests (test) (push) Successful in 2m11s
CI / Tests (test-with-3.15) (push) Successful in 2m15s
CI / Tests (test-with-3.13) (push) Successful in 2m22s
CI / Lint (push) Successful in 2m39s
2026-12-03 11:48:33 +01:00
47a22f9587
Put the ruff per-file ignores on separate lines
Each reason now sits next to its codes,
which reads better than a separate list.
2026-12-03 11:47:32 +01:00
7a000145a7
Lint the notebooks in the lint session
Only `ruff` checks them because the formatters would rewrite the cells.

The per-file ignores fit exploratory code that is never rerun.
2026-12-03 11:45:38 +01:00
a06cb5bdfb
Resolve the remaining ruff findings
Every change keeps the values the same, so the stored outputs stay valid.
`init_r` keeps its import because only its side effect matters.
2026-12-03 11:33:14 +01:00
f9643642b8
Use isna() and notna()
`isnull()` and `notnull()` are mere aliases,
so the stored outputs stay valid.
2026-12-03 11:33:10 +01:00
9c409b619e
Apply the safe ruff fixes
The fixes keep every value the same, so the stored outputs stay valid.
For example, `np.NaN` becomes `np.nan`, which `numpy` v2 requires.
2026-12-03 11:33:04 +01:00
50889df241
Skip the comment-only commits in git blame 2026-12-03 11:15:36 +01:00
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
51f68743e5
Reword the comments in the config files
Each comment is one sentence or two short ones
joined by "=>", without a final period.
2026-12-03 11:06:17 +01:00
bca4250b4d
Reword the comments in the test suite
Each comment is one sentence or two short ones
joined by "=>", without a final period.
2026-12-03 10:52:25 +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
ff7f705bc8
Put identifiers in comments into backticks 2026-12-03 10:17:12 +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
454c2898a0
Remove the F401 ignore for __init__.py files
All re-exporting packages declare `__all__`;
so, unused imports are reported there, too.
2026-12-03 09:48:27 +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
e5c7487515
Merge branch 'ci-and-infra' into develop
All checks were successful
CI / Tests (test-types) (push) Successful in 2m0s
CI / Tests (test) (push) Successful in 2m2s
CI / Tests (test-with-3.15) (push) Successful in 2m4s
CI / Tests (test-with-3.13) (push) Successful in 2m16s
CI / Lint (push) Successful in 2m16s
Reviewed-on: #21
2026-12-03 01:25:32 +01:00
8b5e66d70b
Install only nox and pre-commit in CI
All checks were successful
CI / Tests (test-types) (push) Successful in 2m3s
CI / Tests (test) (push) Successful in 2m6s
CI / Tests (test-with-3.15) (push) Successful in 2m10s
CI / Lint (push) Successful in 2m20s
CI / Tests (test-with-3.13) (push) Successful in 2m21s
The `nox` sessions install `velofy` and its dependencies themselves;
so, a full `uv sync` only duplicated that work.
2026-12-03 01:12:31 +01:00
53746966ac
Cache uv between CI runs
All jobs restore built wheels (e.g., `rpy2`) and the Python versions
instead of building or fetching them again.

Only the "lint" job saves the cache, pruned to what is expensive to rebuild,
and only when its key changed; so, five jobs do not compress the same archive
in parallel, and unchanged runs skip the 15s of packing.
2026-12-03 01:12:30 +01:00
e1cdac4cfa
Run the CI checks in parallel jobs
The test sessions run as a matrix, each with its own database.

This also adds the "test-with" sessions to CI;
so, the setup installs all `SUPPORTED_PYTHONS` via `uv`,
as `nox` would otherwise pick the system Python 3.13,
which lacks the headers to build `rpy2`.
2026-12-03 01:12:29 +01:00
49276bb9cf
Pull the CI setup into a composite action
The upcoming parallel jobs share it.
2026-12-03 01:12:28 +01:00
cc45b78e5d
Rename the CI job and add a timeout
The version in the name broke the required status check
when 3.14 became the `MAIN_PYTHON`.

The timeout ensures the CI server stays ready
even when something goes badly wrong.
2026-12-03 01:12:28 +01:00
9be63c3fef
Merge branch 'python-3.14' into develop
All checks were successful
CI / Checks (Python 3.14) (push) Successful in 2m43s
Reviewed-on: #20
2026-12-02 22:30:07 +01:00
2a64958a93
Make Python 3.14 the MAIN_VERSION
All checks were successful
CI / Checks (Python 3.14) (push) Successful in 2m46s
`requires-python` stays at ">=3.13"; so, `uv.lock` is unchanged
and 3.13 is tested with the "test-with" session.
2026-12-02 21:54:16 +01:00
df53ce7bc4
Pin MAIN_PYTHON in the "init-project" session
Otherwise, `uv` creates ".venv" with the newest installed Python.
2026-12-02 21:49:17 +01:00
67917ae3f6
Type check against the oldest Python version
Without a configured version, `mypy` and `pyright`
check against the Python that runs them.

With `MAIN_PYTHON` at 3.14, they would accept
`stdlib` APIs and `typing` features new in 3.14.

Yet, `requires-python` promises 3.13;
so, the type checkers must flag such code.

`black` and `ruff` already target 3.13 for the same reason.
2026-12-02 21:42:06 +01:00
b947337bd1
Remove flake8-return
It crashes on Python 3.14 (`ast.NameConstant` is gone) and is unmaintained.

`ruff` covers its rules.
2026-12-02 21:39:21 +01:00
80d2573f0d
Remove flake8-pie
It crashes on Python 3.14 (`ast.Str` is gone) and is unmaintained.

`ruff` covers its rules.
2026-12-02 21:27:27 +01:00
5609e8ec6e
Test with Python 3.14 and 3.15
The new "test-with" session runs the test suite with non-main Python versions;
yet, `MAIN_PYTHON` stays at 3.13
2026-12-02 17:43:05 +01:00
a85d426b6e
Merge branch 'alembic-api' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
Reviewed-on: #19
2026-12-02 14:05:17 +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
ef7b41e675
Merge branch 'directions-json' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
Reviewed-on: #18
2026-12-02 11:43:02 +01:00
664dccee02
Store the directions of paths as JSON arrays
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m46s
The data migration converts the 42 existing rows
from a JSON-encoded string into a JSON array.
2026-12-02 11:23:01 +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
2b1dd6af35
Merge branch 'sqlalchemy-select' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m46s
Reviewed-on: #17
2026-12-02 00:38:24 +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
9d98021b11
Request the db_session fixture
The test queries the database but relied on the
global `db.session` that the previous test had left behind.
2026-12-02 00:19:51 +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
c1f04c65aa
Count rows with select() in the tests
`Session.query()` is the legacy API in SQLAlchemy 2.x.
2026-12-01 23:17:57 +01:00
455af6dfdb
Merge branch 'orm-review' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m46s
Reviewed-on: #16
2026-12-01 23:06:03 +01:00
248c1ae600
Ignore the foreign keys into the original data
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
The migrations create foreign keys from the `CLEAN_SCHEMA`
into the `ORIGINAL_SCHEMA` to ensure the cleaned data still
refer to the original data.

The ORM models do not know the original tables.
Also, print the `diff` as indented JSON.
2026-12-01 22:58:01 +01:00
25ed8c744b
Recreate checks stored by an old PostgreSQL version
Before version 14, PostgreSQL stored `EXTRACT(...)` as `date_part(...)`,
and the rendering of `IN (...)` changed as well.

The checks created in 2021 express the same rules as the ORM models
but render differently. See the docstring of the migration for details.
2026-12-01 22:56:12 +01:00
69d3be4a53
Rename constraints to follow the naming convention
Earlier migrations named some constraints without `op.f()`,
a column rename did not rename the unique constraint containing the column,
and the "ordered_timestamps_N" checks in "orders" were shifted by one
compared to the ORM.

See the docstring of the migration for details.
2026-12-01 22:49:36 +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
2a627072d8
Make grids.side_length not nullable
The ORM always defined `Grid.side_length` with `nullable=False`,
but the migration that created the "grids" table did not; the
live database contains no `NULL`s.
2026-12-01 22:20:06 +01:00
db2e00216d
Simplify the docstrings of the migrations
The "Revision" and "Revises" lines and the revision hashes in `upgrade()`
and `downgrade()` repeated the `revision` and `down_revision` variables;
the creation date is in the file name.
2026-12-01 22:20:06 +01:00
f532aae588
Test grids with the same side length in different cities
Regression test for the removed `unique=True` on `Grid.side_length`.
2026-12-01 22:20:06 +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
731299bb6e
Add nox session "verify-db-objects"
The new "verify-db-objects" session creates the ORM objects
with `.create_all()` in a temporary database and compares
them with the `CLEAN_SCHEMA` of a "live" database using `sqlalchemy-diff`
2026-12-01 21:53:31 +01:00
69b9d53704
Merge branch 'add-typeguard' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m47s
Reviewed-on: #15
2026-12-01 17:54:25 +01:00
cfd8d33049
Rename the "doctest" session into "test-docstrings"
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m46s
2026-12-01 17:14:48 +01:00
f47c87f51f
Add the "test-types" session as a pre-commit hook 2026-12-01 17:14:47 +01:00
2f313e7e3a
Pull out the TEST_DEPENDENCIES 2026-12-01 17:13:14 +01:00
5f7d3108de
Check the type annotations at runtime with typeguard 2026-12-01 17:07:00 +01:00
893b6bd8f1
Seed the random fake data in the tests 2026-12-01 15:51:24 +01:00
e4711875ca
Use a pd.DataFrame as the sentinel in test_totals_is_cached 2026-12-01 15:46:54 +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
3b8b041a3e
Merge branch 'add-pyright' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m2s
Reviewed-on: #14
2026-12-01 15:18:18 +01:00
9a0dbb8ad8
Introduce TYPECHECK_LOCATIONS in the noxfile
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m2s
2026-12-01 15:05:54 +01:00
96b5a07f20
Add pyright to the "lint" session 2026-12-01 15:00:26 +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
c74a7b81f1
Merge branch 'stricter-mypy' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m56s
Reviewed-on: #13
2026-12-01 14:26:52 +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
d6b798a736
Type-check scripts/ 2026-12-01 14:05:34 +01:00
f7a6aa1881
Type-check noxfile.py 2026-12-01 14:03:44 +01:00
369957c06b
Narrow the untyped calls of folium.PolyLine 2026-12-01 13:38:00 +01:00
883a3ab8cc
Enable the "truthy-iterable" error code 2026-12-01 13:11:47 +01:00
9da2d0b703
Enable the "truthy-bool" error code 2026-12-01 13:11:46 +01:00
fef268321a
Enable the "redundant-expr" error code 2026-12-01 13:11:45 +01:00
7190724260
Enable the "possibly-undefined" error code 2026-12-01 13:11:32 +01:00
dafc695693
Enable the "mutable-override" error code 2026-12-01 13:11:31 +01:00
a4c1574135
Enable the "deprecated" error code 2026-12-01 13:11:30 +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
bbc00e2f1c
Enable "disallow_any_unimported" 2026-12-01 12:39:44 +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
ef0888619e
Enable PYI019 and PYI034 2026-12-01 12:37:54 +01:00
e4016db9fe
Enable "no_implicit_reexport"
Also, remove the unused `orm_exc` import alias
2026-12-01 12:37:46 +01:00
d9364eea9e
Set all "strict" options explicitly 2026-12-01 12:37:37 +01:00
7e4fe464f6
Merge branch 'pandas-stubs' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m55s
Reviewed-on: #12
2026-12-01 00:35:52 +01:00
2bc2408694
Type-check pandas with pandas-stubs
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m54s
2026-12-01 00:31:21 +01:00
01416a1175
Fix the type annotation of Forecast.from_dataframe() 2026-12-01 00:27:29 +01:00
f835b091b2
Merge branch 'upgrade-dependencies' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m52s
Reviewed-on: #11
2026-12-01 00:21:02 +01:00
ad56683166
Explain why black stays below v26
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m53s
2026-12-01 00:18:34 +01:00
83b5bd40a7
Upgrade various MINOR and PATCH versions 2026-12-01 00:05:39 +01:00
927ea56082
Merge branch 'more-lint-rules' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m53s
Reviewed-on: #10
2026-11-30 23:59:08 +01:00
6ecbd6860a
Add the flake8-only notes to the ruff section
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m52s
2026-11-30 23:50:12 +01:00
8d843895b7
Complete the ruff-only notes in the flake8 section 2026-11-30 23:50:05 +01:00
567bb713e2
Enable YTT in flake8 and ruff 2026-11-30 23:43:49 +01:00
57ac602612
Enable TRY in flake8 and ruff 2026-11-30 23:42:08 +01:00
1827e02f34
Enable TID in flake8 and ruff 2026-11-30 23:41:42 +01:00
4023f32662
Enable RSE in flake8 and ruff 2026-11-30 23:41:00 +01:00
e612e33f59
Enable PIE in flake8 and ruff 2026-11-30 23:40:15 +01:00
991543046d
Enable PGH in ruff 2026-11-30 23:39:08 +01:00
d55e72e04d
Enable LOG in flake8 and ruff 2026-11-30 23:38:43 +01:00
5c62c9919c
Enable G in ruff 2026-11-30 23:38:28 +01:00
33daa9cda7
Enable FLY in ruff 2026-11-30 23:38:13 +01:00
c32566527a
Enable EXE in flake8 and ruff 2026-11-30 23:37:54 +01:00
6ebcd69524
Enable BLE in ruff 2026-11-30 23:37:20 +01:00
ed53324a1d
Hide the capitalization commit from git blame 2026-11-30 23:28:04 +01:00
0090145b65
Capitalize the explanations after "=>" 2026-11-30 23:27:31 +01:00
c56fe649b7
Enable RUF in ruff 2026-11-30 23:17:41 +01:00
ae2dc8db64
Enable EM in flake8 and ruff 2026-11-30 22:59:41 +01:00
652713e702
Enable NPY in ruff 2026-11-30 22:49:41 +01:00
5beb88559f
Enable FBT in flake8 and ruff 2026-11-30 22:43:35 +01:00
d0326aee4f
Enable SLF in ruff 2026-11-30 22:38:26 +01:00
99dda74a9e
Enable PL in ruff 2026-11-30 22:28:12 +01:00
95f08bc96d
Enable PD in flake8 and ruff 2026-11-30 22:11:10 +01:00
f266adad45
Enable A in flake8 and ruff 2026-11-30 22:06:45 +01:00
00aff456c3
Enable FURB in ruff 2026-11-30 22:06:44 +01:00
0a4fd0edbc
Enable PERF in ruff 2026-11-30 22:06:44 +01:00
9cc21f5b69
Enable PTH in ruff 2026-11-30 22:06:43 +01:00
0cb924b3b6
Enable ISC in flake8 and ruff 2026-11-30 22:06:43 +01:00
3bd7dd5772
Enable RET in flake8 and ruff 2026-11-30 22:06:42 +01:00
007998372f
Enable SIM in flake8 and ruff 2026-11-30 22:06:41 +01:00
5dce8e6645
Enable UP in ruff 2026-11-30 21:28:31 +01:00
d0d5c92c55
Sort the ruff-only rule families by code 2026-11-30 20:50:21 +01:00
75824ea602
Merge branch 'unify-imports' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m54s
Reviewed-on: #9
2026-11-30 20:30:53 +01:00
31dda815d9
Ignore the import renames in git blame
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m52s
2026-11-30 20:25:54 +01:00
5c13d719cd
Enforce the established import aliases with ruff
These aliases were already in use before this branch
2026-11-30 20:22:06 +01:00
cf2534f41e
Import velofy.config as pkg_config everywhere 2026-11-30 20:19:35 +01:00
de5e49b497
Import alembic.config as alembic_config 2026-11-30 20:13:46 +01:00
dc45c689c4
Import alembic.command as alembic_cmd 2026-11-30 20:12:41 +01:00
e9743eaa01
Import rpy2.robjects.packages as r_packages 2026-11-30 20:06:09 +01:00
8bca30c836
Import rpy2.rinterface_lib.callbacks as r_callbacks 2026-11-30 20:04:44 +01:00
9b844b16e7
Import statsmodels.tsa.api as tsa
The alias in the `statsmodels` documentation
2026-11-30 20:03:25 +01:00
07e90b7851
Import click.testing as cli_testing
Like `click.core` as `cli_core`
2026-11-30 20:01:43 +01:00
07660ecff9
Import geopy.distance as geo_distance everywhere 2026-11-30 20:01:42 +01:00
d660f0cc4e
Import googlemaps as gm everywhere 2026-11-30 20:01:41 +01:00
d006752194
Enforce the import conventions with ruff
flake8 has no plugin with configurable aliases
2026-11-30 17:18:29 +01:00
5ca16ae47c
Import datetime as dt everywhere 2026-11-30 15:50:17 +01:00
f0c617955b
Use the nox module import 2026-11-30 15:44:05 +01:00
9c3b52befb
Import typing as t ...
... and `collections.abc` as `cabc`

Linting rule for `velofy`: Import modules instead of objects
2026-11-30 15:42:21 +01:00
c6518f6b39
Use builtin generics and X | None
Since Python 3.9 and 3.10, `list`, `tuple`, and `X | None`
replace `typing.List`, `typing.Tuple`, and `typing.Optional`
2026-11-30 15:07:47 +01:00
aa1a7c796f
Register the shared fixtures via pytest_plugins
That is the documented way to share fixtures from other modules,
instead of importing them into tests/conftest.py
2026-11-30 15:03:27 +01:00
0b2a1197a2
Import sqlalchemy.ext.hybrid as sa_hybrid 2026-11-30 14:22:42 +01:00
9d3af5e447
Import the postgresql dialect as psql 2026-11-30 14:21:01 +01:00
78e052b668
Use sa.func instead of importing func
Naming rule for `velofy`: Import modules instead of objects
2026-11-30 14:19:42 +01:00
e30b3efbe8
Use the sa alias for sqlalchemy everywhere
`sa` is the common alias, also in SQLAlchemy's own documentation
2026-11-30 14:18:05 +01:00
a85ba4c4c4
Merge branch 'fix-mypy' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m52s
Reviewed-on: #8
2026-11-30 14:13:43 +01:00
2b112f46e2
Remove the no longer used engine and connection globals
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m52s
Only `session` is used in the package.
Bound to the `engine`, it connects on its first query
instead of when the package is imported.
2026-11-30 14:03:26 +01:00
e9dbf528d7
Query order history via the db.session
The query then runs in the same transaction as the `db.session`

For that, `addresses_mock` now replaces only `session.query()`
instead of the whole `db.session`.
2026-11-30 13:59:34 +01:00
6119064d71
Remove obsolete exceptions from the mypy config
`nox` and `pytest` are not imported in the package,
and the other libraries ship their own types by now
2026-11-30 13:23:29 +01:00
570c9c9fcb
Run mypy in the "lint" session
It needs the dependencies of `velofy` installed,
and it now also reports "# type: ignore" comments without an error code
or that are not needed anymore
2026-11-30 13:15:27 +01:00
295a271ad7
Remove no longer needed "# type: ignore" comments
With the ORM columns annotated, `mypy` understands these lines on its own
2026-11-30 13:11:52 +01:00
607055d55a
Raise an error if Path._directions is not set ...
... instead of failing inside `json.loads()` on `None`
2026-11-30 12:50:31 +01:00
744d9a6353
Raise an error if an Order timestamp is not set
Like `Order.time_to_delivery` already does,
instead of failing with a `TypeError` on `None`
2026-11-30 12:43:33 +01:00
1c206a715b
Rename the restaurants list ...
... because it shadowed the `restaurants` parameter, a `bool`
2026-11-30 12:33:17 +01:00
a4d1f477ae
Return a bool from Order.corrected ...
... because the `or` chain over nullable columns could return `None`
2026-11-30 12:29:09 +01:00
e08272e6ab
Use dt for the datetime module in orders.py
Like in the other modules
2026-11-30 11:44:34 +01:00
1cc5dcff54
Avoid queries that may return None
The last `grid` of the loop already belongs to the `city`,
and `.scalar()` returns the maximum or `None` without indexing a row
2026-11-30 11:39:56 +01:00
82d245836f
Annotate the defaults in Address.draw()
The `**kwargs` for `folium.Circle()` are not all strings
2026-11-30 11:38:27 +01:00
a320c1fba5
Type the database placeholders for mypy
The test fixtures replace the `None` placeholders, and `velofy.configuration` already ensures that "DATABASE_URI" is set outside of tests
2026-11-30 11:36:01 +01:00
b5a6fb42cc
Accept any arguments in the R console callbacks
`rpy2` names the parameter `s`, so `_msg` did not match its signature
2026-11-30 11:33:59 +01:00
27171fe79a
Exclude folium from the "untyped-call" check
`folium` has no type annotations, so every call into it counted as untyped
2026-11-30 11:33:19 +01:00
c339719936
Annotate the ORM columns with orm.Mapped
Since SQLAlchemy 2.0, `orm.mapped_column()` with an annotation
lets `mypy` see `pixel.id` as an `int` instead of a `Column[int]`.
2026-11-30 11:22:04 +01:00
a8b4bca79d
Merge branch 'fix-sawarnings' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m44s
Reviewed-on: #7
2026-11-30 11:05:11 +01:00
c3198ecc48
Turn all warnings into errors
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m43s
New warnings, such as deprecations,
then fail right away instead of piling up.

The ignore for `patsy` is obsolete.
2026-11-30 10:56:56 +01:00
e01421bb96
Close the connection after running the migrations
The pooled `connection` stayed open until garbage collection,
which emits a `ResourceWarning`
2026-11-30 10:54:36 +01:00
ee5a372b2b
Link new objects from the parent
Since SQLAlchemy 2.0, only the parent's end
cascades a new object into the session'
2026-11-30 10:40:27 +01:00
87aaebe475
Join the session into the outer transaction
With "create_savepoint", commits inside a test case
only release a savepoint, so the final rollback no longer warns
2026-11-30 10:24:10 +01:00
fb87326d66
Merge branch 'add-ruff' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m43s
Reviewed-on: #6
2026-11-28 05:01:26 +01:00
a24db98262
Enable PLR in ruff
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m43s
2026-11-28 04:57:25 +01:00
8f36a740d7
Enable ERA in ruff
Dead code belongs in the history, not in comments
2026-11-28 04:55:19 +01:00
707b4ab652
Add flynt to the "format" session
`flynt` converts old-style string formatting
into f-strings before `black` formats the result
2026-11-28 04:49:16 +01:00
e451f03d0f
Add ruff to the "format" session
`ruff format` adds parentheses around multi-line lambda bodies
and removes blank lines after block openers,
both of which `black` accepts.

Lines with `# type:ignore` are shortened
because `black` counts pragma comments toward the line length
and `ruff` does not.
2026-11-28 04:44:52 +01:00
318dff8fc8
Add ruff to the "lint" session
`ruff` runs alongside `flake8` and `isort`,
with the rules aligned to theirs:
- `noqa` comments go where both tools expect them
- `import`s stay sorted case-insensitively,
  now stated explicitly in both tools
- `print()` in the "docs" session became `session.log()`
2026-11-28 04:37:25 +01:00
175d722071
Merge branch 'remove-wps' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m41s
Reviewed-on: #5
2026-11-28 04:16:01 +01:00
88554e3939
Silence the module name notice of bandit
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m41s
2026-11-28 04:11:56 +01:00
1a4dfb0ee7
Sort the plugins in the "select" list 2026-11-28 04:09:52 +01:00
4a81403f15
Replace darglint with pydoclint 2026-11-28 04:06:53 +01:00
3ec7ec8c98
Add pep8-naming 2026-11-28 03:54:49 +01:00
afe8b3ce90
Apply shared fixtures to whole test classes 2026-11-28 03:52:11 +01:00
882d3c98ba
Add flake8-unused-arguments
- Request fixtures only needed for their side effects
  via `@pytest.mark.usefixtures()` instead of as arguments
- Remove fixtures that a test does not use at all
- Exempt abstract methods because their arguments define an interface
2026-11-28 03:48:50 +01:00
29a711f049
Add flake8-todos 2026-11-28 03:37:25 +01:00
cb8f919b1f
Add flake8-sfs 2026-11-28 03:34:40 +01:00
650765a9d3
Add flake8-quotes 2026-11-28 03:28:50 +01:00
50a0e45309
Ignore the double quotes commit in git blame 2026-11-28 03:28:49 +01:00
ea8f1a13e3
Use double quotes 2026-11-28 03:26:13 +01:00
7b32ffc599
Add flake8-docstrings 2026-11-28 03:26:12 +01:00
efde4322bf
Add flake8-debugger 2026-11-28 03:26:12 +01:00
08493d1ea1
Add flake8-comprehensions 2026-11-28 03:26:12 +01:00
7f14c9c855
Add flake8-commas 2026-11-28 03:26:11 +01:00
cb110267f0
Add flake8-bugbear 2026-11-28 03:26:11 +01:00
d9d9464f44
Add flake8-broken-line 2026-11-28 03:26:11 +01:00
2000ceca54
Add flake8-bandit 2026-11-28 03:26:10 +01:00
137b3b1e03
Remove the config of flake8-expression-complexity 2026-11-28 03:26:10 +01:00
b24eb80f70
Remove the config of flake8-string-format 2026-11-28 03:26:10 +01:00
13eedbf699
Remove the config of flake8-rst-docstrings 2026-11-28 03:26:10 +01:00
21d6066086
Remove the config of flake8-isort 2026-11-28 03:26:09 +01:00
785bb99c7d
Remove the config of flake8-eradicate 2026-11-28 03:26:04 +01:00
9fcb3c8c14
Remove all "WPS" codes 2026-11-28 03:25:20 +01:00
8a5a652b3e
Run the local nox hooks serially 2026-11-28 02:00:30 +01:00
7c528d327e
Merge branch 'merge-message-template' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m40s
Reviewed-on: #4
2026-11-28 01:40:15 +01:00
253a12821e
Name merge commits after the merged branch
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m40s
2026-11-28 01:33:40 +01:00
0dc32da8c1
Merge pull request 'ci-no-merges-in-branches' (#3) from ci-no-merges-in-branches into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m39s
Reviewed-on: #3
2026-11-28 01:28:33 +01:00
30aac8e3c7
Use FORGEJO_... names in CI
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m40s
2026-11-28 01:26:18 +01:00
d158577984
Reject merge commits in feature branches 2026-11-28 01:24:44 +01:00
9e10a0c9aa
Merge pull request 'Run CI only on pushes' (#2) from ci-push-only into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m40s
Reviewed-on: #2
2026-11-28 01:15:37 +01:00
4fb96ee485
Run CI only on pushes
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m40s
2026-11-28 01:05:28 +01:00
c6ea7b13ec
Merge pull request 'Use language: unsupported for the local hooks' (#1) from use-language-unsupported into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m44s
Reviewed-on: #1
2026-11-28 01:01:41 +01:00
8265790d5d
Use language: unsupported for the local hooks
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m40s
CI / Checks (Python 3.13) (pull_request) Successful in 1m41s
2026-11-28 00:57:42 +01:00
5c3a942ad5
Merge branch 'rework-pre-commit' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m41s
2026-11-27 16:13:53 +01:00
2f0748e059
Rename ci.yml to ci.yaml
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m41s
2026-11-27 16:11:46 +01:00
d8edd58fe6
Reformat the pre-commit config
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m41s
Also, drop the no longer needed stage overrides
2026-11-27 16:05:19 +01:00
792da0507f
Run the pre-commit hooks in CI
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m42s
2026-11-27 15:15:11 +01:00
fbfb79d610
Export requirements.txt with pre-commit 2026-11-27 15:11:39 +01:00
08dd3b8218
Install all hook types with a plain pre-commit install 2026-11-27 14:59:25 +01:00
83007d458c
Add hooks for the "test" and "doctest" sessions 2026-11-27 14:52:05 +01:00
ff53af5001
Run the pre-commit hooks with uv 2026-11-27 14:36:34 +01:00
9adddd7959
Remove trailing whitespace 2026-11-27 14:29:29 +01:00
79f35ae3aa
Add missing newlines 2026-11-27 14:07:03 +01:00
079a9505ff
Update the pre-commit hooks 2026-11-27 13:59:44 +01:00
ed34e05cc7
Migrate the pre-commit config ...
... with `pre-commit migrate-config` to the new stage names
2026-11-27 13:56:09 +01:00
44eef9eafc
Remove the orphaned "fix-branch-references" hook 2026-11-27 13:55:26 +01:00
0ce8840bed
Merge branch 'rework-nox' into develop
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m31s
2026-11-27 13:47:25 +01:00
518811e138
Pin uv to the 0.13 series ...
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m31s
... to make CI more deterministic
2026-11-27 13:41:59 +01:00
b4e22dd0d4
Upgrade actions/checkout to v6
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m31s
2026-11-27 13:32:27 +01:00
6958cc6a58
Run the nox sessions
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m31s
2026-11-27 13:29:56 +01:00
045139a933
Rename the setup steps 2026-11-27 13:29:49 +01:00
aaeb9b1e72
Set UV_PYTHON_PREFERENCE for the whole job 2026-11-27 13:29:36 +01:00
a8c0e17bed
Wait for the database 2026-11-27 13:29:32 +01:00
ad8d43815e
Reorder the nox sessions ...
All checks were successful
CI / Tests (Python 3.13) (push) Successful in 1m6s
... as listed in the module docstring
2026-11-27 12:58:57 +01:00
7c2e21130f
Streamline the names, docstrings, and comments 2026-11-27 12:58:56 +01:00
689c8a8f42
Rewrite the module docstring 2026-11-27 12:58:56 +01:00
32f6540ec3
Add "doctest" session ...
... to run `xdoctest` against the `velofy` package.

Also, install `xdoctest` with only its "colors" extra
as the notebooks do not contain doctests.
2026-11-27 12:58:52 +01:00
110c6f755b
Streamline the "test" session
Rely on pyproject.toml for the `coverage` options,
and shorten the comments.
2026-11-27 12:48:53 +01:00
e7d93a5496
Do not run mypy for now 2026-11-27 12:48:52 +01:00
50d5b885bf
Rename the nox session functions ...
... and add type hints
2026-11-27 12:48:52 +01:00
2147dbf9d0
Replace the "clean-pwd" session with "clean-cwd" 2026-11-27 12:48:52 +01:00
ded4691177
Remove the "fix-branch-references" session ...
... and use relative links in the docs from now on.

Forgejo resolves relative links against the branch being viewed.
So, rewriting absolute links per branch is no longer necessary.
2026-11-27 12:48:51 +01:00
5f73b74d69
Add a "deps-upgrade-check" session ...
... to report the latest version on PyPI and the age of
every release pinned in uv.lock, using a stdlib-only script.
2026-11-27 12:48:51 +01:00
ebad87b0a3
Add a "deps-lock" session ...
... to lock the dependencies
2026-11-27 12:48:51 +01:00
d918063218
Add a "deps-upgrade" session ...
... to upgrade the pinned dependencies
2026-11-27 12:48:50 +01:00
f5f24ea611
Add a "venv" session ...
... to set up the local develop environment
2026-11-27 12:48:50 +01:00
6d2578ef80
Replace "safety" with "deps-audit"
`safety check` is deprecated.

We use `pip-audit` instead, fed with the hashed dependencies
exported from uv.lock.

We ignore the known vulnerabilities in `black` v25 for now.
2026-11-27 12:48:42 +01:00
60aa7911d2
Remove the CI and pre-commit specific nox sessions 2026-11-27 12:39:14 +01:00
99db2dc623
Run only the "format", "lint", and "test" sessions by default 2026-11-27 12:39:14 +01:00
f5a0a91202
Keep temporary files in .cache/tmp 2026-11-27 12:39:10 +01:00
b5db5ab80e
Set the nox options reuse_venv and stop_on_first_error
Start with fresh virtual environments explicitly,
and stop at the first failing session.
2026-11-26 13:41:53 +01:00
911107af95
Clarify where pytest gets the "TESTING" variable from 2026-11-26 13:41:53 +01:00
218d1d6078
Skip installs in nox only with the "-R" flag
Use `skip_install()` and remove the guards against "-r"
that were only needed for `poetry install --no-dev`.
2026-11-26 13:41:52 +01:00
7ad2e4ee26
Replace _begin() with start() 2026-11-26 13:41:52 +01:00
f6344ac4c5
Use uv in the nox sessions
Make `uv` the backend for the virtual environments,
and install the packages with the versions pinned in uv.lock,
exported into a constraints file with `uv export`,
instead of `poetry export` and `poetry install`.

Also, use `uv run` instead of `poetry run`.
2026-11-26 13:41:52 +01:00
935e3e28d6
Read the supported Python versions ...
... from pyproject.toml
2026-11-26 13:41:51 +01:00
4495da2b60
Add flake8-pyproject
Without it, `flake8` cannot read its config in pyproject.toml.
2026-11-26 13:41:51 +01:00
68ada518ea
Remove the obsolete "--ignore=I0" flag
It was only needed while `isort` v4 and v5 disagreed.
2026-11-26 13:41:51 +01:00
c5c8635c09
Remove wemake-python-styleguide 2026-11-26 13:41:51 +01:00
ed510eba7d
Remove the isort workaround
The `_isort_fix()` context manager was only needed for isort 4.
2026-11-26 13:41:50 +01:00
1dd2810ac7
Move the autoflake config 2026-11-26 13:41:50 +01:00
c4eae82e4d
Use SemVer-like versioning for the dependencies 2026-11-26 13:41:50 +01:00
355dfd993f
Switch from poetry to uv
Use the PEP 735 "[dependency-groups]" (here: "dev", "test", "docs")
instead of Poetry's "dev" group, and `uv_build` as the build backend.

Replace poetry.lock with uv.lock.

Also, adapt CI and the README.
2026-11-26 13:41:49 +01:00
afb17b61da
Merge branch 'integrate-setup-cfg' into develop
All checks were successful
CI / Tests (Python 3.13) (push) Successful in 1m13s
2026-11-25 15:09:21 +01:00
3adfa117a5
Remove the empty setup.cfg
All checks were successful
CI / Tests (Python 3.13) (push) Successful in 1m15s
2026-11-25 15:03:35 +01:00
c3f82deeab
Move the flake8 config
`flake8` cannot read pyproject.toml by itself,
so add `flake8-pyproject`.
2026-11-25 15:03:35 +01:00
c28d702a58
Move the isort config 2026-11-25 15:03:35 +01:00
74ddb54772
Move the mypy config 2026-11-25 15:03:35 +01:00
03617d5bbb
Move the pytest config 2026-11-25 15:03:34 +01:00
8771bb682e
Move the coverage config 2026-11-25 14:38:14 +01:00
63c9453ce7
Merge branch 'upgrade-dependencies-py313' into develop
All checks were successful
CI / Tests (Python 3.13) (push) Successful in 1m14s
2026-11-25 14:19:08 +01:00
eb62ff2048
Lock the major versions of all direct dependencies
All checks were successful
CI / Tests (Python 3.13) (push) Successful in 1m14s
Use ">=installed,<next major" as the version range,
the minor version for 0.x packages, and only
a lower bound for calendar-versioned packages.

`black` stays below v26 to keep 2 lines after the `import`s.

Also, remove the redundant `geopy` entry in the "dev" group.
2026-11-25 14:16:08 +01:00
645802bb7d
Update all transitive dependencies
`fonttools` v4.69.0 has no wheels for this environment yet,
so it stays at v4.68.0.
2026-11-25 14:10:41 +01:00
1faf140c30
Upgrade utm 2026-11-25 13:59:32 +01:00
d7c69f3f37
Upgrade statsmodels 2026-11-25 13:59:31 +01:00
0e2b8f75f8
Upgrade sqlalchemy
`sqlalchemy` v2.1 uses `psycopg` v3 as the default PostgreSQL driver.

So, we replace `psycopg2` with `psycopg`,
using its binary wheel that bundles `libpq`,
so CI no longer needs `libpq-dev` from `apt`.
2026-11-25 13:58:34 +01:00
f0d04c8a2a
Upgrade sphinx-autodoc-typehints 2026-11-25 13:42:35 +01:00
4be36d527f
Upgrade sphinx 2026-11-25 13:41:52 +01:00
505e29b855
Upgrade Shapely 2026-11-25 13:40:33 +01:00
bbe3f9af28
Upgrade pytest-mock 2026-11-25 13:24:37 +01:00
ec7473e87a
Upgrade pytest-env 2026-11-25 13:23:55 +01:00
dd50d7a62f
Upgrade pytest-cov 2026-11-25 13:23:14 +01:00
fbb7d078fa
Upgrade pytest 2026-11-25 13:22:31 +01:00
ea3e25a85b
Upgrade pre-commit 2026-11-25 13:21:44 +01:00
705955b38b
Upgrade pandas
Also, replace the deprecated "T" frequency alias with "min",
and access the trend by position with `.iloc`.
2026-11-25 13:16:55 +01:00
6290d280e2
Upgrade numpy 2026-11-25 12:59:24 +01:00
b6f570e13f
Upgrade mypy 2026-11-25 12:58:10 +01:00
746fe023e6
Upgrade matplotlib 2026-11-25 12:57:25 +01:00
ac3251867f
Upgrade isort 2026-11-25 12:54:53 +01:00
3e11980ab0
Upgrade folium 2026-11-25 12:53:32 +01:00
4516f54236
Upgrade flake8-pytest-style 2026-11-25 12:52:36 +01:00
5189a63bc3
Upgrade flake8-annotations 2026-11-25 12:51:00 +01:00
8cbd1fa979
Upgrade autoflake
This needed `flake8` to be upgraded first.
2026-11-25 12:49:47 +01:00
2f085f7450
Upgrade flake8 2026-11-25 12:46:14 +01:00
36264dc49c
Upgrade Faker 2026-11-25 12:46:07 +01:00
c310c335ff
Upgrade click
Since `click` v8.2, a `Group` invoked without a subcommand
exits with status code 2 ("usage error") instead of 0.
2026-11-25 12:45:59 +01:00
5710d12e21
Upgrade black
Pin to the 2025 series to keep the 2 lines after the `import`s.
Also, target Python 3.13.
2026-11-25 12:45:51 +01:00
5519c9030c
Upgrade alembic 2026-11-25 12:18:04 +01:00
6af7c4437d
Remove wemake-python-styleguide
No 0.x release of `wemake-python-styleguide` runs on Python 3.12+.

The current version pins `flake8-commas` to v2.x,
which crashes on the new f-string tokenizer.

The 1.x releases no longer bundle the `flake8` plug-ins this project uses.

The plug-ins are added back explicitly, one by one, on a separate branch.
2026-11-25 12:13:43 +01:00
042256eb99
Switch to Python 3.13
All checks were successful
CI / Tests (Python 3.13) (push) Successful in 1m17s
The dependencies stay in the same series as on Python 3.8
where those support 3.13.

Only the unavoidable upgrades are taken:
 - `matplotlib` to v3.9
 - `numpy` to v2.1
 - `pandas` to v2.2
 - `scipy` (via statsmodels)

Required code changes:
- `numpy` v2.1 prints its scalars as `np.float64(...)`,
  which `psycopg2` then writes into the SQL
  => Adjust `Forecast.from_dataframe()` to convert the
     rounded values into plain `float`s
- Python 3.12 no longer accepts `float`s in `random.randint()`
  => The test factories now pass the seconds as `int`s

CI and `nox` use a `u`v-managed Python, which ships the C headers
needed to build `psycopg2` and `rpy2`.

`flake8` v4 does not run on Python 3.12+
and is upgraded in a future commit.
2026-11-25 11:30:33 +01:00
34da92102f
Merge branch 'upgrade-dev-tools-py38' into develop
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m24s
2026-11-25 11:04:24 +01:00
d54f94a998
Upgrade pre-commit
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m24s
2026-11-25 11:01:35 +01:00
359d7be62a
Upgrade nox
The sessions in `noxfile.py` do not work since the migration to
Poetry 2: they use `poetry install --no-dev` and `poetry export`,
which Poetry 2 removed or moved into a plugin. The sessions are
reworked together with the other development tools.
2026-11-25 10:59:03 +01:00
9eecd371bc
Upgrade sphinx and sphinx-autodoc-typehints 2026-11-25 10:51:36 +01:00
94df768f74
Widen the version ranges for autoflake ...
... and two flake8 plugins

On Python 3.8, the three packages stay at the newest versions that work
with `flake8` v4, which `wemake-python-styleguide` v0.17 requires.
The lock file now also records their newer releases for newer Python versions.
The actual upgrade follows together with the switch to Python 3.13.
2026-11-25 10:44:08 +01:00
ffd72c9987
Upgrade isort
`isort` v5 honors the `single_line_exclusions = typing` setting in
`setup.cfg`, which `isort` v4 ignored.

So, the `typing` imports that were split onto separate lines to satisfy
`isort` v4 are combined again, as the configuration originally intended.
2026-11-25 10:31:24 +01:00
dbdce83067
Upgrade black 2026-11-25 10:30:47 +01:00
fad875b332
Merge branch 'upgrade-dependencies-py38' into develop
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m23s
2026-11-25 10:17:06 +01:00
685bb872a8
Update all transitive dependencies
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m24s
2026-11-25 10:09:42 +01:00
fc3fe900f6
Upgrade scipy 2026-11-25 09:19:42 +01:00
d8d5eecac9
Upgrade alembic 2026-11-25 09:18:19 +01:00
b2ce82f431
Upgrade the research extra 2026-11-24 17:29:21 +01:00
d33816302c
Upgrade xdoctest 2026-11-24 17:24:49 +01:00
71544f3088
Upgrade Faker 2026-11-24 17:24:48 +01:00
1d03d09a67
Upgrade factory-boy 2026-11-24 17:24:48 +01:00
b21ae1bf26
Upgrade pytest-mock 2026-11-24 17:24:48 +01:00
af6c639cc1
Upgrade pytest-env 2026-11-24 17:24:47 +01:00
e6130f4253
Upgrade pytest-cov 2026-11-24 17:24:47 +01:00
c895078837
Upgrade pytest 2026-11-24 17:24:43 +01:00
47b56550bc
Upgrade mypy 2026-11-24 17:24:42 +01:00
b7cfdcb1c0
Upgrade sqlalchemy to v2 2026-11-24 17:24:42 +01:00
e94ade4c88
Upgrade wemake-python-styleguide 2026-11-24 17:24:42 +01:00
fb2db07d37
Upgrade sqlalchemy to the latest v1.4 2026-11-24 17:24:41 +01:00
793f3105b1
Use sa.text() 2026-11-24 17:24:41 +01:00
46787de9bc
Use an explicit transaction 2026-11-24 17:24:41 +01:00
d8df96763c
Put each typing import on its own line ...
... as configured for `isort`
2026-11-24 17:24:40 +01:00
db1b23cd99
Annotate the type of steps for mypy 2026-11-24 17:24:40 +01:00
39cf160b95
Upgrade stevedore ...
... to fix the `bandit` plugin for `flake8`
2026-11-24 17:24:40 +01:00
f736e0e73b
Import declarative_base from sqlalchemy.orm 2026-11-24 17:24:39 +01:00
061832faa6
Upgrade pandas 2026-11-24 17:24:35 +01:00
fb912d12bb
Upgrade alembic
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 2m3s
2026-11-24 15:28:51 +01:00
b0cb3b412b
Upgrade folium 2026-11-24 15:27:40 +01:00
d4e8f17f0c
Upgrade click to v8 2026-11-24 15:26:24 +01:00
3e080c71c4
Upgrade shapely to v2 2026-11-24 15:22:58 +01:00
1db69037ba
Upgrade matplotlib 2026-11-24 15:20:55 +01:00
4224776f60
Upgrade numpy 2026-11-24 15:19:23 +01:00
4169da38b1
Upgrade statsmodels 2026-11-24 15:17:07 +01:00
706b0938c2
Upgrade packaging 2026-11-24 12:53:49 +01:00
c7f10f4c7f
Upgrade utm 2026-11-24 12:26:12 +01:00
4bc87eaf18
Upgrade rpy2 2026-11-24 12:22:24 +01:00
b44fc5f826
Upgrade googlemaps 2026-11-24 12:14:55 +01:00
629e3e6e3d
Upgrade geopy 2026-11-24 12:14:06 +01:00
dfc5cb7fb6
Upgrade ordered-set 2026-11-24 12:13:19 +01:00
9801baadee
Upgrade psycopg2 2026-11-24 12:12:10 +01:00
dcb2f82deb
Merge branch 'poetry-2' into develop
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m22s
2026-11-24 12:03:27 +01:00
95c760a0c3
Migrate to Poetry 2 and the standard [project] table
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m23s
2026-11-24 11:58:26 +01:00
754303ca71
Update the paper submodule to v1.0.2 2026-11-24 11:41:11 +01:00
5cc8a13719
Update the email address 2026-11-24 11:39:14 +01:00
3c6d3cbc65
Merge branch 'rename-to-velofy' into develop
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m39s
2026-11-24 11:16:26 +01:00
510c28c91e
Move the paper repository to Forgejo as velofy-forecasting 2026-11-24 11:15:38 +01:00
abc3ec5b3c
Rewrite the Forgejo links instead of GitHub links in the nox session 2026-11-24 11:15:20 +01:00
ce2cdd6f3e
Rename urban-meal-delivery into velofy in texts and notebook outputs 2026-11-24 10:56:25 +01:00
447533cceb
Point the links in the README, docs, and notebooks to Forgejo 2026-11-24 10:55:25 +01:00
8eb0dda0e1
Point the project URLs and texts to velofy 2026-11-24 10:34:32 +01:00
fa5b2690ad
Call the manage CLI in the notebooks 2026-11-24 10:28:38 +01:00
8e2536f45a
Replace the umd alias with velofy 2026-11-24 10:26:51 +01:00
e7a2d4a3cb
Rename the umd CLI into manage 2026-11-24 10:02:34 +01:00
4855209392
Rename the urban_meal_delivery package into velofy 2026-11-23 18:06:53 +01:00
a39d636876
Drop the temporary test schema in its own transaction
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m39s
2026-11-23 16:45:38 +01:00
f253c09f43
Run the test suite on the Forgejo runner
All checks were successful
CI / Tests (Python 3.8) (push) Successful in 1m44s
2026-11-23 16:27:04 +01:00
2a3450f537
Mark the Python 3.8 baseline
Some checks failed
CI / fast (without R) (push) Failing after 15s
CI / slow (with R) (push) Failing after 16s
2026-11-23 13:37:46 +01:00
830f44e3cc
Merge branch 'simulation-data' into develop
Some checks failed
CI / fast (without R) (push) Has been cancelled
CI / slow (with R) (push) Has been cancelled
2021-09-16 13:21:42 +02:00
419c7e6bf6
Add tests for the Order ORM model
- so far, the check constraints were untested
  + the tests mirror the tests for the `ReplayedOrder` model
    with some variations
- shorten some import names
- fix some typos
2021-09-16 12:05:22 +02:00
e4e543bd40
Add ORM models for the simulation data
- add new ORM models `ReplaySimulation` and `ReplayedOrder`
  to store the data generated by the routing simulations
- add migrations script to create the corresponding database tables
  + create "replay_simulations" and "replayed_orders" tables
  + add missing check constraints to "orders" table
  + add unique constraint to "orders" table to enable compound key
  + drop unnecessary check constraints from the "orders" table
- add tests for the new ORM models
  + add `simulation`, `replayed_order`, `make_replay_order()`, and
    `pre_order` fixtures
  + add `ReplayedOrderFactor` faker class
- fix some typos
2021-09-16 11:58:55 +02:00
41f75f507d
Use a unified DATE constant for convenience 2021-09-16 11:53:40 +02:00
f0eb9d3b6f
There is no 'too complex function'
We check a function's cognitive complexity only with `mccabe` (=C901)
and not with WPS231 as the two overlap in most cases.
2021-09-15 14:51:56 +02:00
6091ad95c6
Fix failing tests due to randomization 2021-09-15 12:00:03 +02:00
f891fac3dc
Refactor tests.db.fake_data.factories into a package 2021-09-15 11:58:17 +02:00
7e23033d84
There is no 'too deep nesting' 2021-09-15 11:58:13 +02:00
5978b0e92f
Modules are never 'too complex' 2021-09-15 11:47:38 +02:00
d03c2f91fb
Merge branch 'main' into develop 2021-09-13 11:37:37 +02:00
0f60640bc0
Show how the Google Maps API is integrated
Some checks failed
CI / fast (without R) (push) Has been cancelled
CI / slow (with R) (push) Has been cancelled
- show an example order's path from the restaurant to the customer's
  delivery address as it is travelled by a courier
- explain how to use the Google Maps API directly
- show how the API is integrated into the data model
2021-09-13 11:30:17 +02:00
f6b331883e
Merge branch 'release-0.4.0' into main
Some checks failed
CI / fast (without R) (push) Has been cancelled
CI / slow (with R) (push) Has been cancelled
2021-09-13 11:22:42 +02:00
5eabd541e8
Merge branch 'release-0.4.0' into develop 2021-09-13 11:22:01 +02:00
19d7b6f3cc
Finalize release 0.4.0 2021-09-13 11:20:53 +02:00
97b75f2579
Merge branch 'google-maps' into develop 2021-09-13 11:11:53 +02:00
d83ff2e273
Add Order.draw() and Path.draw()
- `Order.draw()` plots a `Courier`'s path from the
  `Order.pickup_address` to the `Order.delivery_address`
- `Path.draw()` plots a `Courier`'s path between any two
  `Address` objects
2021-09-13 10:33:35 +02:00
2449492aba
Add Path.from_order() convenience method
Special case of `Path.from_addresses()` to create a single
`Path` object from an `Order.restaurant` to the `Customer`.
2021-09-13 09:57:25 +02:00
2d324b77eb
Rename DistanceMatrix into Path
- a `Path` is a better description for an instance of the model
- the `Location`s en route are renamed into `.waypoints`
- generic `assoc` is renamed into `path` in the test suite
2021-09-12 17:33:48 +02:00
2d08afa309
Upgrade sqlalchemy
Adapt code to prevent new warnings and errors (as of SQLAlchemy 1.4):
- Overlapping foreign key columns could be set in a conflicting way
  => This is prevented by the application logic
  => Ignore the warning by setting a `overlaps` flag
- Transaction already rolled back
  => This only happens when tests cause an `IntegrityError` on purpose
  => Filter away the corresponding warning in the fixture
- Query returns `Row` objects and not scalars
  => Add genexpr to pull out `primary_id`
2021-09-12 16:52:51 +02:00
3bef9ca38d
Remove flake8-expression-complexity ...
... from the dev dependencies.

Longer queries in SQLAlchemy get flagged even though they are not
complicated. Other expressions are generally not that complicated.
2021-09-12 16:52:44 +02:00
1c19da2f70
Solve all issues detected by PyCharm
- as of September 2021, PyCharm is used to write some of the code
- PyCharm's built-in code styler, linter, and type checker issued
  some warnings that are resolved in this commit
  + spelling mistakes
  + all instance attributes must be specified explicitly
    in a class's __init__() method
    => use `functools.cached_property` for caching
  + make `tuple`s explicit with `(...)`
  + one test failed randomly although everything is ok
    => adjust the fixture's return value (stub for Google Directions API)
  + reformulate SQL so that PyCharm can understand the symbols
2021-09-12 16:51:12 +02:00
1268aba017
Pin the dependencies ...
... after upgrading:
- alembic
- geopy
- googlemaps
- psycopg2
- rpy2
- dev dependencies
  + coverage       + darglint      + flake8      + flake8-annotations
  + flake8-black   + flake8-comprehensions       + flake8-docstrings
  + flake8-pytest-style            + pre-commit  + pytest
  + pytest-cov     + pytest-mock   + sphinx      + sphinx-autodoc-typehints
- research dependencies
  + jupyterlab     + matplotlib    + numpy       + pandas
- transient dependencies
  + argcomplete    + argon2-cffi   + attrs       + babel
  + bleach         + certifi       + cffi        + cfgv
  + chardset-normalizer            + colorlog    + debugpy
  + decorator      + defusedxml    + distlib     + geographiclib
  + gitdb          + gitpython     + greenlet    + identify
  + idna           + importlib-resources         + ipykernel
  + ipython        + jinja2        + json5       + jupyter-client
  + kiwisolver     + mako          + markupsafe
  + nbclient       + nbconvert     + nbformat    + nodeenv
  + notebook       + parso         + pathspec    + pbr
  + pillow         + platformdirs  + pluggy      + prometheus-client
  + prompt-toolkit + pycodestyle   + pydocstyle  + pyflakes
  + pygments       + pyristent     + python-dateutil
  + pywin32        + pywinpty      + pyzmq       + regex
  + requests       + scipy         + send2trash  + six
  + smmap          + sphinxcontrib-htmlhelp
  + sphinxcontrib-serializinghtml  + stevedore   + terminado
  + textfixtures   + testpath      + traitlets   + typed-ast
  + typing-extensions              + tzdata      + tzlocal
  + urllib3        + virtualenv    + zipp
2021-09-12 16:51:12 +02:00
6636e56ec8
Upgrade flake8-pytest-style
The newly introduced "P023" error code must be disabled explicitly.
2021-09-12 16:51:11 +02:00
fa3b761054
Remove pytest-randomly from the dev dependencies
- problem: because of the randomization of test cases, every once in a
  while, the schema holding the test db already exists and cannot be
  created a second time (background: we run all tests against a db
  created with `metadate.create_all()` by SQLAlchemy at once and
  a db created by running all incremental Alchemy migration scripts)
- quick fix: possible, we could find a way to run all tests against
  one of the two test db's in random order and then against the other
  => in the interest of time, we simply do not randomize the test cases
2021-09-12 16:51:11 +02:00
322ce57062
Make mypy a bit stricter 2021-09-12 16:51:11 +02:00
2ba4914af7
Ignore PyCharm's .idea/ folder 2021-09-12 16:51:10 +02:00
db715edd6d
Add constructor for the DistanceMatrix class
- `DistanceMatrix.from_addresses()` takes a variable number of
  `Address` objects and creates distance matrix entries for them
- as a base measure, the air distance between two `Address`
  objects is calculated
- in addition, an integration with the Google Maps Directions API is
  implemented that provides a more realistic measure of the distance
  and duration a rider on a bicycle would need to travel between two
  `Address` objects
- add a `Location.lat_lng` convenience property that provides the
  `.latitude` and `.longitude` of an `Address` as a 2-`tuple`
2021-09-12 16:51:10 +02:00
5e9307523c
Add ordered-set to the dependencies 2021-09-12 16:51:10 +02:00
cc75307e5a
Add DistanceMatrix class
- the class stores the data of a distance matrix between all addresses
  + air distances
  + bicycle distances
- in addition, the "path" returned by the Google Directions API are
  also stored as a JSON serialized sequence of latitude-longitude pairs
- we assume a symmetric graph
2021-09-12 16:51:10 +02:00
28368cc30a
Add geopy to the dependencies 2021-09-12 16:51:09 +02:00
3dd848605c
Add googlemaps to the dependencies 2021-09-12 16:51:09 +02:00
6c03261b07
Merge branch 'main' into develop 2021-03-01 14:45:24 +01:00
f5ced933d6
Merge branch 'tactical-forecasting' into main
Some checks failed
CI / fast (without R) (push) Has been cancelled
CI / slow (with R) (push) Has been cancelled
2021-03-01 14:13:21 +01:00
9d6de9d98c
Create tactical demand forecasts
- the first notebook runs the tactical-forecasts command
- the second notebook describes the tactical demand forecasting process
  + demand aggregation on a per-pixel level
  + time series generation: horizontal, vertical, and real-time time series
  + STL decomposition into seasonal, trend, and residual components
  + choosing the most promising forecasting model
  + predicting demand with various models
- fix where to re-start the forecasting process after it was interrupted
- enable the heuristic for choosing the most promising model
  to also work for 7 training weeks
2021-02-09 17:06:37 +01:00
21d012050c
Add visualization scripts for customers/restaurants
- the two notebook files are helpful in visualizing all relevant
  pickup (red) or delivery (blue) locations from the point of view
  of either e restaurant or a customer
2021-02-04 16:19:12 +01:00
40471b883c
Add infos on tactical demand forecasting 2021-02-04 16:12:25 +01:00
915aa4d3b4
Merge branch 'release-0.3.0' into develop 2021-02-04 13:23:39 +01:00
169 changed files with 227676 additions and 213876 deletions

View file

@ -0,0 +1,52 @@
name: Set up `velofy`
description: Install R, `uv`, `nox`, and `pre-commit`
runs:
using: composite
steps:
- name: Install R via system packages
shell: bash
run: |
apt-get update
apt-get install --no-install-recommends \
r-base-dev \
r-cran-forecast \
r-cran-zoo \
-y
# Built wheels (e.g., `rpy2`) and Python versions, keyed by their pins
# => Only the "lint" job in ci.yaml saves the cache
- name: Restore the `uv` cache
id: uv-cache
uses: actions/cache/restore@v4
with:
path: |
~/.cache/uv
~/.local/share/uv/python
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock', 'pyproject.toml') }}
restore-keys: uv-${{ runner.os }}-
# Tell the "lint" job in ci.yaml the key and if it must save the cache
- name: Remember the `uv` cache key and if it was restored exactly
shell: bash
run: |
echo "UV_CACHE_KEY=${{ steps.uv-cache.outputs.cache-primary-key }}" >> "$FORGEJO_ENV"
echo "UV_CACHE_HIT=${{ steps.uv-cache.outputs.cache-hit }}" >> "$FORGEJO_ENV"
# All `SUPPORTED_PYTHONS` from the "classifiers" in pyproject.toml
# => `nox` would otherwise pick the system's Python without headers
- name: Install `uv` and all supported Python versions
shell: bash
run: |
curl -LsSf https://astral.sh/uv/0.13.10/install.sh | sh
echo "$HOME/.local/bin" >> "$FORGEJO_PATH"
"$HOME/.local/bin/uv" python install $(grep -oP 'Programming Language :: Python :: \K3\.\d+' pyproject.toml)
# The jobs only use `nox` and `pre-commit` from the develop environment
# => The `nox` sessions install `velofy` and its dependencies themselves
- name: Install `nox` and `pre-commit`
shell: bash
run: '"$HOME/.local/bin/uv" sync --locked --only-group dev'

View file

@ -0,0 +1,2 @@
Merge branch '${HeadBranch}' into ${BaseBranch}
${ReviewedOn}

117
.forgejo/workflows/ci.yaml Normal file
View file

@ -0,0 +1,117 @@
name: CI
# Run on every push, which also covers pull requests from this repository
on:
push:
# Use `bash` instead of the container's default `sh`
defaults:
run:
shell: bash
# Same variables as in `.env` on `nehemiah`, the main development machine
env:
DATABASE_URI: postgresql://user:password@postgres:5432/db
GOOGLE_MAPS_API_KEY: AIzaDummyKeyForTests # Fake key to mock the Google API
R_LIBS: /usr/lib/R/site-library
UV_NO_SYNC: "1" # Keep `uv run` from installing all groups (see the setup action)
UV_PYTHON_PREFERENCE: only-managed # Only uv's Python has the headers to build `rpy2`
jobs:
lint:
name: Lint
runs-on: debian-13
# Stop hanging jobs (e.g., a test waiting for a database lock)
timeout-minutes: 20
# Throwaway database, reachable from the job as host `postgres`
services: &database
postgres:
image: postgres:17
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: db
# Start the steps only once the database accepts connections
options: >-
--health-cmd "pg_isready --username=user --dbname=db"
--health-interval 2s
--health-timeout 5s
--health-retries 15
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all branches with their history for the next step
- name: Ensure feature branches contain no merge commits
if: forgejo.ref_name != 'develop' && forgejo.ref_name != 'main'
run: "! git rev-list --merges origin/develop..HEAD | grep ."
- uses: ./.forgejo/actions/setup
- name: Ensure `nox -s format` changes nothing
run: uv run nox -s format && git diff --exit-code
- name: Lint the source files
run: uv run nox -s lint
- name: Test the code snippets in the docstrings with `xdoctest`
run: uv run nox -s test-docstrings
- name: Run the `pre-commit` hooks not covered by `nox`
run: uv run pre-commit run --all-files --show-diff-on-failure
env:
SKIP: local-format,local-lint,local-test,local-test-docstrings,local-test-types,no-commit-to-branch
# Only this job saves the `uv` cache that ./.forgejo/actions/setup restores
# => Keep only what is expensive to rebuild, not wheels that are cheap to download
- name: Shrink the `uv` cache
if: env.UV_CACHE_HIT != 'true'
run: uv cache prune --ci
- name: Save the `uv` cache
if: env.UV_CACHE_HIT != 'true'
uses: actions/cache/save@v4
with:
path: |
~/.cache/uv
~/.local/share/uv/python
key: ${{ env.UV_CACHE_KEY }}
tests:
name: Tests (${{ matrix.session }})
runs-on: debian-13
# Stop hanging jobs (e.g., a test waiting for a database lock)
timeout-minutes: 20
# Run the sessions in parallel, each with its own database
strategy:
matrix:
session:
- test
- test-types
# One job per non-main Python version listed in the "classifiers"
# in pyproject.toml => Keep in sync manually
- test-with-3.15
# Same database as in the "lint" job
services: *database
steps:
- uses: actions/checkout@v6
- uses: ./.forgejo/actions/setup
- name: Run the `nox` session
run: uv run nox -s ${{ matrix.session }}

92
.git-blame-ignore-revs Normal file
View file

@ -0,0 +1,92 @@
# Mechanical commits that `git blame` skips
# => Enable locally with `git config blame.ignoreRevsFile .git-blame-ignore-revs`
# Use double quotes
ea8f1a13e34bfce01ea66951311e5f5fb5ab967f
# Use the `sa` alias for `sqlalchemy` everywhere
e30b3efbe8fc719f7d1d5bef32c69df67884f4d7
# Use `sa.func` instead of importing `func`
78e052b668d029204daeb17d0ded3938156f1f2b
# Import the `postgresql` dialect as `psql`
9d3af5e44719c88e4115c429d38e9e795de5bf05
# Import `sqlalchemy.ext.hybrid` as `sa_hybrid`
0b2a1197a2b089120f66ae2c8c365fac983192f4
# Use builtin generics and `X | None`
c6518f6b39386a7c803d0c2792fdae6d61436064
# Import `typing` as `t` ...
9c3b52befb51f91026accb9d4d3e0874ef6c3d23
# Use the `nox` module import
f0c617955bc8e9d46cd4126e0a334f1a28cc7849
# Import `datetime` as `dt` everywhere
5ca16ae47c63c06ac67b11908f813a544c377670
# Import `googlemaps` as `gm` everywhere
d660f0cc4ed6d9e62d0fe7c6d618322d57a1b049
# Import `geopy.distance` as `geo_distance` everywhere
07660ecff980932d082f82c43575fbfafc1172fe
# Import `click.testing` as `cli_testing`
07e90b7851e3c585270edf84b94fbb2998e51c46
# Import `statsmodels.tsa.api` as `tsa`
9b844b16e777ef643ea20f93f9fe415ecc51ff20
# Import `rpy2.rinterface_lib.callbacks` as `r_callbacks`
8bca30c83630a7136cba9c427d6bcc1dbffb2b7a
# Import `rpy2.robjects.packages` as `r_packages`
e9743eaa013362cd4e79b19dd7dd0c25ede11e73
# Import `alembic.command` as `alembic_cmd`
dc45c689c40ccfe98c2148f9ba08612612121083
# Import `alembic.config` as `alembic_config`
de5e49b497cc8f5904637fa5d913e2f8b331f2e8
# Import `velofy.config` as `pkg_config` everywhere
cf2534f41e9e535b8f68a38bb3e0ebadf3fb19b3
# Capitalize the explanations after "=>"
0090145b654c098cc464aed757e6c1fdda7487bd
# Remove periods from one-sentence comments
049a5f6f62e05f08ffdcb6ce90c1f07ec3042871
# Break multi-line comments before conjunctions
2f1afd459fe73c2ab4136acaa1f87ecf64212e9f
# Put identifiers in comments into backticks
ff7f705bc831734bbab63a43fd78a11121696bc5
# Reword the comments in `velofy.db`
1413d08ed9115501fa2757b97de23525581d9acf
# Reword the comments in `velofy.forecasts`
9b8fe8b8fd41e920954ce4cda5b2fd5e70b44185
# Reword the comments in the rest of `velofy`
0f6970922623a7bda82b78bb48d5fb05646e7d45
# Reword the comments in the test suite
bca4250b4d9512dde4f67996f21f4c4bc9c18387
# Reword the comments in the config files
51f68743e537a9ffa744f47e65313485b0ecd3c5
# Explain the "why" in a few more comments
f90f263dab12013cc1353381e6ee3258df5e9176
# Refer to sources with "See:" in comments
c18fc2ba59ed9286336da113604a98f423cbc32f
# Put the `ruff` per-file ignores on separate lines
47a22f9587f94fa5bc2705302a3e29dca3701dcf

View file

@ -1,32 +0,0 @@
name: CI
on: push
jobs:
fast-tests:
name: fast (without R)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8
architecture: x64
- run: pip install nox==2020.5.24
- run: pip install poetry==1.1.4
- run: nox -s format lint ci-tests-fast safety docs
slow-tests:
name: slow (with R)
runs-on: ubuntu-latest
env:
R_LIBS: .r_libs
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8
architecture: x64
- run: mkdir .r_libs
- run: sudo apt-get install r-base r-base-dev libcurl4-openssl-dev libxml2-dev patchelf
- run: R -e "install.packages('forecast')"
- run: pip install nox==2020.5.24
- run: pip install poetry==1.1.4
- run: nox -s ci-tests-slow

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
.cache/
**/*.egg-info/
.env
.idea/
**/.ipynb_checkpoints/
.python-version
.venv/

2
.gitmodules vendored
View file

@ -1,3 +1,3 @@
[submodule "research/papers/demand-forecasting"]
path = research/papers/demand-forecasting
url = git@github.com:webartifex/urban-meal-delivery-demand-forecasting.git
url = ssh://git@git.webartifex.de/alexander/velofy-forecasting.git

View file

@ -1,50 +1,109 @@
default_stages: [commit] # only used if a hook does not specify stages
# Hooks run by `git commit` and `git merge`,
# installed with `uv run nox -s init-project`
# Used by a plain `pre-commit install`
default_install_hook_types:
- pre-commit
- pre-merge-commit
# Used if a hook does not specify stages
default_stages:
- pre-commit
fail_fast: true
repos:
# Run the local formatting, linting, and testing tool chains.
- repo: local
hooks:
- id: local-fix-branch-references
name: Check for wrong branch references
entry: poetry run nox -s fix-branch-references --
language: system
stages: [commit]
types: [text]
- id: local-format
name: Format the source files
entry: poetry run nox -s format --
language: system
stages: [commit]
types: [python]
- id: local-lint
name: Lint the source files
entry: poetry run nox -s lint --
language: system
stages: [commit]
types: [python]
- id: local-test-suite
name: Run the entire test suite
entry: poetry run nox -s test-suite --
language: system
stages: [merge-commit]
types: [text]
# Enable hooks provided by the pre-commit project to
# enforce rules that local tools could not that easily.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-added-large-files
args: [--maxkb=100]
- id: check-case-conflict
- id: check-builtin-literals
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
stages: [commit] # overwrite the default
- id: mixed-line-ending
args: [--fix=no]
- id: no-commit-to-branch
args: [--branch, main]
- id: trailing-whitespace
stages: [commit] # overwrite the default
# Format, lint, and test with the `nox` sessions
- repo: local
hooks:
# `require_serial: true`
# => Parallel runs would recreate the same `nox` environment
- id: local-format
name: Format the source files
entry: uv run nox -s format --
language: unsupported
stages: [pre-commit]
types: [python]
require_serial: true
- id: local-lint
name: Lint the source files
entry: uv run nox -s lint --
language: unsupported
stages: [pre-commit]
types: [python]
require_serial: true
- id: local-test
name: Run the test suite
entry: uv run nox -s test
language: unsupported
stages: [pre-merge-commit]
pass_filenames: false # => No `--` at the end of the "entry"
always_run: true
require_serial: true
- id: local-test-docstrings
name: Run the doctests
entry: uv run nox -s test-docstrings
language: unsupported
stages: [pre-merge-commit]
pass_filenames: false # => No `--` at the end of the "entry"
always_run: true
require_serial: true
- id: local-test-types
name: Check the type annotations at runtime
entry: uv run nox -s test-types
language: unsupported
stages: [pre-merge-commit]
pass_filenames: false # => No `--` at the end of the "entry"
always_run: true
require_serial: true
# Keep requirements.txt in sync with uv.lock
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.13.10
hooks:
- id: uv-export
args:
- --extra=research
- --no-default-groups
- --no-emit-project
- --frozen
- --quiet
- --output-file=requirements.txt
# Generic checks that the "local" tools can not cover
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
args: [--maxkb=100]
exclude: ^requirements\.txt$ # Large because of the hashes
- id: check-builtin-literals
- id: check-case-conflict
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=no]
- id: no-commit-to-branch
args: [--branch, main]
- id: trailing-whitespace

View file

@ -1,4 +1,4 @@
Copyright (c) 2020 Alexander Hess [alexander@webartifex.biz]
Copyright (c) 2020 Alexander Hess [alexander@webartifex.de]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -16,19 +16,39 @@ that iteratively build on each other.
### Data Cleaning
The UDP provided its raw data as a PostgreSQL dump.
This [notebook](https://nbviewer.jupyter.org/github/webartifex/urban-meal-delivery/blob/develop/research/clean_data.ipynb)
This [notebook](research/01_clean_data.ipynb)
cleans the data extensively
and maps them onto the [ORM models](https://github.com/webartifex/urban-meal-delivery/tree/develop/src/urban_meal_delivery/db)
defined in the `urban-meal-delivery` package
that is developed in the [src/](https://github.com/webartifex/urban-meal-delivery/tree/develop/src) folder
and maps them onto the [ORM models](src/velofy/db)
defined in the `velofy` package
that is developed in the [src/](src) folder
and contains all source code to drive the analyses.
Due to a non-disclosure agreement with the UDP,
neither the raw nor the cleaned data are published as of now.
However, previews of the data can be seen throughout the [research/](https://github.com/webartifex/urban-meal-delivery/tree/develop/research) folder.
However, previews of the data can be seen throughout the [research/](research) folder.
### Real-time Demand Forecasting
### Tactical Demand Forecasting
Before any optimizations of the UDP's operations are done,
a **demand forecasting** system for *tactical* purposes is implemented.
To achieve that, the cities first undergo a **gridification** step
where each *pickup* location is assigned into a pixel on a "checker board"-like grid.
The main part of the source code that implements that is in this [file](src/velofy/db/grids.py#L60).
Visualizations of the various grids can be found in the [visualizations/](research/visualizations) folder
and in this [notebook](research/03_grid_visualizations.ipynb).
Then, demand is aggregated on a per-pixel level
and different kinds of order time series are generated.
The latter are the input to different kinds of forecasting `*Model`s.
They all have in common that they predict demand into the *short-term* future (e.g., one hour)
and are thus used for tactical purposes, in particular predictive routing (cf., next section).
The details of how this works can be found in the first academic paper
published in the context of this research project
and titled "*Real-time Demand Forecasting for an Urban Delivery Platform*"
(cf., the [repository](https://code.webartifex.de/alexander/velofy-forecasting) with the LaTeX files).
All demand forecasting related code is in the [forecasts/](src/velofy/forecasts) sub-package.
### Predictive Routing
@ -39,23 +59,23 @@ However, previews of the data can be seen throughout the [research/](https://git
To play with the code developed for the analyses,
you can clone the project with [git](https://git-scm.com/)
and install the contained `urban-meal-delivery` package
and install the contained `velofy` package
and all its dependencies
in a [virtual environment](https://docs.python.org/3/tutorial/venv.html)
with [poetry](https://python-poetry.org/docs/):
with [uv](https://docs.astral.sh/uv/):
`git clone https://github.com/webartifex/urban-meal-delivery.git`
`git clone ssh://git@git.webartifex.de/alexander/velofy.git`
and
`poetry install --extras research`
`uv sync --extra research`
The `--extras` option is necessary as the non-develop dependencies
are structured in the [pyproject.toml](https://github.com/webartifex/urban-meal-delivery/blob/develop/pyproject.toml) file
into dependencies related to only the `urban-meal-delivery` source code package
The `--extra` option is necessary as the non-develop dependencies
are structured in the [pyproject.toml](pyproject.toml) file
into dependencies related to only the `velofy` source code package
and dependencies used to run the [Jupyter](https://jupyter.org/) environment
with the analyses.
Contributions are welcome.
Use the [issues](https://github.com/webartifex/urban-meal-delivery/issues) tab.
The project is licensed under the [MIT license](https://github.com/webartifex/urban-meal-delivery/blob/develop/LICENSE.txt).
Use the [issues](https://code.webartifex.de/alexander/velofy/issues) tab.
The project is licensed under the [MIT license](LICENSE.txt).

View file

@ -1,15 +1,15 @@
"""Configure sphinx."""
import urban_meal_delivery as umd
import velofy
project = umd.__pkg_name__
author = umd.__author__
copyright = f'2020, {author}'
version = release = umd.__version__
project = velofy.__pkg_name__
author = velofy.__author__
project_copyright = f"2020, {author}"
version = release = velofy.__version__
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx_autodoc_typehints',
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx_autodoc_typehints",
]

View file

@ -9,7 +9,7 @@ Urban Meal Delivery
reference
This is the documentation for the `urban-meal-delivery` package
This is the documentation for the `velofy` package
that contains all the source code
used in a research project
residing in this `repository`_.
@ -25,13 +25,13 @@ All other software is automatically installed (cf., next section).
Installation
------------
The `urban-meal-delivery` package is installed
The `velofy` package is installed
only after cloning the `repository`_.
It is *not* available on `PyPI`_ via `pip`_.
.. code-block:: console
$ git clone https://github.com/webartifex/urban-meal-delivery.git
$ git clone ssh://git@git.webartifex.de/alexander/velofy.git
Use `poetry`_ to install the package
with its dependencies into a `virtual environment`_,
@ -91,5 +91,5 @@ You can use them to choose among the different tasks you want to achieve.
.. _poetry: https://python-poetry.org/docs/
.. _pypi: https://pypi.org/
.. _python: https://docs.python.org/3/
.. _repository: https://github.com/webartifex/urban-meal-delivery
.. _repository: https://code.webartifex.de/alexander/velofy
.. _virtual environment: https://docs.python.org/3/tutorial/venv.html

View file

@ -6,43 +6,41 @@ from logging import config as log_config
import sqlalchemy as sa
from alembic import context
from urban_meal_delivery import config as umd_config
from urban_meal_delivery import db
from velofy import config as pkg_config
from velofy import db
# Disable the --sql option, a.k.a, the "offline mode".
# Disable the --sql option, a.k.a, the "offline mode"
if context.is_offline_mode():
raise NotImplementedError('The --sql option is not implemented in this project')
msg = "The --sql option is not implemented in this project"
raise NotImplementedError(msg)
# Set up the default Python logger from the alembic.ini file.
# Set up the default Python logger from the alembic.ini file
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
type_ in {'table', 'column'}
and hasattr(obj, 'schema') # noqa:WPS421 => fix for rare edge case
and obj.schema != umd_config.CLEAN_SCHEMA
):
return False
return True
return not (
type_ in {"table", "column"}
and hasattr(obj, "schema") # => Fix for rare edge case
and obj.schema != pkg_config.CLEAN_SCHEMA
)
engine = sa.create_engine(umd_config.DATABASE_URI)
# Without a `pool`, the `connection` really closes after the migrations
engine = sa.create_engine(pkg_config.DATABASE_URI, poolclass=sa.pool.NullPool)
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='{alembic_table}{test_schema}'.format(
alembic_table=umd_config.ALEMBIC_TABLE,
test_schema=(f'_{umd_config.CLEAN_SCHEMA}' if os.getenv('TESTING') else ''),
),
version_table_schema=umd_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():

View file

@ -1,8 +1,4 @@
"""${message}.
Revision: # ${up_revision} at ${create_date}
Revises: # ${down_revision | comma,n}
"""
"""${message}."""
import os
@ -10,7 +6,8 @@ import sqlalchemy as sa
from alembic import op
${imports if imports else ""}
from urban_meal_delivery import configuration
from velofy import configuration
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
@ -18,14 +15,14 @@ branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
def upgrade():
"""Upgrade to revision ${up_revision}."""
"""Upgrade to the next revision."""
${upgrades if upgrades else "pass"}
def downgrade():
"""Downgrade to revision ${down_revision}."""
"""Downgrade to the previous revision."""
${downgrades if downgrades else "pass"}

View file

@ -1,167 +1,176 @@
"""Add pixel grid.
Revision: #888e352d7526 at 2021-01-02 18:11:02
Revises: #f11cd76d2f45
"""
"""Add pixel grid."""
import os
import sqlalchemy as sa
from alembic import op
from urban_meal_delivery import configuration
from velofy import configuration
revision = '888e352d7526'
down_revision = 'f11cd76d2f45'
revision = "888e352d7526"
down_revision = "f11cd76d2f45"
branch_labels = None
depends_on = None
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
def upgrade():
"""Upgrade to revision 888e352d7526."""
"""Upgrade to the next revision."""
op.create_table(
'grids',
sa.Column('id', sa.SmallInteger(), autoincrement=True, nullable=False),
sa.Column('city_id', sa.SmallInteger(), nullable=False),
sa.Column('side_length', sa.SmallInteger(), nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('pk_grids')),
"grids",
sa.Column("id", sa.SmallInteger(), autoincrement=True, nullable=False),
sa.Column("city_id", sa.SmallInteger(), nullable=False),
sa.Column("side_length", sa.SmallInteger(), nullable=True),
sa.PrimaryKeyConstraint("id", name=op.f("pk_grids")),
sa.ForeignKeyConstraint(
['city_id'],
[f'{config.CLEAN_SCHEMA}.cities.id'],
name=op.f('fk_grids_to_cities_via_city_id'),
onupdate='RESTRICT',
ondelete='RESTRICT',
["city_id"],
[f"{config.CLEAN_SCHEMA}.cities.id"],
name=op.f("fk_grids_to_cities_via_city_id"),
onupdate="RESTRICT",
ondelete="RESTRICT",
),
sa.UniqueConstraint(
'city_id', 'side_length', name=op.f('uq_grids_on_city_id_side_length'),
"city_id",
"side_length",
name=op.f("uq_grids_on_city_id_side_length"),
),
# This `UniqueConstraint` is needed by the `addresses_pixels` table below.
sa.UniqueConstraint('id', 'city_id', name=op.f('uq_grids_on_id_city_id')),
# This `UniqueConstraint` is needed by the `addresses_pixels` table below
sa.UniqueConstraint("id", "city_id", name=op.f("uq_grids_on_id_city_id")),
schema=config.CLEAN_SCHEMA,
)
op.create_table(
'pixels',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('grid_id', sa.SmallInteger(), nullable=False),
sa.Column('n_x', sa.SmallInteger(), nullable=False),
sa.Column('n_y', sa.SmallInteger(), nullable=False),
sa.CheckConstraint('0 <= n_x', name=op.f('ck_pixels_on_n_x_is_positive')),
sa.CheckConstraint('0 <= n_y', name=op.f('ck_pixels_on_n_y_is_positive')),
"pixels",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("grid_id", sa.SmallInteger(), nullable=False),
sa.Column("n_x", sa.SmallInteger(), nullable=False),
sa.Column("n_y", sa.SmallInteger(), nullable=False),
sa.CheckConstraint("0 <= n_x", name=op.f("ck_pixels_on_n_x_is_positive")),
sa.CheckConstraint("0 <= n_y", name=op.f("ck_pixels_on_n_y_is_positive")),
sa.ForeignKeyConstraint(
['grid_id'],
[f'{config.CLEAN_SCHEMA}.grids.id'],
name=op.f('fk_pixels_to_grids_via_grid_id'),
onupdate='RESTRICT',
ondelete='RESTRICT',
["grid_id"],
[f"{config.CLEAN_SCHEMA}.grids.id"],
name=op.f("fk_pixels_to_grids_via_grid_id"),
onupdate="RESTRICT",
ondelete="RESTRICT",
),
sa.PrimaryKeyConstraint('id', name=op.f('pk_pixels')),
sa.PrimaryKeyConstraint("id", name=op.f("pk_pixels")),
sa.UniqueConstraint(
'grid_id', 'n_x', 'n_y', name=op.f('uq_pixels_on_grid_id_n_x_n_y'),
"grid_id",
"n_x",
"n_y",
name=op.f("uq_pixels_on_grid_id_n_x_n_y"),
),
sa.UniqueConstraint('id', 'grid_id', name=op.f('uq_pixels_on_id_grid_id')),
sa.UniqueConstraint("id", "grid_id", name=op.f("uq_pixels_on_id_grid_id")),
schema=config.CLEAN_SCHEMA,
)
op.create_index(
op.f('ix_pixels_on_grid_id'),
'pixels',
['grid_id'],
op.f("ix_pixels_on_grid_id"),
"pixels",
["grid_id"],
unique=False,
schema=config.CLEAN_SCHEMA,
)
op.create_index(
op.f('ix_pixels_on_n_x'),
'pixels',
['n_x'],
op.f("ix_pixels_on_n_x"),
"pixels",
["n_x"],
unique=False,
schema=config.CLEAN_SCHEMA,
)
op.create_index(
op.f('ix_pixels_on_n_y'),
'pixels',
['n_y'],
op.f("ix_pixels_on_n_y"),
"pixels",
["n_y"],
unique=False,
schema=config.CLEAN_SCHEMA,
)
# This `UniqueConstraint` is needed by the `addresses_pixels` table below.
# This `UniqueConstraint` is needed by the `addresses_pixels` table below
op.create_unique_constraint(
'uq_addresses_on_id_city_id',
'addresses',
['id', 'city_id'],
"uq_addresses_on_id_city_id",
"addresses",
["id", "city_id"],
schema=config.CLEAN_SCHEMA,
)
op.create_table(
'addresses_pixels',
sa.Column('address_id', sa.Integer(), nullable=False),
sa.Column('city_id', sa.SmallInteger(), nullable=False),
sa.Column('grid_id', sa.SmallInteger(), nullable=False),
sa.Column('pixel_id', sa.Integer(), nullable=False),
"addresses_pixels",
sa.Column("address_id", sa.Integer(), nullable=False),
sa.Column("city_id", sa.SmallInteger(), nullable=False),
sa.Column("grid_id", sa.SmallInteger(), nullable=False),
sa.Column("pixel_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
['address_id', 'city_id'],
["address_id", "city_id"],
[
f'{config.CLEAN_SCHEMA}.addresses.id',
f'{config.CLEAN_SCHEMA}.addresses.city_id',
f"{config.CLEAN_SCHEMA}.addresses.id",
f"{config.CLEAN_SCHEMA}.addresses.city_id",
],
name=op.f('fk_addresses_pixels_to_addresses_via_address_id_city_id'),
onupdate='RESTRICT',
ondelete='RESTRICT',
name=op.f("fk_addresses_pixels_to_addresses_via_address_id_city_id"),
onupdate="RESTRICT",
ondelete="RESTRICT",
),
sa.ForeignKeyConstraint(
['grid_id', 'city_id'],
["grid_id", "city_id"],
[
f'{config.CLEAN_SCHEMA}.grids.id',
f'{config.CLEAN_SCHEMA}.grids.city_id',
f"{config.CLEAN_SCHEMA}.grids.id",
f"{config.CLEAN_SCHEMA}.grids.city_id",
],
name=op.f('fk_addresses_pixels_to_grids_via_grid_id_city_id'),
onupdate='RESTRICT',
ondelete='RESTRICT',
name=op.f("fk_addresses_pixels_to_grids_via_grid_id_city_id"),
onupdate="RESTRICT",
ondelete="RESTRICT",
),
sa.ForeignKeyConstraint(
['pixel_id', 'grid_id'],
["pixel_id", "grid_id"],
[
f'{config.CLEAN_SCHEMA}.pixels.id',
f'{config.CLEAN_SCHEMA}.pixels.grid_id',
f"{config.CLEAN_SCHEMA}.pixels.id",
f"{config.CLEAN_SCHEMA}.pixels.grid_id",
],
name=op.f('fk_addresses_pixels_to_pixels_via_pixel_id_grid_id'),
onupdate='RESTRICT',
ondelete='RESTRICT',
name=op.f("fk_addresses_pixels_to_pixels_via_pixel_id_grid_id"),
onupdate="RESTRICT",
ondelete="RESTRICT",
),
sa.PrimaryKeyConstraint(
'address_id', 'pixel_id', name=op.f('pk_addresses_pixels'),
"address_id",
"pixel_id",
name=op.f("pk_addresses_pixels"),
),
sa.UniqueConstraint(
'address_id',
'grid_id',
name=op.f('uq_addresses_pixels_on_address_id_grid_id'),
"address_id",
"grid_id",
name=op.f("uq_addresses_pixels_on_address_id_grid_id"),
),
schema=config.CLEAN_SCHEMA,
)
def downgrade():
"""Downgrade to revision f11cd76d2f45."""
op.drop_table('addresses_pixels', schema=config.CLEAN_SCHEMA)
"""Downgrade to the previous revision."""
op.drop_table("addresses_pixels", schema=config.CLEAN_SCHEMA)
op.drop_constraint(
'uq_addresses_on_id_city_id',
'addresses',
"uq_addresses_on_id_city_id",
"addresses",
type_=None,
schema=config.CLEAN_SCHEMA,
)
op.drop_index(
op.f('ix_pixels_on_n_y'), table_name='pixels', schema=config.CLEAN_SCHEMA,
op.f("ix_pixels_on_n_y"),
table_name="pixels",
schema=config.CLEAN_SCHEMA,
)
op.drop_index(
op.f('ix_pixels_on_n_x'), table_name='pixels', schema=config.CLEAN_SCHEMA,
op.f("ix_pixels_on_n_x"),
table_name="pixels",
schema=config.CLEAN_SCHEMA,
)
op.drop_index(
op.f('ix_pixels_on_grid_id'), table_name='pixels', schema=config.CLEAN_SCHEMA,
op.f("ix_pixels_on_grid_id"),
table_name="pixels",
schema=config.CLEAN_SCHEMA,
)
op.drop_table('pixels', schema=config.CLEAN_SCHEMA)
op.drop_table('grids', schema=config.CLEAN_SCHEMA)
op.drop_table("pixels", schema=config.CLEAN_SCHEMA)
op.drop_table("grids", schema=config.CLEAN_SCHEMA)

View file

@ -1,45 +1,41 @@
"""Add demand forecasting.
Revision: #e40623e10405 at 2021-01-06 19:55:56
Revises: #888e352d7526
"""
"""Add demand forecasting."""
import os
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects import postgresql as psql
from urban_meal_delivery import configuration
from velofy import configuration
revision = 'e40623e10405'
down_revision = '888e352d7526'
revision = "e40623e10405"
down_revision = "888e352d7526"
branch_labels = None
depends_on = None
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
def upgrade():
"""Upgrade to revision e40623e10405."""
"""Upgrade to the next revision."""
op.create_table(
'forecasts',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('pixel_id', sa.Integer(), nullable=False),
sa.Column('start_at', sa.DateTime(), nullable=False),
sa.Column('time_step', sa.SmallInteger(), nullable=False),
sa.Column('training_horizon', sa.SmallInteger(), nullable=False),
sa.Column('method', sa.Unicode(length=20), nullable=False),
sa.Column('prediction', postgresql.DOUBLE_PRECISION(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_forecasts')),
"forecasts",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("pixel_id", sa.Integer(), nullable=False),
sa.Column("start_at", sa.DateTime(), nullable=False),
sa.Column("time_step", sa.SmallInteger(), nullable=False),
sa.Column("training_horizon", sa.SmallInteger(), nullable=False),
sa.Column("method", sa.Unicode(length=20), nullable=False),
sa.Column("prediction", psql.DOUBLE_PRECISION(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_forecasts")),
sa.ForeignKeyConstraint(
['pixel_id'],
[f'{config.CLEAN_SCHEMA}.pixels.id'],
name=op.f('fk_forecasts_to_pixels_via_pixel_id'),
onupdate='RESTRICT',
ondelete='RESTRICT',
["pixel_id"],
[f"{config.CLEAN_SCHEMA}.pixels.id"],
name=op.f("fk_forecasts_to_pixels_via_pixel_id"),
onupdate="RESTRICT",
ondelete="RESTRICT",
),
sa.CheckConstraint(
"""
@ -49,48 +45,49 @@ def upgrade():
EXTRACT(HOUR FROM start_at) > 22
)
""",
name=op.f('ck_forecasts_on_start_at_must_be_within_operating_hours'),
name=op.f("ck_forecasts_on_start_at_must_be_within_operating_hours"),
),
sa.CheckConstraint(
'CAST(EXTRACT(MINUTES FROM start_at) AS INTEGER) % 15 = 0',
name=op.f('ck_forecasts_on_start_at_minutes_must_be_quarters_of_the_hour'),
"CAST(EXTRACT(MINUTES FROM start_at) AS INTEGER) % 15 = 0",
name=op.f("ck_forecasts_on_start_at_minutes_must_be_quarters_of_the_hour"),
),
sa.CheckConstraint(
'CAST(EXTRACT(MICROSECONDS FROM start_at) AS INTEGER) % 1000000 = 0',
name=op.f('ck_forecasts_on_start_at_allows_no_microseconds'),
"CAST(EXTRACT(MICROSECONDS FROM start_at) AS INTEGER) % 1000000 = 0",
name=op.f("ck_forecasts_on_start_at_allows_no_microseconds"),
),
sa.CheckConstraint(
'EXTRACT(SECONDS FROM start_at) = 0',
name=op.f('ck_forecasts_on_start_at_allows_no_seconds'),
"EXTRACT(SECONDS FROM start_at) = 0",
name=op.f("ck_forecasts_on_start_at_allows_no_seconds"),
),
sa.CheckConstraint(
'time_step > 0', name=op.f('ck_forecasts_on_time_step_must_be_positive'),
"time_step > 0",
name=op.f("ck_forecasts_on_time_step_must_be_positive"),
),
sa.CheckConstraint(
'training_horizon > 0',
name=op.f('ck_forecasts_on_training_horizon_must_be_positive'),
"training_horizon > 0",
name=op.f("ck_forecasts_on_training_horizon_must_be_positive"),
),
sa.UniqueConstraint(
'pixel_id',
'start_at',
'time_step',
'training_horizon',
'method',
"pixel_id",
"start_at",
"time_step",
"training_horizon",
"method",
name=op.f(
'uq_forecasts_on_pixel_id_start_at_time_step_training_horizon_method',
"uq_forecasts_on_pixel_id_start_at_time_step_training_horizon_method",
),
),
schema=config.CLEAN_SCHEMA,
)
op.create_index(
op.f('ix_forecasts_on_pixel_id'),
'forecasts',
['pixel_id'],
op.f("ix_forecasts_on_pixel_id"),
"forecasts",
["pixel_id"],
unique=False,
schema=config.CLEAN_SCHEMA,
)
def downgrade():
"""Downgrade to revision 888e352d7526."""
op.drop_table('forecasts', schema=config.CLEAN_SCHEMA)
"""Downgrade to the previous revision."""
op.drop_table("forecasts", schema=config.CLEAN_SCHEMA)

View file

@ -1,55 +1,54 @@
"""Add confidence intervals to forecasts.
Revision: #26711cd3f9b9 at 2021-01-20 16:08:21
Revises: #e40623e10405
"""
"""Add confidence intervals to forecasts."""
import os
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects import postgresql as psql
from urban_meal_delivery import configuration
from velofy import configuration
revision = '26711cd3f9b9'
down_revision = 'e40623e10405'
revision = "26711cd3f9b9"
down_revision = "e40623e10405"
branch_labels = None
depends_on = None
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
def upgrade():
"""Upgrade to revision 26711cd3f9b9."""
"""Upgrade to the next revision."""
op.alter_column(
'forecasts', 'method', new_column_name='model', schema=config.CLEAN_SCHEMA,
)
op.add_column(
'forecasts',
sa.Column('low80', postgresql.DOUBLE_PRECISION(), nullable=True),
"forecasts",
"method",
new_column_name="model",
schema=config.CLEAN_SCHEMA,
)
op.add_column(
'forecasts',
sa.Column('high80', postgresql.DOUBLE_PRECISION(), nullable=True),
"forecasts",
sa.Column("low80", psql.DOUBLE_PRECISION(), nullable=True),
schema=config.CLEAN_SCHEMA,
)
op.add_column(
'forecasts',
sa.Column('low95', postgresql.DOUBLE_PRECISION(), nullable=True),
"forecasts",
sa.Column("high80", psql.DOUBLE_PRECISION(), nullable=True),
schema=config.CLEAN_SCHEMA,
)
op.add_column(
'forecasts',
sa.Column('high95', postgresql.DOUBLE_PRECISION(), nullable=True),
"forecasts",
sa.Column("low95", psql.DOUBLE_PRECISION(), nullable=True),
schema=config.CLEAN_SCHEMA,
)
op.add_column(
"forecasts",
sa.Column("high95", psql.DOUBLE_PRECISION(), nullable=True),
schema=config.CLEAN_SCHEMA,
)
op.create_check_constraint(
op.f('ck_forecasts_on_ci_upper_and_lower_bounds'),
'forecasts',
op.f("ck_forecasts_on_ci_upper_and_lower_bounds"),
"forecasts",
"""
NOT (
low80 IS NULL AND high80 IS NOT NULL
@ -64,8 +63,8 @@ def upgrade():
schema=config.CLEAN_SCHEMA,
)
op.create_check_constraint(
op.f('prediction_must_be_within_ci'),
'forecasts',
op.f("prediction_must_be_within_ci"),
"forecasts",
"""
NOT (
prediction < low80
@ -80,8 +79,8 @@ def upgrade():
schema=config.CLEAN_SCHEMA,
)
op.create_check_constraint(
op.f('ci_upper_bound_greater_than_lower_bound'),
'forecasts',
op.f("ci_upper_bound_greater_than_lower_bound"),
"forecasts",
"""
NOT (
low80 > high80
@ -92,8 +91,8 @@ def upgrade():
schema=config.CLEAN_SCHEMA,
)
op.create_check_constraint(
op.f('ci95_must_be_wider_than_ci80'),
'forecasts',
op.f("ci95_must_be_wider_than_ci80"),
"forecasts",
"""
NOT (
low80 < low95
@ -106,19 +105,30 @@ def upgrade():
def downgrade():
"""Downgrade to revision e40623e10405."""
"""Downgrade to the previous revision."""
op.alter_column(
'forecasts', 'model', new_column_name='method', schema=config.CLEAN_SCHEMA,
"forecasts",
"model",
new_column_name="method",
schema=config.CLEAN_SCHEMA,
)
op.drop_column(
'forecasts', 'low80', schema=config.CLEAN_SCHEMA,
"forecasts",
"low80",
schema=config.CLEAN_SCHEMA,
)
op.drop_column(
'forecasts', 'high80', schema=config.CLEAN_SCHEMA,
"forecasts",
"high80",
schema=config.CLEAN_SCHEMA,
)
op.drop_column(
'forecasts', 'low95', schema=config.CLEAN_SCHEMA,
"forecasts",
"low95",
schema=config.CLEAN_SCHEMA,
)
op.drop_column(
'forecasts', 'high95', schema=config.CLEAN_SCHEMA,
"forecasts",
"high95",
schema=config.CLEAN_SCHEMA,
)

View file

@ -126,16 +126,16 @@ import os
from alembic import op
from urban_meal_delivery import configuration
from velofy import configuration
revision = 'e86290e7305e'
down_revision = '26711cd3f9b9'
revision = "e86290e7305e"
down_revision = "26711cd3f9b9"
branch_labels = None
depends_on = None
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
def upgrade():
@ -326,7 +326,7 @@ def upgrade():
""",
)
# 4) Ensure every `Restaurant` has only one `Order.pickup_address`.
# 4) Ensure every `Restaurant` has only one `Order.pickup_address`
op.execute(
f"""
UPDATE
@ -347,26 +347,26 @@ def upgrade():
""",
)
op.create_unique_constraint(
'uq_restaurants_on_id_address_id',
'restaurants',
['id', 'address_id'],
"uq_restaurants_on_id_address_id",
"restaurants",
["id", "address_id"],
schema=config.CLEAN_SCHEMA,
)
op.create_foreign_key(
op.f('fk_orders_to_restaurants_via_restaurant_id_pickup_address_id'),
'orders',
'restaurants',
['restaurant_id', 'pickup_address_id'],
['id', 'address_id'],
op.f("fk_orders_to_restaurants_via_restaurant_id_pickup_address_id"),
"orders",
"restaurants",
["restaurant_id", "pickup_address_id"],
["id", "address_id"],
source_schema=config.CLEAN_SCHEMA,
referent_schema=config.CLEAN_SCHEMA,
onupdate='RESTRICT',
ondelete='RESTRICT',
onupdate="RESTRICT",
ondelete="RESTRICT",
)
op.drop_constraint(
'fk_orders_to_restaurants_via_restaurant_id',
'orders',
type_='foreignkey',
"fk_orders_to_restaurants_via_restaurant_id",
"orders",
type_="foreignkey",
schema=config.CLEAN_SCHEMA,
)
@ -374,25 +374,25 @@ def upgrade():
def downgrade():
"""Downgrade to revision 26711cd3f9b9."""
op.create_foreign_key(
op.f('fk_orders_to_restaurants_via_restaurant_id'),
'orders',
'restaurants',
['restaurant_id'],
['id'],
op.f("fk_orders_to_restaurants_via_restaurant_id"),
"orders",
"restaurants",
["restaurant_id"],
["id"],
source_schema=config.CLEAN_SCHEMA,
referent_schema=config.CLEAN_SCHEMA,
onupdate='RESTRICT',
ondelete='RESTRICT',
onupdate="RESTRICT",
ondelete="RESTRICT",
)
op.drop_constraint(
'fk_orders_to_restaurants_via_restaurant_id_pickup_address_id',
'orders',
type_='foreignkey',
"fk_orders_to_restaurants_via_restaurant_id_pickup_address_id",
"orders",
type_="foreignkey",
schema=config.CLEAN_SCHEMA,
)
op.drop_constraint(
'uq_restaurants_on_id_address_id',
'restaurants',
type_='unique',
"uq_restaurants_on_id_address_id",
"restaurants",
type_="unique",
schema=config.CLEAN_SCHEMA,
)

View file

@ -9,33 +9,33 @@ import os
import sqlalchemy as sa
from alembic import op
from urban_meal_delivery import configuration
from velofy import configuration
revision = 'c2af85bada01'
down_revision = 'e86290e7305e'
revision = "c2af85bada01"
down_revision = "e86290e7305e"
branch_labels = None
depends_on = None
config = configuration.make_config('testing' if os.getenv('TESTING') else 'production')
config = configuration.make_config("testing" if os.getenv("TESTING") else "production")
def upgrade():
"""Upgrade to revision c2af85bada01."""
op.add_column(
'forecasts',
sa.Column('actual', sa.SmallInteger(), nullable=False),
"forecasts",
sa.Column("actual", sa.SmallInteger(), nullable=False),
schema=config.CLEAN_SCHEMA,
)
op.create_check_constraint(
op.f('ck_forecasts_on_actuals_must_be_non_negative'),
'forecasts',
'actual >= 0',
op.f("ck_forecasts_on_actuals_must_be_non_negative"),
"forecasts",
"actual >= 0",
schema=config.CLEAN_SCHEMA,
)
def downgrade():
"""Downgrade to revision e86290e7305e."""
op.drop_column('forecasts', 'actual', schema=config.CLEAN_SCHEMA)
op.drop_column("forecasts", "actual", schema=config.CLEAN_SCHEMA)

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