Pipelines (CLI)¶
Each module is a Click command registered under the src.pipelines group.
DVC calls these entrypoints via python -m src.pipelines <command> [args...].
Source¶
cli_load_data_from_source(output_path_matches, output_path_matches_raw)
¶
Run the load-data-from-source DVC stage.
Source code in src/pipelines/source.py
Preprocess¶
cli_export_metadata(input_path)
¶
Export match metadata (tournamentId, regionId maps) to DATA_METADATA_PATH.
Source code in src/pipelines/preprocess.py
cli_preprocessing(input_path, output_finished_path, output_future_path, reference_date)
¶
Run the preprocessing DVC stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
Path
|
Parquet of raw match records. |
required |
output_finished_path
|
Path
|
Destination for finished-match parquet. |
required |
output_future_path
|
Path
|
Destination for future-match feature parquet. |
required |
reference_date
|
Cutoff datetime separating finished from future
matches. Overrides |
required |
Source code in src/pipelines/preprocess.py
Features¶
cli_feature_engineering(input_path, output_path_features)
¶
Run the feature-engineering DVC stage.
Source code in src/pipelines/features.py
Validation (split)¶
cli_time_based_split(input_finished_path, input_features_path, output_dataset_path, output_train_ids_path, output_test_ids_path, output_folds_path)
¶
Run the time-based-split DVC stage.
Source code in src/pipelines/validation.py
Classification¶
cli_classification_models(input_dataset_path, input_train_ids_path, input_test_ids_path, input_folds_path, input_features_meta_path, output_run_id_path)
¶
Run the classification-models DVC stage.
Source code in src/pipelines/classification.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
Tuning¶
CLI entrypoints for hyperparameter tuning stages (XGBoost, LogReg, HGB).
cli_tune_xgb(input_dataset_path, input_train_ids_path, input_folds_path, input_features_meta_path, output_best_params_path)
¶
Run Optuna hyperparameter search for XGBoost and save best params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dataset_path
|
Path
|
Parquet dataset with features and train IDs. |
required |
input_train_ids_path
|
Path
|
Parquet with training match IDs. |
required |
input_folds_path
|
Path
|
Parquet with CV fold definitions. |
required |
input_features_meta_path
|
Path
|
Parquet features-meta table. |
required |
output_best_params_path
|
Path
|
Destination for the best-params JSON. |
required |
Source code in src/pipelines/tune.py
cli_tune_logreg(input_dataset_path, input_train_ids_path, input_folds_path, input_features_meta_path, output_best_params_path)
¶
Run Optuna hyperparameter search for LogisticRegression and save best params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dataset_path
|
Path
|
Parquet dataset with features and train IDs. |
required |
input_train_ids_path
|
Path
|
Parquet with training match IDs. |
required |
input_folds_path
|
Path
|
Parquet with CV fold definitions. |
required |
input_features_meta_path
|
Path
|
Parquet features-meta table. |
required |
output_best_params_path
|
Path
|
Destination for the best-params JSON. |
required |
Source code in src/pipelines/tune.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
cli_tune_hgb(input_dataset_path, input_train_ids_path, input_folds_path, input_features_meta_path, output_best_params_path)
¶
Run Optuna hyperparameter search for HistGradientBoosting and save best params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dataset_path
|
Path
|
Parquet dataset with features and train IDs. |
required |
input_train_ids_path
|
Path
|
Parquet with training match IDs. |
required |
input_folds_path
|
Path
|
Parquet with CV fold definitions. |
required |
input_features_meta_path
|
Path
|
Parquet features-meta table. |
required |
output_best_params_path
|
Path
|
Destination for the best-params JSON. |
required |
Source code in src/pipelines/tune.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
Final Training¶
CLI entrypoint for the final training stage.
Reads the winner from select_model stage (best_model.json) which contains the best model name, its tuned hyperparameters, and the CV log-loss score from fair Optuna competition across all candidates.
Retrains the winner on the full training set and evaluates once on the holdout. The holdout set is intentionally NOT touched before this stage.
cli_final_train(input_dataset_path, input_train_ids_path, input_test_ids_path, input_features_meta_path, input_best_model_path, output_final_run_id_path)
¶
Retrain the winning model on the full training set and evaluate on holdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dataset_path
|
Path
|
Parquet dataset with features and split IDs. |
required |
input_train_ids_path
|
Path
|
Parquet with training match IDs. |
required |
input_test_ids_path
|
Path
|
Parquet with holdout match IDs. |
required |
input_features_meta_path
|
Path
|
Parquet features-meta table. |
required |
input_best_model_path
|
Path
|
JSON written by the |
required |
output_final_run_id_path
|
Path
|
Destination for the final MLflow run ID JSON. |
required |
Source code in src/pipelines/final_train.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
Inference¶
CLI entrypoint for the batch inference (feature pre-computation) stage.
Computes ELO ratings and rolling statistics for all matches — both upcoming
(future) and completed (finished) — and writes the result to
data/predictions/match_features.parquet for the serving layer.
This stage is an INDEPENDENT BRANCH of the pipeline. It depends only on
preprocessing outputs (finished.parquet, future.parquet) and the
feature metadata produced by feature_engineering. It does NOT depend on
classification_models, tune_xgb, final_train, or register_model, and can
run in parallel with the training branch.
compute_all_match_features(df_finished, df_future, feature_columns, windows, stats_cols)
¶
Compute rolling features for ALL matches — upcoming and finished.
Finished matches carry actual outcome columns (outcome_1x2,
homeScore, awayScore) so the serving layer can compare
predictions against real results. Future matches have NaN for those
columns. An is_future boolean column distinguishes the two sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_finished
|
DataFrame
|
Completed matches with full stats and outcomes. |
required |
df_future
|
DataFrame
|
Upcoming matches without scores. |
required |
feature_columns
|
list[str]
|
Ordered list of feature names expected by the model. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame indexed by match |
DataFrame
|
metadata columns, outcome columns, and |
Source code in src/pipelines/inference.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
cli_batch_inference(input_future_path, input_finished_path, input_features_meta_path, output_path, output_predictions_path)
¶
Compute model features and predictions for all matches and save to parquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_future_path
|
Path
|
Parquet of future (upcoming) match records. |
required |
input_finished_path
|
Path
|
Parquet of finished match records. |
required |
input_features_meta_path
|
Path
|
Parquet features-meta table. |
required |
output_path
|
Path
|
Destination for the combined features parquet. |
required |
output_predictions_path
|
Path
|
Destination for the predictions parquet. |
required |
Source code in src/pipelines/inference.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
Register Model¶
DVC pipeline stage: register the best MLflow run in the Model Registry.
Reads run_id.json produced by classification_models, creates/updates a registered model version, and transitions it to the configured stage.
The operation is idempotent: re-running with the same run_id is safe.
cli_register_model(input_run_id_path, output_registered_model_path, model_name, stage)
¶
Register the best training run in the MLflow Model Registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_run_id_path
|
Path
|
JSON with the |
required |
output_registered_model_path
|
Path
|
Destination for the registered model metadata JSON. |
required |
model_name
|
str | None
|
MLflow registered model name. |
required |
stage
|
str | None
|
Initial alias or stage to assign (e.g. |
required |
Source code in src/pipelines/register_model.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
Data Validation (Great Expectations)¶
DVC pipeline stage: validate raw match data with Great Expectations.
Validates match_raw.parquet against the raw_match_suite expectation suite. Writes a JSON report to the output path and exits with code 1 on failure.
cli_validate_raw(input_path, output_report_path)
¶
Validate raw match data against Great Expectations suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
Path
|
Parquet of raw match records. |
required |
output_report_path
|
Path
|
Destination for the validation report JSON. |
required |
Exits with code 1 if any expectation fails.
Source code in src/pipelines/validate_raw.py
DVC pipeline stage: validate preprocessed finished matches with Great Expectations.
Validates interim/finished.parquet against the finished_suite. Writes a JSON report and exits with code 1 on any expectation failure.
cli_validate_finished(input_path, output_report_path)
¶
Validate preprocessed finished matches against Great Expectations suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
Path
|
Parquet of preprocessed finished match records. |
required |
output_report_path
|
Path
|
Destination for the validation report JSON. |
required |
Exits with code 1 if any expectation fails.
Source code in src/pipelines/validate_finished.py
DVC pipeline stage: validate preprocessed future matches with Great Expectations.
Validates interim/future.parquet against the future_match_suite. Writes a JSON report and exits with code 1 on any expectation failure, including the anti-leakage check (score columns must be absent).
cli_validate_future(input_path, output_report_path)
¶
Validate preprocessed future matches against Great Expectations suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
Path
|
Parquet of preprocessed future match records. |
required |
output_report_path
|
Path
|
Destination for the validation report JSON. |
required |
Also asserts that score and target columns are absent (anti-leakage). Exits with code 1 if any expectation fails.
Source code in src/pipelines/validate_future.py
DVC pipeline stage: validate engineered features with Great Expectations.
Validates features.parquet against two suites: 1. Static schema suite (row count) 2. Dynamic per-column suite (completeness + value ranges, built from features_meta)
Writes a combined JSON report and exits with code 1 on any failure.
cli_validate_features(input_features_path, input_meta_path, output_report_path)
¶
Validate engineered features against Great Expectations suites.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features_path
|
Path
|
Parquet with engineered feature columns. |
required |
input_meta_path
|
Path
|
Parquet features-meta table. |
required |
output_report_path
|
Path
|
Destination for the validation report JSON. |
required |
Exits with code 1 if any expectation fails.
Source code in src/pipelines/validate_features.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
Feature Metadata¶
Generate features_meta.parquet from configuration parameters only.
This stage is lightweight — it does not load any match data. Feature column names are derived deterministically from: - features.stats_cols - features.window_sizes - features.elo
This allows batch_inference to resolve its feature contract without depending on the heavy feature_engineering stage.
build_features_meta(stats_cols, window_sizes, elo_cfg)
¶
Build features_meta DataFrame from config, without loading match data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stats_cols
|
list[str]
|
Stat column names to generate windowed features for. |
required |
window_sizes
|
list[int]
|
Rolling window sizes to enumerate. |
required |
elo_cfg
|
dict
|
ELO configuration dict (expects |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns |
DataFrame
|
|
Source code in src/pipelines/features_meta.py
cli_generate_features_meta(output_path)
¶
Run the generate-features-meta DVC stage.
Source code in src/pipelines/features_meta.py
Model Selection & Promotion¶
DVC pipeline stage: select the best tuned model from all candidates.
Reads the tuning result files produced by tune_xgb, tune_logreg, and tune_hgb.
Each file contains best_params dict AND a cv_logloss metric written
by the corresponding tuning stage. This stage picks the candidate with the
lowest mean CV log-loss and writes data/models/best_model.json which
final_train reads to know which model to retrain on the full training set.
Design decisions¶
- Decision is based purely on CV log-loss (same objective used in all three Optuna studies), so the comparison is fully apples-to-apples.
- The output
best_model.jsoncontains bothmodel_nameandbest_paramssofinal_trainneeds only a single input file instead of three. - This stage is intentionally free of IO side-effects beyond writing the output file — no MLflow calls, no data reads.
cli_select_model(input_xgb_params_path, input_logreg_params_path, input_hgb_params_path, output_best_model_path)
¶
Compare tuned model CV scores and write best_model.json for the final_train stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_xgb_params_path
|
Path
|
JSON with best XGBoost tuning params. |
required |
input_logreg_params_path
|
Path
|
JSON with best LogisticRegression tuning params. |
required |
input_hgb_params_path
|
Path
|
JSON with best HGB tuning params. |
required |
output_best_model_path
|
Path
|
Destination for the best-model selection JSON. |
required |
Source code in src/pipelines/select_model.py
DVC pipeline stage: promote a registered model to the 'candidate' alias.
Quality gate¶
The new model's promote_model.metric (default: final.logloss) must not
exceed the current candidate's value by more than promote_model.tolerance
(default: 0.002).
Alias scheme¶
smoke — always assigned by register_model; used for CI smoke tests.
candidate — assigned here when the gate passes; safe for further manual review.
champion — reserved for manual promotion (human sign-off); never touched here.
If no current candidate exists the gate is skipped and promotion always proceeds (first model registered to a fresh registry).
Failure semantics¶
A gate failure is an expected outcome — the stage exits successfully and writes
promoted: false to the output JSON. The DVC pipeline does not fail.
Downstream stages that depend on a specific alias will find that the alias still
points to the previous candidate version.
cli_promote_model(input_registered_model_path, output_promoted_model_path)
¶
Promote a registered model version to the candidate alias
if quality gate passes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_registered_model_path
|
Path
|
JSON written by the |
required |
output_promoted_model_path
|
Path
|
Destination for the promotion result JSON. |
required |
Source code in src/pipelines/promote_model.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
Live Scraping¶
Pipeline entrypoint: scrape livescores and persist to PostgreSQL.
Runs in a KubernetesPodOperator pod using the API image (Selenoid remote Chrome).
Replaces the former update_livescores Celery task and PATCH /sources/livescores/.
Usage::
python -m src.pipelines.scrape_livescores --date-end 2026-05-12 --count-days 3 [--no-update-db] [--save-raw]
main(date_end, count_days, update_db, save_raw, timeout)
¶
Scrape livescores from 1xbet/WhoScored for a window of past dates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_end
|
str
|
Last date to scrape, formatted |
required |
count_days
|
int
|
Number of days to scrape backwards from |
required |
update_db
|
bool
|
Write parsed match records to PostgreSQL when |
required |
save_raw
|
bool
|
Upload raw HTML responses to MinIO when |
required |
timeout
|
int
|
Per-date Selenium page-load timeout in seconds. |
required |
Source code in src/pipelines/scrape_livescores.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
Odds Collection (Fonbet)¶
Pipeline entrypoint: collect fon.bet odds snapshot via Selenium and save to MinIO.
Launches a headless Chrome via Selenoid, injects a CDP fetch/XHR interceptor, navigates to the fon.bet football page, and saves all captured JSON responses as a gzip-compressed snapshot.
Usage::
python -m src.pipelines.collect_fonbet_odds
main()
¶
Collect daily fon.bet odds snapshot via Selenium and save to MinIO.
Source code in src/pipelines/collect_fonbet_odds.py
Pipeline: extract 1X2 odds from latest Fonbet snapshot for linked matches.
Reads match_links/fonbet_links.parquet to get the set of matched
fonbet_event_id values, then loads the latest Fonbet snapshot from MinIO
and extracts 1X2 coefficients (factors 921/922/923) for those events.
Output (upsert by fonbet_event_id):
s3://{MINIO_BUCKET_DATA_RAW}/match_links/fonbet_odds.parquet
Columns:
match_id int64 – site match ID
fonbet_event_id int64 – Fonbet event ID
odd_home float64 – factor 921 (win for home)
odd_draw float64 – factor 922 (draw)
odd_away float64 – factor 923 (win for away)
markets_count int64 – total number of markets for this event
snapshot_key str – MinIO key of the source snapshot
fetched_at datetime – UTC timestamp of this pipeline run
Run
python -m src.pipelines.fetch_fonbet_odds
main()
¶
Fetch Fonbet 1X2 odds for linked matches and write to MinIO.
Source code in src/pipelines/fetch_fonbet_odds.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
Pipeline entrypoint: link Fonbet odds snapshots to upcoming site matches.
For every match in the upcoming MATCH_WINDOW_DAYS window
(sourced from match_raw.parquet), finds the corresponding Fonbet event
using a three-layer fuzzy-matching strategy (country → league → teams) and
records the link in MinIO:
s3://{MINIO_BUCKET_DATA_RAW}/match_links/fonbet_links.parquet
Upsert semantics¶
An existing fonbet_links.parquet is loaded first.
- Rows where
fonbet_event_idis not null (already matched) are kept as-is — no re-matching is done. - Rows where
fonbet_event_idis null (previously unmatched) and any newmatch_idvalues not yet in the store are re-attempted against the latest Fonbet snapshot.
This makes the pipeline safely re-runnable and idempotent.
Usage::
python -m src.pipelines.link_fonbet_odds
Environment variables¶
MATCH_WINDOW_DAYS : int (default 3)
How many days ahead to include in the matching window.
FONBET_TIME_WINDOW_MIN : int (default 90)
±tolerance in minutes when comparing kick-off times.
FONBET_COUNTRY_THR : int (default 80)
Minimum fuzzy score to accept a site region → Fonbet country mapping.
FONBET_LEAGUE_THR : int (default 65)
Minimum fuzzy score to accept a site tournament → Fonbet league mapping.
FONBET_COMBINED_THR : int (default 75)
Minimum combined (home+away)/2 team score to accept a match.
FONBET_PER_TEAM_THR : int (default 40)
Minimum per-team score required alongside the combined threshold.
run_matching(df_site, df_fonbet_idx, *, time_window, country_thr, league_thr, combined_thr, per_team_thr)
¶
Match every row in df_site against df_fonbet_idx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_site
|
DataFrame
|
DataFrame of upcoming site matches with columns
|
required |
df_fonbet_idx
|
DataFrame
|
Fonbet event index with columns |
required |
time_window
|
Timedelta
|
Maximum allowed kick-off time difference. |
required |
country_thr
|
int
|
Fuzzy-score threshold for region → country mapping. |
required |
league_thr
|
int
|
Fuzzy-score threshold for tournament → league mapping. |
required |
combined_thr
|
int
|
Minimum (home+away)/2 combined team score. |
required |
per_team_thr
|
int
|
Minimum per-team score alongside |
required |
Returns:
| Type | Description |
|---|---|
DataFrame with one row per site match and columns
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Source code in src/pipelines/link_fonbet_odds.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
main()
¶
Run the Fonbet match-linking pipeline.
Source code in src/pipelines/link_fonbet_odds.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
Odds Loading (Football-Data.co.uk)¶
CLI entrypoint: download Bet365 closing odds from football-data.co.uk.
cli_load_odds_fdco(output_path)
¶
Download Bet365 closing odds from football-data.co.uk and save to parquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Destination parquet file path. |
required |
Reads leagues and seasons from params.yaml odds_fdco block.
Source code in src/pipelines/load_odds_fdco.py
Odds Export / Upload¶
Pipeline entrypoint: export a PostgreSQL table to MinIO as Parquet.
Replaces the former export_data_raw Celery task and GET /sources/export/{name_table}.
Usage::
python -m src.pipelines.export_to_storage --table match
python -m src.pipelines.export_to_storage --table match_raw
main(table)
¶
Export a PostgreSQL table to MinIO as a parquet file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Name of the PostgreSQL table to export. Must be one of
the tables listed in |
required |
Source code in src/pipelines/export_to_storage.py
CLI command: upload inference artifacts to MinIO after dvc repro.
Run immediately after dvc repro batch_inference in the inference pod so that
downstream pods (e.g. ml_live_betting_01) can download the artifacts without
re-running the full pipeline.
Artifacts uploaded¶
data/interim/finished.parquet→artifacts/finished.parquetdata/predictions/predictions.parquet→artifacts/predictions.parquet
Both are stored in MINIO_BUCKET_PREDICTIONS.
upload_artifacts()
¶
Upload finished.parquet and predictions.parquet to MinIO after dvc repro.
Source code in src/pipelines/upload_artifacts.py
Analysis & Reporting¶
CLI entrypoint for the error analysis stage.
Loads the registered champion model from MLflow, runs inference on the holdout set, slices errors by league (tournamentId), region (regionId), Elo gap bins, season, and home/away. Writes a Markdown report and figures.
This stage is OPTIONAL in the pipeline — it does not gate registration.
cli_error_analysis(input_dataset_path, input_test_ids_path, input_features_meta_path, output_predictions_path, output_report_dir, data_dir, metadata_dir, roi_analysis_dir)
¶
Run error analysis on holdout set and write Markdown report + figures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dataset_path
|
Path
|
Parquet dataset with features and holdout IDs. |
required |
input_test_ids_path
|
Path
|
Parquet with holdout match IDs. |
required |
input_features_meta_path
|
Path
|
Parquet features-meta table. |
required |
output_predictions_path
|
Path
|
Destination for holdout predictions parquet. |
required |
output_report_dir
|
Path
|
Directory for the Markdown report and figures. |
required |
data_dir
|
Path
|
Directory containing DVC-versioned data artifacts. |
required |
metadata_dir
|
Path
|
Directory with |
required |
roi_analysis_dir
|
Path | None
|
Optional directory for ROI sub-report artifacts. |
required |
Source code in src/pipelines/error_analysis.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
CLI entrypoint for the ROI analysis stage.
Depends only on the holdout predictions saved by error_analysis and the Bet365 closing odds from football-data.co.uk (load_odds_fdco stage).
Separation rationale¶
Changing odds configuration (seasons, leagues) should not force a full model pipeline rerun. This stage runs independently of all ML stages — it only needs the holdout_predictions.parquet output of error_analysis plus the odds file.
Usage (standalone): dvc repro roi_analysis
cli_roi_analysis(input_predictions_path, input_odds_path, input_dataset_path, output_report_dir, data_dir, metadata_dir, error_analysis_dir)
¶
Compute ROI simulation against Bet365 closing odds on the holdout set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_predictions_path
|
Path
|
Parquet with holdout predictions. |
required |
input_odds_path
|
Path
|
Parquet with Bet365 closing odds. |
required |
input_dataset_path
|
Path
|
Full dataset parquet (for region/ELO enrichment). |
required |
output_report_dir
|
Path
|
Directory for report artifacts. |
required |
data_dir
|
Path
|
Directory containing DVC-versioned data artifacts. |
required |
metadata_dir
|
Path
|
Directory with segment lookup JSON files. |
required |
error_analysis_dir
|
Path | None
|
Optional directory for error-analysis sub-reports. |
required |
Source code in src/pipelines/roi_analysis.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
CLI entrypoint for live betting strategy simulation on Fonbet odds.
Joins model predictions (batch_inference) with actual Fonbet live odds to simulate flat-stake and fractional-Kelly betting strategies on finished matches.
This stage is intentionally NOT part of the DVC graph: Fonbet odds accumulate
continuously, and the simulation can be re-run at any time as new match results
arrive. Run via make live-betting or directly::
python -m src.pipelines.live_betting \
--fonbet-odds-path data/predictions/fonbet_odds.parquet
All analysis CSVs are written to data/analysis/live_betting/ by default.
cli_live_betting(predictions_path, finished_path, fonbet_odds_path, output_dir, metadata_dir, min_edge, min_bets, kelly_fraction, initial_bankroll, error_analysis_dir)
¶
Simulate flat-stake and Kelly betting strategies on live Fonbet odds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions_path
|
Path
|
Parquet with batch-inference predictions. |
required |
finished_path
|
Path
|
Parquet of finished match records. |
required |
fonbet_odds_path
|
Path
|
Parquet with Fonbet 1X2 odds. |
required |
output_dir
|
Path
|
Directory for output CSVs and reports. |
required |
metadata_dir
|
Path
|
Directory with segment lookup files. |
required |
min_edge
|
float
|
Minimum model-implied edge to place a bet. |
required |
min_bets
|
int
|
Minimum bets required to include a segment in reports. |
required |
kelly_fraction
|
float
|
Fractional Kelly coefficient. |
required |
initial_bankroll
|
float
|
Starting bankroll for Kelly simulation. |
required |
error_analysis_dir
|
Path | None
|
Optional directory with per-segment error CSVs. |
required |
Source code in src/pipelines/live_betting.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
Monitoring (Pipeline Stages)¶
DVC pipeline stage: monitor feature drift using Evidently.
Resolves the champion model's run_id from the MLflow Model Registry, loads recent production feature records from data/predictions/match_features.parquet, runs Evidently drift analysis, writes results to reports/, and updates the model_feature_drift_score Prometheus metric via a textfile collectd can scrape.
Usage (DVC-managed, see dvc.yaml):
python -m src.pipelines cli-monitor-drift \
The stage is also triggered after batch inference by airflow/dags/ml_monitor_drift_01.py (KubernetesPodOperator, same CLI entrypoint).
cli_monitor_drift(input_predictions_features_path, output_drift_json_path, output_report_dir, metrics_textfile, stattest_threshold)
¶
Compute feature drift between reference and recent production features.
The champion model's run_id is resolved live from the MLflow Model Registry (model name and alias from config / env vars), so no local artifact file is required. This makes the command safe to run inside ephemeral Kubernetes pods that start with an empty data volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_predictions_features_path
|
Path
|
Parquet of recent production features (batch_inference output). |
required |
output_drift_json_path
|
Path
|
Destination for the drift summary JSON. |
required |
output_report_dir
|
Path
|
Directory for the full Evidently HTML report. |
required |
metrics_textfile
|
Path | None
|
Optional path for a DVC-metrics text file. |
required |
stattest_threshold
|
float
|
Evidently p-value threshold for drift detection. |
required |
Source code in src/pipelines/monitor_drift.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
CLI entrypoint: monitor ML quality on finished production matches.
Downloads predictions and finished match results, joins them, computes classification quality metrics across rolling windows, writes a Prometheus textfile, and saves an Evidently HTML report.
Usage::
python -m src.pipelines monitor-ml-quality \
--predictions-path data/predictions/predictions.parquet \
--finished-path data/interim/finished.parquet \
--output-dir data/analysis/ml_quality
Triggered daily by airflow/dags/ml_monitor_quality_01.py.
cli_monitor_ml_quality(predictions_path, finished_path, output_dir, evidently_report_dir, metrics_textfile)
¶
Compute ML quality metrics for rolling windows and write monitoring outputs.
Source code in src/pipelines/monitor_ml_quality.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
Internal¶
Minimal configuration for ML pipeline stages.
Reads only the env vars required by training/evaluation pipelines: MLflow tracking URI, MinIO credentials, and model registry defaults.
Intentionally isolated from src.app.config (which instantiates
DatabaseSettings and other app-layer services not needed during training).
Extends src.shared.config.SharedInfraConfig to avoid duplicating the
four shared env-var field declarations.
PipelineConfig
¶
Bases: SharedInfraConfig
Settings used exclusively by DVC pipeline stages.
Inherits from SharedInfraConfig
- mlflow_tracking_uri (MLFLOW_TRACKING_URL)
- minio_endpoint_url (MINIO_ENDPOINT_URL)
- minio_access_key (MINIO_USER)
- minio_secret_key (MINIO_PASSWORD)
Adds pipeline-specific model-registry defaults:
Source code in src/pipelines/_config.py
get_pipeline_config()
cached
¶
Return the pipeline config singleton (lazy, cached).
Deferred instantiation prevents pydantic-settings from validating required env vars at import time. Pipeline stages that do not need MLflow / MinIO (e.g. load_data_from_sources) import this module without triggering a ValidationError just because their sibling modules do.
Use get_pipeline_config.cache_clear() in tests to reset the cache
after changing env vars with monkeypatch.
Returns:
| Type | Description |
|---|---|
Singleton
|
class: |