from typing import List, Tuple from .random_street_view import SOURCE_GROUP as RSV_SOURCE_GROUP, VALID_COUNTRIES as RSV_COUNTRIES from .urban_centers import SOURCE_GROUP as URBAN_CENTER_SOURCE_GROUP, VALID_COUNTRIES as URBAN_COUNTRIES from .shared import ExhaustedSourceError from ..schemas import GameConfig, GenMethodEnum, CacheInfo, GeneratorInfo source_groups = { GenMethodEnum.rsv: RSV_SOURCE_GROUP, GenMethodEnum.urban: URBAN_CENTER_SOURCE_GROUP, } def generate_points(config: GameConfig) -> List[Tuple[str, float, float]]: """ Generate points according to the GameConfig. """ # note - force exactly config.rounds points, even though most top level sources should be well-behaved in this regard return source_groups[config.generation_method].get_points_from(config.rounds, config.country_lock)[:config.rounds] def restock_source(config: GameConfig): """ Restock any caches associated with the GameConfig. """ source_groups[config.generation_method].restock(config.country_lock) def get_cache_info() -> List[CacheInfo]: """ Get CacheInfo for all caches. """ return [CacheInfo(cache_name=c.get_name(), size=len(c.stock)) for g in source_groups.values() for c in g.cached] def get_generators() -> List[GeneratorInfo]: """ Get all available Generators and their country options """ return [ GeneratorInfo( generation_method=GenMethodEnum.rsv, country_locks=RSV_COUNTRIES ), GeneratorInfo( generation_method=GenMethodEnum.urban, country_locks=URBAN_COUNTRIES ), ]