Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| import os | |
| import math | |
| from dataclasses import dataclass | |
| from typing import Dict, Any, Optional, List | |
| import pandas as pd | |
| import numpy as np | |
| def get_env(name: str, default: Optional[str] = None) -> Optional[str]: | |
| # HF Spaces: secrets mounted as env | |
| return os.getenv(name, default) | |
| def heat_index_c(temp_c: float, rh: float) -> float: | |
| """Compute heat index (°C) using Rothfusz regression. | |
| Input temp in °C, RH in %. | |
| """ | |
| T = temp_c * 9/5 + 32 | |
| R = rh | |
| HI_f = (-42.379 + 2.04901523*T + 10.14333127*R - 0.22475541*T*R | |
| - 6.83783e-3*T*T - 5.481717e-2*R*R + 1.22874e-3*T*T*R | |
| + 8.5282e-4*T*R*R - 1.99e-6*T*T*R*R) | |
| return (HI_f - 32) * 5/9 | |
| def bucketize(val: float, bins: List[float], labels: List[str]) -> str: | |
| idx = np.digitize([val], bins)[0] | |
| return labels[min(idx, len(labels)-1)] | |
| def safe_float(x, default=np.nan): | |
| try: | |
| return float(x) | |
| except Exception: | |
| return default |