drone-landing-safety / app /data_sources.py
yakvrz's picture
Remove embedded example assets and enable real examples
4d329d3
from __future__ import annotations
from functools import lru_cache
from pathlib import Path
from .config import EXAMPLES_ROOT, IMAGE_EXTS, IMAGE_ROOT, VISLOC_DIR
@lru_cache(maxsize=1)
def list_visloc_images() -> list[Path]:
if not VISLOC_DIR.exists():
return []
files = [p for p in VISLOC_DIR.iterdir() if p.suffix in IMAGE_EXTS]
return sorted(files)
@lru_cache(maxsize=1)
def list_example_images() -> list[Path]:
examples_dir = EXAMPLES_ROOT / "visloc"
files: list[Path] = []
if examples_dir.exists():
files = [p for p in examples_dir.rglob("*") if p.is_file() and p.suffix in IMAGE_EXTS]
return sorted(files)
@lru_cache(maxsize=1)
def list_all_data_inputs() -> list[str]:
paths: list[Path] = []
def _add(paths_in: list[Path]):
for p in paths_in:
if p not in paths:
paths.append(p)
# Prefer structured datasets first
_add(list_example_images())
_add(list_visloc_images())
# Allow arbitrary images anywhere under data/Image/
if IMAGE_ROOT.exists():
for p in IMAGE_ROOT.rglob("*"):
if p.is_file() and p.suffix in IMAGE_EXTS:
if p not in paths:
paths.append(p)
return [str(p) for p in sorted(paths)]
def clear_caches() -> None:
list_visloc_images.cache_clear()
list_example_images.cache_clear()
list_all_data_inputs.cache_clear()
__all__ = [
"list_visloc_images",
"list_example_images",
"list_all_data_inputs",
"clear_caches",
]