from __future__ import annotations import json from functools import lru_cache from pathlib import Path from typing import Dict, List, Tuple import pandas as pd from .models import Attraction BASE_DIR = Path(__file__).parent.parent DATA_DIR = BASE_DIR / "data" @lru_cache(maxsize=1) def load_nodes() -> Dict[str, Dict]: with (DATA_DIR / "park_nodes.json").open("r", encoding="utf-8") as f: return json.load(f) @lru_cache(maxsize=1) def load_edges() -> List[Dict]: with (DATA_DIR / "park_edges.json").open("r", encoding="utf-8") as f: return json.load(f) @lru_cache(maxsize=1) def load_attractions() -> Dict[str, Attraction]: with (DATA_DIR / "attractions.json").open("r", encoding="utf-8") as f: raw = json.load(f) return {a["id"]: Attraction.model_validate(a) for a in raw} @lru_cache(maxsize=1) def load_wait_history() -> pd.DataFrame: return pd.read_csv(DATA_DIR / "wait_time_history.csv") def get_attraction_by_name(name: str) -> Attraction | None: name_lower = name.strip().lower() for attr in load_attractions().values(): if attr.name.lower() == name_lower: return attr return None def walking_distance_between(node_from: str, node_to: str) -> int: from .routing import shortest_path_distance return shortest_path_distance(node_from, node_to) def summarize_dataset() -> Tuple[int, int, int]: nodes = load_nodes() edges = load_edges() attractions = load_attractions() return len(nodes), len(edges), len(attractions)