(swLat, swLng, neLat, neLng)
| 394 | |
| 395 | @staticmethod |
| 396 | def get_gyms(swLat, swLng, neLat, neLng): |
| 397 | if swLat is None or swLng is None or neLat is None or neLng is None: |
| 398 | results = (Gym |
| 399 | .select() |
| 400 | .dicts()) |
| 401 | else: |
| 402 | results = (Gym |
| 403 | .select() |
| 404 | .where((Gym.latitude >= swLat) & |
| 405 | (Gym.longitude >= swLng) & |
| 406 | (Gym.latitude <= neLat) & |
| 407 | (Gym.longitude <= neLng)) |
| 408 | .dicts()) |
| 409 | |
| 410 | # Performance: Disable the garbage collector prior to creating a (potentially) large dict with append() |
| 411 | gc.disable() |
| 412 | |
| 413 | gyms = {} |
| 414 | gym_ids = [] |
| 415 | for g in results: |
| 416 | g['name'] = None |
| 417 | g['pokemon'] = [] |
| 418 | gyms[g['gym_id']] = g |
| 419 | gym_ids.append(g['gym_id']) |
| 420 | |
| 421 | if len(gym_ids) > 0: |
| 422 | pokemon = (GymMember |
| 423 | .select( |
| 424 | GymMember.gym_id, |
| 425 | GymPokemon.cp.alias('pokemon_cp'), |
| 426 | GymPokemon.pokemon_id, |
| 427 | Trainer.name.alias('trainer_name'), |
| 428 | Trainer.level.alias('trainer_level')) |
| 429 | .join(Gym, on=(GymMember.gym_id == Gym.gym_id)) |
| 430 | .join(GymPokemon, on=(GymMember.pokemon_uid == GymPokemon.pokemon_uid)) |
| 431 | .join(Trainer, on=(GymPokemon.trainer_name == Trainer.name)) |
| 432 | .where(GymMember.gym_id << gym_ids) |
| 433 | .where(GymMember.last_scanned > Gym.last_modified) |
| 434 | .order_by(GymMember.gym_id, GymPokemon.cp) |
| 435 | .dicts()) |
| 436 | |
| 437 | for p in pokemon: |
| 438 | p['pokemon_name'] = get_pokemon_name(p['pokemon_id']) |
| 439 | gyms[p['gym_id']]['pokemon'].append(p) |
| 440 | |
| 441 | details = (GymDetails |
| 442 | .select( |
| 443 | GymDetails.gym_id, |
| 444 | GymDetails.name) |
| 445 | .where(GymDetails.gym_id << gym_ids) |
| 446 | .dicts()) |
| 447 | |
| 448 | for d in details: |
| 449 | gyms[d['gym_id']]['name'] = d['name'] |
| 450 | |
| 451 | # Re-enable the GC. |
| 452 | gc.enable() |
| 453 |
no test coverage detected