MCPcopy Create free account
hub / github.com/RocketMap/RocketMap / get_seen

Method get_seen

pogom/models.py:164–201  ·  view source on GitHub ↗
(cls, timediff)

Source from the content-addressed store, hash-verified

162 @classmethod
163 @cached(cache)
164 def get_seen(cls, timediff):
165 if timediff:
166 timediff = datetime.utcnow() - timediff
167 pokemon_count_query = (Pokemon
168 .select(Pokemon.pokemon_id,
169 fn.COUNT(Pokemon.pokemon_id).alias('count'),
170 fn.MAX(Pokemon.disappear_time).alias('lastappeared')
171 )
172 .where(Pokemon.disappear_time > timediff)
173 .group_by(Pokemon.pokemon_id)
174 .alias('counttable')
175 )
176 query = (Pokemon
177 .select(Pokemon.pokemon_id,
178 Pokemon.disappear_time,
179 Pokemon.latitude,
180 Pokemon.longitude,
181 pokemon_count_query.c.count)
182 .join(pokemon_count_query, on=(Pokemon.pokemon_id == pokemon_count_query.c.pokemon_id))
183 .distinct()
184 .where(Pokemon.disappear_time == pokemon_count_query.c.lastappeared)
185 .dicts()
186 )
187
188 # Performance: Disable the garbage collector prior to creating a (potentially) large dict with append()
189 gc.disable()
190
191 pokemons = []
192 total = 0
193 for p in query:
194 p['pokemon_name'] = get_pokemon_name(p['pokemon_id'])
195 pokemons.append(p)
196 total += p['count']
197
198 # Re-enable the GC.
199 gc.enable()
200
201 return {'pokemon': pokemons, 'total': total}
202
203 @classmethod
204 def get_appearances(cls, pokemon_id, timediff):

Callers 1

raw_dataMethod · 0.80

Calls 2

get_pokemon_nameFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected