Ejemplo n.º 1
0
    def _get_count_and_coords_in_circle_within_timedelta(
            self, middle, relations, earliest_timestamp, latest_timestamp,
            max_radius):
        inside_circle = []
        highest_timedelta = 0
        if self.useS2:
            region = s2sphere.CellUnion(
                S2Helper.get_S2cells_from_circle(middle.lat, middle.lng,
                                                 self.max_radius,
                                                 self.S2level))

        for event_relations in relations:
            # exclude previously clustered events...
            if len(event_relations) == 4 and event_relations[3]:
                inside_circle.append(event_relations)
                continue
            distance = get_distance_of_two_points_in_meters(
                middle.lat, middle.lng, event_relations[1].lat,
                event_relations[1].lng)
            event_in_range = 0 <= distance <= max_radius
            if self.useS2:
                event_in_range = region.contains(
                    s2sphere.LatLng.from_degrees(
                        event_relations[1].lat,
                        event_relations[1].lng).to_point())
            # timedelta of event being inspected to the earliest timestamp
            timedelta_end = latest_timestamp - event_relations[0]
            timedelta_start = event_relations[0] - earliest_timestamp
            if timedelta_end < 0 and event_in_range:
                # we found an event starting past the current latest timestamp, let's update the latest_timestamp
                latest_timestamp_temp = latest_timestamp + abs(timedelta_end)
                if latest_timestamp_temp - earliest_timestamp <= self.max_timedelta_seconds:
                    latest_timestamp = latest_timestamp_temp
                    highest_timedelta = highest_timedelta + abs(timedelta_end)
                    inside_circle.append(event_relations)
            elif timedelta_start < 0 and event_in_range:
                # we found an event starting before earliest_timestamp, let's check that...
                earliest_timestamp_temp = earliest_timestamp - \
                                          abs(timedelta_start)
                if latest_timestamp - earliest_timestamp_temp <= self.max_timedelta_seconds:
                    earliest_timestamp = earliest_timestamp_temp
                    highest_timedelta = highest_timedelta + \
                                        abs(timedelta_start)
                    inside_circle.append(event_relations)
            elif timedelta_end >= 0 and timedelta_start >= 0 and event_in_range:
                # we found an event within our current timedelta and proximity, just append it to the list
                inside_circle.append(event_relations)

        return len(
            inside_circle), inside_circle, highest_timedelta, latest_timestamp
Ejemplo n.º 2
0
Archivo: map.py Proyecto: rgeyer/MAD
def get_routepool_coords(coord_list, mode):
    route_serialized = []
    s2cells = {}
    prepared_coords = coord_list
    if isinstance(coord_list, RoutePoolEntry):
        prepared_coords = coord_list.subroute
    for location in prepared_coords:
        route_serialized.append(
            [getCoordFloat(location.lat),
             getCoordFloat(location.lng)])
        if mode == "raids_mitm":
            cells = S2Helper.get_S2cells_from_circle(location.lat,
                                                     location.lng, 490)
            for cell in cells:
                s2cells[str(cell.id())] = S2Helper.coords_of_cell(cell.id())
    return (route_serialized, s2cells)