__init__.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from typing import List, Tuple
  2. from .random_street_view import SOURCE_GROUP as RSV_SOURCE_GROUP, VALID_COUNTRIES as RSV_COUNTRIES
  3. from .urban_centers import SOURCE_GROUP as URBAN_CENTER_SOURCE_GROUP, VALID_COUNTRIES as URBAN_COUNTRIES
  4. from .shared import ExhaustedSourceError
  5. from ..schemas import GameConfig, GenMethodEnum, CacheInfo, GeneratorInfo
  6. source_groups = {
  7. GenMethodEnum.rsv: RSV_SOURCE_GROUP,
  8. GenMethodEnum.urban: URBAN_CENTER_SOURCE_GROUP,
  9. }
  10. def generate_points(config: GameConfig) -> List[Tuple[str, float, float]]:
  11. """
  12. Generate points according to the GameConfig.
  13. """
  14. # note - force exactly config.rounds points, even though most top level sources should be well-behaved in this regard
  15. return source_groups[config.generation_method].get_points_from(config.rounds, config.country_lock)[:config.rounds]
  16. def restock_source(config: GameConfig):
  17. """
  18. Restock any caches associated with the GameConfig.
  19. """
  20. source_groups[config.generation_method].restock(config.country_lock)
  21. def get_cache_info() -> List[CacheInfo]:
  22. """
  23. Get CacheInfo for all caches.
  24. """
  25. return [CacheInfo(cache_name=c.get_name(), size=len(c.stock)) for g in source_groups.values() for c in g.cached]
  26. def get_generators() -> List[GeneratorInfo]:
  27. """
  28. Get all available Generators and their country options
  29. """
  30. return [
  31. GeneratorInfo(
  32. generation_method=GenMethodEnum.rsv,
  33. country_locks=RSV_COUNTRIES
  34. ),
  35. GeneratorInfo(
  36. generation_method=GenMethodEnum.urban,
  37. country_locks=URBAN_COUNTRIES
  38. ),
  39. ]