Occasion-Scanner / app /utils.py
ganemmah's picture
Upload folder using huggingface_hub
b22d3c4 verified
Raw
History Blame Contribute Delete
1.74 kB
"""Shared utilities for Occasion Scanner."""
from __future__ import annotations
import os
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[1]
DATA_DIR = PROJECT_ROOT / "data"
RAW_DATA_DIR = DATA_DIR / "raw"
PROCESSED_DATA_DIR = DATA_DIR / "processed"
SAMPLE_DATA_DIR = DATA_DIR / "samples"
MODELS_DIR = PROJECT_ROOT / "models"
REPORTS_DIR = PROJECT_ROOT / "reports"
FIGURES_DIR = REPORTS_DIR / "figures"
SCREENSHOTS_DIR = REPORTS_DIR / "screenshots"
EUR_TO_CHF_RATE = float(os.getenv("EUR_TO_CHF_RATE", "0.95"))
SWISS_MARKET_FACTOR = float(os.getenv("SWISS_MARKET_FACTOR", "1.08"))
def ensure_project_directories() -> None:
"""Create the standard project directories if they do not exist."""
for path in [
RAW_DATA_DIR,
PROCESSED_DATA_DIR,
SAMPLE_DATA_DIR,
MODELS_DIR,
MODELS_DIR / "damage_model",
REPORTS_DIR,
FIGURES_DIR,
SCREENSHOTS_DIR,
]:
path.mkdir(parents=True, exist_ok=True)
def format_eur(value: float | int | None) -> str:
"""Format a numeric value as an EUR amount for app output."""
if value is None:
return "n/a"
return f"EUR {float(value):,.0f}".replace(",", "'")
def eur_to_chf(value: float | int | None) -> float | None:
"""Convert an internal EUR model amount to Swiss-market-calibrated CHF."""
if value is None:
return None
return round(float(value) * EUR_TO_CHF_RATE * SWISS_MARKET_FACTOR, 2)
def format_chf(value: float | int | None) -> str:
"""Format an internal EUR model amount as calibrated CHF for app output."""
chf_value = eur_to_chf(value)
if chf_value is None:
return "n/a"
return f"CHF {chf_value:,.0f}".replace(",", "'")