(cls, center, steps)
| 285 | |
| 286 | @classmethod |
| 287 | def get_spawnpoints_in_hex(cls, center, steps): |
| 288 | log.info('Finding spawn points {} steps away'.format(steps)) |
| 289 | |
| 290 | n, e, s, w = hex_bounds(center, steps) |
| 291 | |
| 292 | query = (Pokemon |
| 293 | .select(Pokemon.latitude.alias('lat'), |
| 294 | Pokemon.longitude.alias('lng'), |
| 295 | ((Pokemon.disappear_time.minute * 60) + Pokemon.disappear_time.second).alias('time'), |
| 296 | Pokemon.spawnpoint_id |
| 297 | )) |
| 298 | query = (query.where((Pokemon.latitude <= n) & |
| 299 | (Pokemon.latitude >= s) & |
| 300 | (Pokemon.longitude >= w) & |
| 301 | (Pokemon.longitude <= e) |
| 302 | )) |
| 303 | # Sqlite doesn't support distinct on columns |
| 304 | if args.db_type == 'mysql': |
| 305 | query = query.distinct(Pokemon.spawnpoint_id) |
| 306 | else: |
| 307 | query = query.group_by(Pokemon.spawnpoint_id) |
| 308 | |
| 309 | s = list(query.dicts()) |
| 310 | |
| 311 | # The distance between scan circles of radius 70 in a hex is 121.2436 |
| 312 | # steps - 1 to account for the center circle then add 70 for the edge |
| 313 | step_distance = ((steps - 1) * 121.2436) + 70 |
| 314 | # Compare spawnpoint list to a circle with radius steps * 120 |
| 315 | # Uses the direct geopy distance between the center and the spawnpoint. |
| 316 | filtered = [] |
| 317 | |
| 318 | for idx, sp in enumerate(s): |
| 319 | if geopy.distance.distance(center, (sp['lat'], sp['lng'])).meters <= step_distance: |
| 320 | filtered.append(s[idx]) |
| 321 | |
| 322 | # at this point, 'time' is DISAPPEARANCE time, we're going to morph it to APPEARANCE time |
| 323 | for location in filtered: |
| 324 | # examples: time shifted |
| 325 | # 0 ( 0 + 2700) = 2700 % 3600 = 2700 (0th minute to 45th minute, 15 minutes prior to appearance as time wraps around the hour) |
| 326 | # 1800 (1800 + 2700) = 4500 % 3600 = 900 (30th minute, moved to arrive at 15th minute) |
| 327 | # todo: this DOES NOT ACCOUNT for pokemons that appear sooner and live longer, but you'll _always_ have at least 15 minutes, so it works well enough |
| 328 | location['time'] = cls.get_spawn_time(location['time']) |
| 329 | |
| 330 | return filtered |
| 331 | |
| 332 | |
| 333 | class Pokestop(BaseModel): |
no test coverage detected