(swLat, swLng, neLat, neLng)
| 89 | |
| 90 | @staticmethod |
| 91 | def get_active(swLat, swLng, neLat, neLng): |
| 92 | if swLat is None or swLng is None or neLat is None or neLng is None: |
| 93 | query = (Pokemon |
| 94 | .select() |
| 95 | .where(Pokemon.disappear_time > datetime.utcnow()) |
| 96 | .dicts()) |
| 97 | else: |
| 98 | query = (Pokemon |
| 99 | .select() |
| 100 | .where((Pokemon.disappear_time > datetime.utcnow()) & |
| 101 | (((Pokemon.latitude >= swLat) & |
| 102 | (Pokemon.longitude >= swLng) & |
| 103 | (Pokemon.latitude <= neLat) & |
| 104 | (Pokemon.longitude <= neLng)))) |
| 105 | .dicts()) |
| 106 | |
| 107 | # Performance: Disable the garbage collector prior to creating a (potentially) large dict with append() |
| 108 | gc.disable() |
| 109 | |
| 110 | pokemons = [] |
| 111 | for p in query: |
| 112 | p['pokemon_name'] = get_pokemon_name(p['pokemon_id']) |
| 113 | p['pokemon_rarity'] = get_pokemon_rarity(p['pokemon_id']) |
| 114 | p['pokemon_types'] = get_pokemon_types(p['pokemon_id']) |
| 115 | if args.china: |
| 116 | p['latitude'], p['longitude'] = \ |
| 117 | transform_from_wgs_to_gcj(p['latitude'], p['longitude']) |
| 118 | pokemons.append(p) |
| 119 | |
| 120 | # Re-enable the GC. |
| 121 | gc.enable() |
| 122 | |
| 123 | return pokemons |
| 124 | |
| 125 | @staticmethod |
| 126 | def get_active_by_id(ids, swLat, swLng, neLat, neLng): |
no test coverage detected