__init__.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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[float, float]]:
  11. """
  12. Generate points according to the GameConfig.
  13. """
  14. return source_groups[config.generation_method].get_points_from(config.rounds, config.country_lock)
  15. def restock_source(config: GameConfig):
  16. """
  17. Restock any caches associated with the GameConfig.
  18. """
  19. source_groups[config.generation_method].restock(config.country_lock)
  20. def get_cache_info() -> List[CacheInfo]:
  21. """
  22. Get CacheInfo for all caches.
  23. """
  24. return [CacheInfo(cache_name=c.get_name(), size=len(c.stock)) for g in source_groups.values() for c in g.cached]
  25. def get_generators() -> List[GeneratorInfo]:
  26. """
  27. Get all available Generators and their country options
  28. """
  29. return [
  30. GeneratorInfo(
  31. generation_method=GenMethodEnum.rsv,
  32. country_locks=RSV_COUNTRIES
  33. ),
  34. GeneratorInfo(
  35. generation_method=GenMethodEnum.urban,
  36. country_locks=URBAN_COUNTRIES
  37. ),
  38. ]