def get_gym_markers(names=POKEMON): with session_scope() as session: forts = get_forts(session) return [{ 'id': 'fort-' + str(fort['fort_id']), 'sighting_id': fort['id'], 'prestige': fort['prestige'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': names[fort['guard_pokemon_id']], 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'] } for fort in forts]
def get_gym_markers(names=POKEMON): with session_scope() as session: forts = get_forts(session) return [{ 'id': 'fort-' + str(fort['fort_id']), 'sighting_id': fort['id'], 'prestige': fort['prestige'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': names[fort['guard_pokemon_id']], 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'] } for fort in forts]
def get_gym_markers(names=POKEMON): with session_scope() as session: forts = get_forts(session) return [{ 'id': 'fort-' + str(fort['fort_id']), 'sighting_id': fort['id'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': names[fort['guard_pokemon_id']], 'team': fort['team'], 'in_battle': fort['in_battle'], 'slots_available': fort['slots_available'], 'time_ocuppied': fort['time_ocuppied'], 'lat': fort['lat'], 'lon': fort['lon'] } for fort in forts]
def get_pokemarkers(): markers = [] session = db.Session(autoflush=False) pokemons = db.get_sightings(session) forts = db.get_forts(session) session.close() for pokemon in pokemons: markers.append({ 'id': 'pokemon-{}'.format(pokemon.id), 'type': 'pokemon', 'trash': pokemon.pokemon_id in config.TRASH_IDS, 'name': POKEMON_NAMES[pokemon.pokemon_id], 'pokemon_id': pokemon.pokemon_id, 'lat': pokemon.lat, 'lon': pokemon.lon, 'expires_at': pokemon.expire_timestamp, }) for fort in forts: if fort['guard_pokemon_id']: pokemon_name = POKEMON_NAMES[fort['guard_pokemon_id']] else: pokemon_name = 'Empty' markers.append({ 'id': 'fort-{}'.format(fort['fort_id']), 'sighting_id': fort['id'], 'type': 'fort', 'prestige': fort['prestige'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': pokemon_name, 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'], }) if config.MAP_WORKERS: # Worker stats try: markers.extend(get_worker_markers()) except RemoteError: print('Unable to connect to manager for worker data.') return markers
def get_gym_markers(names=POKEMON): with session_scope() as session: forts = get_forts(session) return [{ 'id': 'fort-' + str(fort['fort_id']), 'fort_id': fort['fort_id'], 'sighting_id': fort['id'], 'gym_name': fort['name'], 'image_url': fort['url'], 'external_id': fort['external_id'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': names[fort['guard_pokemon_id']], 'slots_available': fort['slots_available'], 'time_occupied': fort['time_occupied'], 'last_modified': fort['last_modified'], 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'], 'sponsor': fort['sponsor'] } for fort in forts]
def get_stats(): cache_valid = ( CACHE['data'] and CACHE['generated_at'] > datetime.now() - timedelta(minutes=15) ) if cache_valid: return CACHE['data'] with db.session_scope() as session: forts = db.get_forts(session) count = {t.value: 0 for t in db.Team} strongest = {t.value: None for t in db.Team} guardians = {t.value: {} for t in db.Team} top_guardians = {t.value: None for t in db.Team} prestige = {t.value: 0 for t in db.Team} percentages = {} prestige_percent = {} total_prestige = 0 last_date = 0 pokemon_names = POKEMON for fort in forts: if fort['last_modified'] > last_date: last_date = fort['last_modified'] team = fort['team'] count[team] += 1 if team != 0: # Strongest gym existing = strongest[team] should_replace = ( existing is not None and fort['prestige'] > existing[0] or existing is None ) pokemon_id = fort['guard_pokemon_id'] if should_replace: strongest[team] = ( fort['prestige'], pokemon_id, pokemon_names[pokemon_id], ) # Guardians guardian_value = guardians[team].get(pokemon_id, 0) guardians[team][pokemon_id] = guardian_value + 1 # Prestige prestige[team] += fort['prestige'] total_prestige = sum(prestige.values()) for team in db.Team: percentages[team.value] = ( count.get(team.value) / len(forts) * 100 ) prestige_percent[team.value] = ( prestige.get(team.value) / total_prestige * 100 ) if guardians[team.value]: pokemon_id = sorted( guardians[team.value], key=guardians[team.value].__getitem__, reverse=True )[0] top_guardians[team.value] = pokemon_names[pokemon_id] CACHE['generated_at'] = datetime.now() CACHE['data'] = { 'order': sorted(count, key=count.__getitem__, reverse=True), 'count': count, 'total_count': len(forts), 'strongest': strongest, 'prestige': prestige, 'prestige_percent': prestige_percent, 'percentages': percentages, 'last_date': last_date, 'top_guardians': top_guardians, 'generated_at': CACHE['generated_at'], } return CACHE['data']
def get_stats(): cache_valid = ( CACHE['data'] and CACHE['generated_at'] > datetime.now() - timedelta(minutes=15)) if cache_valid: return CACHE['data'] with db.session_scope() as session: forts = db.get_forts(session) count = {t.value: 0 for t in db.Team} strongest = {t.value: None for t in db.Team} guardians = {t.value: {} for t in db.Team} top_guardians = {t.value: None for t in db.Team} prestige = {t.value: 0 for t in db.Team} percentages = {} prestige_percent = {} total_prestige = 0 last_date = 0 pokemon_names = POKEMON for fort in forts: if fort['last_modified'] > last_date: last_date = fort['last_modified'] team = fort['team'] count[team] += 1 if team != 0: # Strongest gym existing = strongest[team] should_replace = (existing is not None and fort['prestige'] > existing[0] or existing is None) pokemon_id = fort['guard_pokemon_id'] if should_replace: strongest[team] = ( fort['prestige'], pokemon_id, pokemon_names[pokemon_id], ) # Guardians guardian_value = guardians[team].get(pokemon_id, 0) guardians[team][pokemon_id] = guardian_value + 1 # Prestige prestige[team] += fort['prestige'] total_prestige = sum(prestige.values()) for team in db.Team: percentages[team.value] = (count.get(team.value) / len(forts) * 100) prestige_percent[team.value] = (prestige.get(team.value) / total_prestige * 100) if guardians[team.value]: pokemon_id = sorted(guardians[team.value], key=guardians[team.value].__getitem__, reverse=True)[0] top_guardians[team.value] = pokemon_names[pokemon_id] CACHE['generated_at'] = datetime.now() CACHE['data'] = { 'order': sorted(count, key=count.__getitem__, reverse=True), 'count': count, 'total_count': len(forts), 'strongest': strongest, 'prestige': prestige, 'prestige_percent': prestige_percent, 'percentages': percentages, 'last_date': last_date, 'top_guardians': top_guardians, 'generated_at': CACHE['generated_at'], } return CACHE['data']