"""Rank planets by extraction factor for a resource, with founding cost (environment extras from FIO's own BuildRequirements - authoritative, not guessed from temperature/pressure thresholds, which PRUNplanner's own calculations don't model either).""" from . import fio def candidates(resource_ticker: str, min_factor: float = 0.0): """All planets with this resource, sorted by factor descending. Each: PlanetNaturalId, PlanetName, factor, resource_type, plus the raw planet record (temperature/pressure/ gravity/fertility/faction/BuildRequirements/SystemId etc).""" mats = {m["Ticker"]: m["MaterialId"] for m in fio.materials()} mid = mats.get(resource_ticker.upper()) if not mid: raise ValueError(f"unknown material ticker {resource_ticker!r}") out = [] for p in fio.planets_full(): for r in p.get("Resources", []): if r["MaterialId"] == mid and r["Factor"] >= min_factor: out.append({ "natural_id": p["PlanetNaturalId"], "name": p["PlanetName"], "factor": r["Factor"], "resource_type": r["ResourceType"], "temperature": p["Temperature"], "pressure": p["Pressure"], "gravity": p["Gravity"], "fertility": p["Fertility"], "faction": p.get("FactionCode"), "system_id": p["SystemId"], "build_requirements": p.get("BuildRequirements", []), }) out.sort(key=lambda x: -x["factor"]) return out