|
|
|
@ -26,10 +26,26 @@ class PokemonList:
|
|
|
|
|
return result.all()
|
|
|
|
|
|
|
|
|
|
def sort_by_cp(self, reverse=False):
|
|
|
|
|
self.pokemons.sort(key=lambda pokemon: pokemon.cp, reverse=reverse)
|
|
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
if reverse:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \
|
|
|
|
|
.order_by(desc(Pokemon.cp))
|
|
|
|
|
else:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \
|
|
|
|
|
.order_by(Pokemon.cp)
|
|
|
|
|
session.commit()
|
|
|
|
|
return result.all()
|
|
|
|
|
|
|
|
|
|
def sort_by_level(self, reverse=False):
|
|
|
|
|
self.pokemons.sort(key=lambda pokemon: pokemon.level, reverse=reverse)
|
|
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
if reverse:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \
|
|
|
|
|
.order_by(desc(Pokemon.level))
|
|
|
|
|
else:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \
|
|
|
|
|
.order_by(Pokemon.level)
|
|
|
|
|
session.commit()
|
|
|
|
|
return result.all()
|
|
|
|
|
|
|
|
|
|
def sort_by_distance(self, location: Location, reverse=False):
|
|
|
|
|
self.pokemons.sort(key=lambda pokemon: location.distance(pokemon.location), reverse=False)
|
|
|
|
|