Example #1
0
    def check_latency_marker(self, event: Message) -> Optional[int]:
        """
        Checks if a message is a latency marker

        Args:
            event: The event details protobuf message

        Returns:
            The geocell if the message is a latency marker, None otherwise
        """
        # Geocells are used to identify and track latency markers
        if hasattr(event, "geocell"):
            cell = event.geocell
        elif hasattr(event, "latitude") and hasattr(event, "longitude"):
            cell = h3.geo_to_h3(event.latitude, event.longitude,
                                self.h3_resolution)
        else:
            return

        if hasattr(event, "vehicle") and hasattr(event.vehicle, "operator"):
            # For input.* events, we can check for the special operator
            if event.vehicle.operator == self.LATENCY_MARKER_OPERATOR:
                return cell
        else:
            # For analytics.* events, we need to check by geocell distance
            try:
                if h3.h3_distance(self.origin, cell) <= self.h3_max_k:
                    return cell
            except SystemError:
                # System errors can occur when the distance is too large
                pass
Example #2
0
def return_h3_inds(loc_list, rot=None):
    if rot is None:
        rot = random_ll_rot(identity=True)
    locs_rotated = [rot(loc[0], loc[1]) for loc in loc_list]
    return [
        h3.geo_to_h3(lng=loc[0], lat=loc[1], resolution=3)
        for loc in locs_rotated
    ]
Example #3
0
def geo_to_placekey(lat, long):
    """
    Convert latitude and longitude into a Placekey.

    :param lat: Latitude (float)
    :param long: Longitude (float)
    :return: Placekey (string)

    """
    return _encode_h3_int(h3_int.geo_to_h3(lat, long, resolution=RESOLUTION))
Example #4
0
    def __init__(
        self,
        h3_resolution: int,
        h3_max_k: int,
    ):
        # Use "Point Nemo" as latency marker origin since we can assume no real events come from there
        self.origin = h3.geo_to_h3(-48.875, -123.393, h3_resolution)
        self.h3_resolution = h3_resolution
        self.h3_max_k = h3_max_k

        self.coordinate_generator = iter(
            SpiralingCoordinateGenerator(self.origin, h3_max_k))
Example #5
0
def test_int_output():
    lat = 37.7752702151959
    lng = -122.418307270836

    assert h3.geo_to_h3(lat, lng, 9) == 617700169958293503
    assert h3.geo_to_h3(lat, lng, 9) == 0x8928308280fffff
Example #6
0
def _hexagon(resolution: 'int') -> 'Callable[[float, float, int], int]':
    return lambda column: H3.geo_to_h3(column[_LATITUDE], column[_LONGITUDE],
                                       resolution)
Example #7
0
REPLACEMENT_CHARS = "eu"
REPLACEMENT_MAP = (
    ("prn", "pre"),
    ("f4nny", "f4nne"),
    ("tw4t", "tw4e"),
    ("ngr", "ngu"),  # 'u' avoids introducing 'gey'
    ("dck", "dce"),
    ("vjn", "vju"),  # 'u' avoids introducing 'jew'
    ("fck", "fce"),
    ("pns", "pne"),
    ("sht", "she"),
    ("kkk", "kke"),
    ("fgt", "fgu"),  # 'u' avoids introducing 'gey'
    ("dyk", "dye"),
    ("bch", "bce"))
HEADER_BITS = bin(h3_int.geo_to_h3(0.0, 0.0,
                                   resolution=RESOLUTION))[2:].zfill(64)[:12]
BASE_CELL_SHIFT = 2**(3 * 15
                      )  # Adding this will increment the base cell value by 1
UNUSED_RESOLUTION_FILLER = 2**(3 * (15 - BASE_RESOLUTION)) - 1
FIRST_TUPLE_REGEX = '[' + ALPHABET + REPLACEMENT_CHARS + PADDING_CHAR + ']{3}'
TUPLE_REGEX = '[' + ALPHABET + REPLACEMENT_CHARS + ']{3}'
WHERE_REGEX = re.compile(
    '^' + '-'.join([FIRST_TUPLE_REGEX, TUPLE_REGEX, TUPLE_REGEX]) + '$')
WHAT_REGEX = re.compile('^[' + ALPHABET + ']{3}(-[' + ALPHABET + ']{3})?$')


def _get_header_int():
    """
    :return: An integer corresponding to the header of an H3 integer
    """
    header_int = 0