コード例 #1
0
 def _get_circle(self, event, to_be_inspected, relations, max_radius):
     if len(to_be_inspected) == 0:
         return event, [event]
     elif len(to_be_inspected) == 1:
         # TODO: do relations hold themselves or is there a return missing here?
         return event, [event]
     # use the get_farthest... since we have previously moved the middle, we need to check for matching events in
     # such cases and build new circle events in time
     if len(event) == 4 and event[3]:
         # this is a previously clustered event, we will simply check for other events that have not been clustered
         # to include those in our current circle
         # all we need to do is update timestamps to keep track as to whether we are still inside the max_timedelta
         # constraint
         middle_event = event
         middle = event[1]
         earliest_timestamp = event[0] - event[2]
         latest_timestamp = event[0]
         farthest_away = event
         distance_to_farthest = max_radius
     else:
         farthest_away, distance_to_farthest = self._get_farthest_in_relation(
             to_be_inspected)
         all_events_within_range_and_time = [event, farthest_away]
         earliest_timestamp = self._get_earliest_timestamp_in_queue(
             all_events_within_range_and_time)
         latest_timestamp = self._get_latest_timestamp_in_queue(
             all_events_within_range_and_time)
         middle = get_middle_of_coord_list([event[1], farthest_away[1]])
         middle_event = (latest_timestamp, middle,
                         latest_timestamp - earliest_timestamp, True)
     count_inside, events_in_circle, highest_timedelta, latest_timestamp = \
         self._get_count_and_coords_in_circle_within_timedelta(middle, relations,
                                                               earliest_timestamp, latest_timestamp,
                                                               max_radius)
     middle_event = (latest_timestamp, middle_event[1], highest_timedelta,
                     middle_event[3])
     if count_inside <= self.max_count_per_circle and count_inside == len(
             to_be_inspected):
         return middle_event, events_in_circle
     elif count_inside > self.max_count_per_circle:
         to_be_inspected = [
             to_keep for to_keep in to_be_inspected
             if not to_keep.other_event == farthest_away
         ]
         return self._get_circle(event, to_be_inspected, relations,
                                 distance_to_farthest)
     else:
         return middle_event, events_in_circle
コード例 #2
0
ファイル: s2Helper.py プロジェクト: kimzky/MAD
    def _generate_locations(distance: float, geofence_helper: GeofenceHelper):
        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))

        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.')
            else:
                logger.info("Ordering location")
                results = S2Helper.order_location_list_rows(results)
        return results
コード例 #3
0
ファイル: s2Helper.py プロジェクト: daangroot/MAD-fork
    def _generate_locations(distance: float, geofence_helper: GeofenceHelper):
        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.')
            else:
                logger.info("Ordering location")
                results = S2Helper.order_location_list_rows(results)
        return results