This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def predict(max_branch: int = 3, | |
max_length: int = 10) -> FeatureGroup | None: | |
fg = folium.FeatureGroup(name="polylines") | |
if "token_list" in st.session_state: | |
hex_list = st.session_state["token_list"] | |
seed = hex_list[-3:-1] | |
if len(seed) > 1: | |
paths = expand_seed(seed[0], seed[1], | |
max_branch=max_branch, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_successors(h0: int, h1: int) -> Counter: | |
cnt = get_cache_successors(h0, h1) | |
if cnt is None: | |
db = TrajDb() | |
sql = "select t2 from triple where t0=? and t1=?" | |
successors = [r[0] for r in db.query(sql, [int(h0), int(h1)])] | |
cnt = Counter(successors) | |
set_cache_successors(h0, h1, cnt) | |
return cnt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compute_probability(token_list: list[int]) -> float: | |
nodes = token_list[1:-1] | |
prob = 0.0 | |
if len(nodes) > 2: | |
prob = 1.0 | |
for i in range(len(nodes)-2): | |
t0, t1, t2 = nodes[i:i+3] | |
cnt = get_successors(int(t0), int(t1)) | |
if len(cnt): | |
prob *= cnt[t2] / cnt.total() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insert_h3_nodes(h3_nodes: list[tuple[int,tuple[float,float]]]): | |
db = TrajDb() | |
sql = "insert or ignore into h3_node (h3, lat, lon) values (?, ?, ?)" | |
db.execute_sql(sql, [(n[0], n[1][1], n[1][0]) for n in h3_nodes], many=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insert_triples(traj_id: int, | |
triples: list[(int,int,int)]): | |
db = TrajDb() | |
sql = "insert into triple (traj_id, t0, t1, t2) values (?, ?, ?, ?)" | |
params = [(traj_id, t0, t1, t2) for t0, t1, t2 in triples] | |
db.execute_sql(sql, params, many=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insert_h3(traj_id: int, | |
h3_list: list[int]) -> None: | |
db = TrajDb() | |
sql = "insert into traj_h3 (traj_id, h3) values (?, ?)" | |
params = [[traj_id, int(h)] for h in h3_list] | |
db.execute_sql(sql, params, many=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_triples(hex_list: list[int]) -> list[(int,int,int)]: | |
triples = [] | |
if len(hex_list) > 2: | |
for i in range(len(hex_list) - 2): | |
t0, t1, t2 = hex_list[i:i + 3] | |
triples.append((t0, t1, t2)) | |
return triples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from valhalla import Actor, get_config | |
config = get_config(tile_extract='./valhalla/custom_files/valhalla_tiles.tar', | |
verbose=True) | |
actor = Actor(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install pyvalhalla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run -it --rm --name valhalla_gis-ops -p 8002:8002 \ | |
-v $PWD/valhalla/custom_files:/custom_files \ | |
-e tile_urls=http://download.geofabrik.de/north-america/us/michigan-latest.osm.pbf \ | |
-e serve_tiles=True -e build_admins=True \ | |
docker.pkg.github.com/gis-ops/docker-valhalla/valhalla:3.3.0 |