Last active
September 1, 2020 17:42
-
-
Save sn0opy/b7254a19a5312c8e2ed5ee2d5ebd1cf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
import json | |
import time | |
from db.DbFactory import DbFactory | |
from geofence.geofenceHelper import GeofenceHelper | |
from utils.walkerArgs import parseArgs | |
from utils.logging import logger, initLogging | |
# path to geofence file goes here | |
geofence_file = "" | |
if __name__ == "__main__": | |
args = parseArgs() | |
initLogging(args) | |
db_wrapper, db_wrapper_manager = DbFactory.get_wrapper(args) | |
# parse fence | |
geofence_helper = GeofenceHelper(geofence_file, None) | |
logger.info("Running for geofence file: {}".format(geofence_file)) | |
# get outer bounds of fence | |
aa, ab, ba, bb = geofence_helper.get_polygon_from_fence() | |
# get spawns and mons | |
spawns = json.loads(db_wrapper.download_spawns(ba, bb, aa, ab)) | |
mons = db_wrapper.get_mons_in_rectangle(ba, bb, aa, ab) | |
mons_in_geofence = [] | |
for mon in mons: | |
if geofence_helper.is_coord_inside_include_geofence((mon["latitude"], mon["longitude"])): | |
mons_in_geofence.append(mon["spawnpoint_id"]) | |
spawns_in_geofence = [] | |
for i in spawns: | |
spawn = spawns[i] | |
if geofence_helper.is_coord_inside_include_geofence((spawn["lat"], spawn["lon"])): | |
spawn["spawnpoint_id"] = i | |
spawns_in_geofence.append(spawn) | |
current_time_of_day = datetime.now().replace(microsecond=0) | |
current_time = time.time() | |
counts = { | |
"inactive": 0, | |
"active": 0, | |
"unknown_despawn": 0, | |
"mons_in_geofence": len(mons_in_geofence), | |
"spawns_in_geofence": len(spawns_in_geofence) | |
} | |
for spawn in spawns_in_geofence: | |
if spawn["endtime"] is None: | |
counts["unknown_despawn"] += 1 | |
continue | |
endminsec_split = spawn["endtime"].split(":") | |
minutes = int(endminsec_split[0]) | |
seconds = int(endminsec_split[1]) | |
spawn_duration_minutes = 60 if spawn["spawndef"] == 15 else 30 | |
despawn_time = current_time_of_day.replace(minute=minutes, second=seconds) | |
if minutes < datetime.now().minute: | |
despawn_time = despawn_time + timedelta(hours=1) | |
spawn_time = despawn_time - timedelta(minutes=spawn_duration_minutes) | |
if despawn_time > current_time_of_day > spawn_time: | |
counts["active"] += 1 | |
else: | |
counts["inactive"] += 1 | |
logger.success(counts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
checkout https://gist.github.com/to-fr/908cfbaacb207b08b152dc172fc81426 for an updated version