mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 23:36:17 +00:00
feat(storage): migrate project to sqlite
This commit is contained in:
1 parent
1bc1e58781
commit
9c8ba03574
17 files changed
+1204
-688
No files matched your search
@@ -11,7 +11,7 @@ Columns in the TSV:
|
||||
pistasprocessed, minprocessed, maxprocessed, idestado
|
||||
|
||||
This module downloads all available seasons for the three target stations
|
||||
and saves the combined data as CSVs in data/raw/.
|
||||
and stores the combined raw history in SQLite.
|
||||
"""
|
||||
|
||||
import io
|
||||
@@ -22,11 +22,11 @@ from pathlib import Path
|
||||
import pandas as pd
|
||||
import requests
|
||||
|
||||
from storage import SQLiteStore
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
_RAW_DIR = _PROJECT_ROOT / "data" / "raw"
|
||||
|
||||
_BASE_URL = "https://www.infonieve.es/estacion-esqui.historico-nieve.tsv.php"
|
||||
|
||||
# Infonieve internal IDs for our stations
|
||||
@@ -101,7 +101,7 @@ def download_season(
|
||||
return df
|
||||
|
||||
|
||||
def download_all_history() -> pd.DataFrame:
|
||||
def download_all_history(store: SQLiteStore | None = None) -> pd.DataFrame:
|
||||
"""Download all available historical data for all three stations.
|
||||
|
||||
Returns
|
||||
@@ -145,11 +145,9 @@ def download_all_history() -> pd.DataFrame:
|
||||
# Sort
|
||||
combined = combined.sort_values(["station_id", "date"]).reset_index(drop=True)
|
||||
|
||||
# Save
|
||||
_RAW_DIR.mkdir(parents=True, exist_ok=True)
|
||||
output_path = _RAW_DIR / "station_historical_all.csv"
|
||||
combined.to_csv(output_path, index=False)
|
||||
logger.info("Historical data saved to %s: %d total rows.", output_path, len(combined))
|
||||
effective_store = store if store is not None else SQLiteStore()
|
||||
effective_store.save_historical_station_raw(combined)
|
||||
logger.info("Historical data saved to SQLite: %d total rows.", len(combined))
|
||||
|
||||
# Summary
|
||||
for sid in _STATION_IDS:
|
||||
|
||||
Reference in new issue
Block a user