Spaces:
Sleeping
Sleeping
File size: 1,602 Bytes
214f910 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 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)
|