def _directly_surrounding_gmo_cells_containing_stops_around_current_position(self, gmo_cells) -> List: """ Returns a list of cells containing forts Args: gmo_cells: Returns: List of cells that actually contain forts around the current position """ cells_with_forts = [] if not gmo_cells: self.logger.debug("No GMO cells passed for surrounding cell check") return cells_with_forts # 35m radius around current location (thus cells that may be touched by that radius hopefully get included) s2cells_valid_around_location: List[CellId] = \ S2Helper.get_s2cells_from_circle(self.current_location.lat, self.current_location.lng, RADIUS_FOR_CELLS_CONSIDERED_FOR_STOP_SCAN, S2_GMO_CELL_LEVEL) s2cell_ids_valid: List[str] = [s2cell.id() for s2cell in s2cells_valid_around_location] for cell in gmo_cells: # each cell contains an array of forts, check each cell for a fort with our current location (maybe +- # very very little jitter) and check its properties if cell["id"] not in s2cell_ids_valid: continue forts: list = cell.get("forts", None) if forts: cells_with_forts.append(cell) if not cells_with_forts: self.logger.debug2("GMO cells around current position ({}) do not contain stops ", self.current_location) return cells_with_forts
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