|
|
@ -26,15 +26,31 @@ class PokemonList:
|
|
|
|
return result.all()
|
|
|
|
return result.all()
|
|
|
|
|
|
|
|
|
|
|
|
def sort_by_cp(self, reverse=False):
|
|
|
|
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):
|
|
|
|
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):
|
|
|
|
def sort_by_distance(self, location: Location, reverse=False):
|
|
|
|
self.pokemons.sort(key=lambda pokemon: location.distance(pokemon.location), reverse=False)
|
|
|
|
self.pokemons.sort(key=lambda pokemon: location.distance(pokemon.location), reverse=False)
|
|
|
|
|
|
|
|
|
|
|
|
def get_at(self, index:int):
|
|
|
|
def get_at(self, index: int):
|
|
|
|
return self.pokemons[index]
|
|
|
|
return self.pokemons[index]
|
|
|
|
|
|
|
|
|
|
|
|
def search_by_name(self, query:str):
|
|
|
|
def search_by_name(self, query:str):
|
|
|
|