import pandas as pd
import numpy as np

PFILE = "part-00000-tid-257698335488947142-c2a078b1-adfb-43b6-98b6-947dfaff5eda-5415-1.c000.parquet"
pq = pd.read_parquet(PFILE)

print("Read Parquet of size", len(pq))

TFILE = "tugs.csv"
tugs = pd.read_csv(TFILE)

print("Read Tugboat Information")

mmsi = tugs["MMSI"].dropna().astype(np.int32)
S = 0
for idx in mmsi:
	# print(idx)
	tug = pq[pq["mmsi"] == idx]
	S += len(tug)
	if len(tug) > 0:
		tug.to_csv("results/%s.csv" % str(idx), columns=["mmsi", "ts", "lon", "lat", "speed"], index=False)
		# tug.to_parquet("results/%s.parquet" % str(idx), compression=None)
print(S, "events stored")



