예제 #1
0
    def stops_from_db_unvisited(self, geofence_helper: GeofenceHelper,
                                origin: str):
        logger.debug("DbWrapper::stops_from_db_unvisited called")
        minLat, minLon, maxLat, maxLon = geofence_helper.get_polygon_from_fence(
        )
        query = (
            "SELECT pokestop.latitude, pokestop.longitude,GROUP_CONCAT(trs_visited.origin) AS vis "
            "FROM pokestop "
            "LEFT JOIN trs_visited ON pokestop.pokestop_id = trs_visited.pokestop_id "
            "WHERE (pokestop.latitude >= {} AND pokestop.longitude >= {} "
            "AND pokestop.latitude <= {} AND pokestop.longitude <= {}) "
            "GROUP by pokestop.pokestop_id HAVING INSTR(vis,'{}') < 1").format(
                minLat, minLon, maxLat, maxLon, origin)

        res = self.execute(query)
        unvisited: List[Location] = []

        for (latitude, longitude, vis) in res:
            unvisited.append(Location(latitude, longitude))

        if geofence_helper is not None:
            geofenced_coords = geofence_helper.get_geofenced_coordinates(
                unvisited)
            return geofenced_coords
        else:
            return unvisited
예제 #2
0
def main():
    args = Args()
    initLogging(args)

    if len(sys.argv) != 2:
         logger.error("usage: remove_all_spawns_within_geofence.py GEOFENCE_FILENAME")
         sys.exit(1)

    LocationWithID = collections.namedtuple('Location', ['lat', 'lng', 'spawnpoint'])

    geofence_filename = sys.argv[1]
    #print("Argument: '%s'" % (geofence_filename))
    # no .txt, add it
    if ".txt" not in geofence_filename:
        geofence_filename = geofence_filename+".txt"
    # no / in filename, probably not an absolute path, append standard MAD path
    if "/" not in geofence_filename:
        geofence_filename = "../configs/geofences/" + geofence_filename
    logger.info("Trying to use file: {}", geofence_filename)
    if not os.path.isfile(geofence_filename):
         logger.error("Geofence file {} not found, exit", geofence_filename)
         sys.exit(1)

    geofence_helper = GeofenceHelper(geofence_filename, None)
    minLat, minLon, maxLat, maxLon = geofence_helper.get_polygon_from_fence()
    query = (
            "SELECT latitude, longitude, spawnpoint "
            "FROM trs_spawn "
            "WHERE (latitude >= {} AND longitude >= {} "
            "AND latitude <= {} AND longitude <= {}) "
    ).format(minLat, minLon, maxLat, maxLon)

    delete_query = (
            "DELETE FROM trs_spawn "
            "WHERE spawnpoint = {} "
    )

    list_of_coords: List[LocationWithID] = []

    dbip = get_value_for(r'\s+dbip:\s+([^\s]+)')
    dbport = get_value_for(r'\s+dbport:\s+([^.\s]*)', False)
    if dbport is None:  # if dbport is not set, use default
        dbport = '3306'
    dbusername = get_value_for(r'\s+dbusername:\s+([^.\s]*)')
    dbpassword = get_value_for(r'\s+dbpassword:\s+([^.\s]*)')
    dbname = get_value_for(r'\s+dbname:\s+([^.\s]*)')

    #print("Successfully parsed config.ini, using values:")
    #print("dbport: %s" % dbport)
    #print("dbusername: %s" % dbusername)
    #print("dbname: %s" % dbname)
    #print("dbip: %s" % dbip)

    connection = mysql.connector.connect(
        host = dbip,
        port = dbport,
        user = dbusername,
        passwd = dbpassword,
        database = dbname)
    cursor = connection.cursor()

    cursor.execute(query)
    res = cursor.fetchall()
    for (latitude, longitude, spawnpoint) in res:
        list_of_coords.append(LocationWithID(latitude, longitude, spawnpoint))

    geofenced_coords = geofence_helper.get_geofenced_coordinates(list_of_coords)
    spawnpointcount = len(geofenced_coords)
    for coords in geofenced_coords:
         sql = delete_query.format(coords.spawnpoint)
         cursor.execute(sql)
         #print(sql)

    connection.commit()

    cursor.close()
    connection.close()
    logger.success("Done, deleted {} spawnpoints", spawnpointcount)
예제 #3
0
    def _generate_locations(distance: float, geofence_helper: GeofenceHelper):
        results = []
        south, east, north, west = geofence_helper.get_polygon_from_fence()

        corners = [
            Location(south, east),
            Location(south, west),
            Location(north, east),
            Location(north, west)
        ]
        # get the center
        center = get_middle_of_coord_list(corners)

        # get the farthest to the center...
        farthest_dist = 0
        for corner in corners:
            dist_temp = get_distance_of_two_points_in_meters(
                center.lat, center.lng, corner.lat, corner.lng)
            if dist_temp > farthest_dist:
                farthest_dist = dist_temp

        # calculate step_limit, round up to reduce risk of losing stuff
        step_limit = math.ceil(farthest_dist / distance)

        # This will loop thorugh all the rings in the hex from the centre
        # moving outwards
        logger.info("Calculating positions for init scan")
        num_cores = multiprocessing.cpu_count()
        with multiprocessing.Pool(processes=num_cores) as pool:
            temp = [
                pool.apply(S2Helper._generate_star_locs,
                           args=(center, distance, i))
                for i in range(1, step_limit)
            ]

        results = [item for sublist in temp for item in sublist]
        results.append(Location(center.lat, center.lng))

        # for ring in range(1, step_limit):
        #     for i in range(0, 6):
        #         # Star_locs will contain the locations of the 6 vertices of
        #         # the current ring (90,150,210,270,330 and 30 degrees from
        #         # origin) to form a star
        #         star_loc = S2Helper.get_new_coords(center, distance * ring,
        #                                            90 + 60 * i)
        #         for j in range(0, ring):
        #             # Then from each point on the star, create locations
        #             # towards the next point of star along the edge of the
        #             # current ring
        #             loc = S2Helper.get_new_coords(star_loc, distance * j, 210 + 60 * i)
        #             results.append(loc)

        logger.info("Filtering positions for init scan")
        # Geofence results.
        if geofence_helper is not None and geofence_helper.is_enabled():
            results = geofence_helper.get_geofenced_coordinates(results)
            if not results:
                logger.error(
                    'No cells regarded as valid for desired scan area. '
                    'Check your provided geofences. Aborting.')
                sys.exit(1)
        logger.info("Ordering location")
        results = S2Helper.order_location_list_rows(results)

        return results