feat(storage): migrate project to sqlite

This commit is contained in:
dasemu committed 2026-03-13 06:50:18 +01:00
1 parent 1bc1e58781
commit 9c8ba03574
17 files changed
+1204 -688

No files matched your search

+16 -11
View File
@@ -35,10 +35,10 @@ This downloads 16+ seasons of station data from infonieve.es, fetches matching h
.venv/bin/python scripts/build_full_dataset.py
```
Step 2 fetches weather data from Open-Meteo in 1-year chunks. Each chunk is cached in `data/raw/weather_cache/`, so reruns skip already-fetched years. First run may need 15-20 min due to API rate limits. Subsequent runs are fast.
Step 2 fetches weather data from Open-Meteo in 1-year chunks and persists the full historical state in SQLite. First run may need 15-20 min due to API rate limits. Subsequent runs reuse the database cache.
Output:
- `data/processed/dataset_featured.csv` - Full dataset with engineered features
- `data/processed/skipredictor.db` - SQLite database with historical/runtime datasets, predictions, and reports
- `ml/models/station_open_model.joblib` - Open/closed classifier (RandomForest)
- `ml/models/km_open_model.joblib` - Km open regressor (GradientBoosting)
- `ml/models/crowd_level_model.joblib` - Crowd classifier (LightGBM)
@@ -52,7 +52,7 @@ As the daily pipeline collects new data, retrain periodically to improve the mod
.venv/bin/python scripts/retrain_model.py
```
This loads `data/processed/dataset_featured.csv`, trains all models, evaluates with cross-validation, and overwrites the model files in `ml/models/`.
This loads the historical featured dataset from SQLite, trains all models, evaluates them, and overwrites the model files in `ml/models/`.
### Recommended retraining schedule
@@ -82,9 +82,9 @@ Runs every day at 22:00 (after stations close for the day):
The pipeline executes 5 steps:
1. Fetch weather forecasts from Open-Meteo for all 3 stations
2. Scrape current station status from infonieve.es (lifts, km, snow depth)
3. Append today's data to `data/processed/dataset.csv`
4. Run feature engineering -> `data/processed/dataset_featured.csv`
5. Generate next-day predictions -> `data/processed/predictions_latest.json`
3. Append today's data to the SQLite runtime dataset tables
4. Run feature engineering into SQLite runtime feature tables
5. Generate next-day predictions and publish them into SQLite for the bot
### Monthly model retraining (optional, recommended)
@@ -177,15 +177,20 @@ journalctl -u skipredictor-bot -f
### Check predictions
```bash
cat data/processed/predictions_latest.json | python -m json.tool
sqlite3 data/processed/skipredictor.db "
SELECT generated_at, prediction_date, run_kind
FROM prediction_runs
ORDER BY generated_at DESC, id DESC
LIMIT 5;
"
```
### Check dataset health
```bash
.venv/bin/python -c "
import pandas as pd
df = pd.read_csv('data/processed/dataset_featured.csv')
from storage import HISTORICAL_FEATURED_TABLE, SQLiteStore
df = SQLiteStore().read_dataframe(HISTORICAL_FEATURED_TABLE, parse_dates=('date',))
print(f'Rows: {len(df)}')
print(f'Date range: {df[\"date\"].min()} to {df[\"date\"].max()}')
print(f'Stations: {df[\"station_id\"].unique()}')
@@ -225,6 +230,6 @@ skipredictor/
├── start.sh # Setup and launch script
├── requirements.txt # Python dependencies
└── data/ # Runtime data (gitignored)
├── raw/ # Station CSVs, weather cache
└── processed/ # Dataset, features, predictions
├── raw/ # Webcam snapshots and transient downloads
└── processed/ # SQLite database and runtime logs
```