import pandas as pd
from de2.routing import get_graph, get_closest_vertex, pathfinder

berths = pd.read_csv("berths.csv", index_col=0)
bmap = {}
for _, berth in berths.iterrows():
	bmap[berth["lpl_id"]] = berth["center_lon"], berth["center_lat"]

graph = get_graph()

locks = ["ZAS", "BOS", "BES", "KAS", "KIS"]
mtx = pd.DataFrame(columns=["source"] + locks)

for _, berth in berths.iterrows():
	row = [berth["lpl_id"]]
	bnode = get_closest_vertex(graph, berth["center_lon"], berth["center_lat"])

	for lock in locks:
		_, ds = pathfinder(graph, bmap[berth["lpl_id"]], bmap[lock])
		row.append(sum(ds))

	mtx.loc[len(mtx.index)] = row

mtx.to_csv("berths2.csv", index=False)

