2024-04-05 18:32:15 +02:00
|
|
|
import csv
|
|
|
|
import json
|
|
|
|
|
|
|
|
node_names = set()
|
|
|
|
edges = []
|
|
|
|
|
2024-04-12 15:31:55 +02:00
|
|
|
libraries = {}
|
|
|
|
locations = {}
|
|
|
|
with open("data/locaties.csv") as fp:
|
|
|
|
reader = csv.DictReader(fp, delimiter=";")
|
|
|
|
for item in reader:
|
|
|
|
locatie = item['Locatie'].split(',')
|
|
|
|
try:
|
|
|
|
lat, lon = locatie
|
|
|
|
except ValueError as e:
|
|
|
|
lat, lon = None, None
|
|
|
|
library = {
|
|
|
|
'name': item['Library Name'],
|
|
|
|
'code': item['Library Code'],
|
|
|
|
'adres': item['Adres'],
|
|
|
|
'lat': lat,
|
|
|
|
'lon': lon,
|
|
|
|
}
|
|
|
|
location = {
|
|
|
|
'location': item['Location Name'],
|
|
|
|
'code': item['Location Code'],
|
|
|
|
'library': library
|
|
|
|
}
|
|
|
|
|
|
|
|
libraries[library['name']] = library
|
|
|
|
locations[location['code']] = location
|
|
|
|
|
|
|
|
|
2024-04-05 18:32:15 +02:00
|
|
|
with open("data/requests.csv") as fp:
|
|
|
|
reader = csv.DictReader(fp, delimiter=";")
|
|
|
|
for item in reader:
|
|
|
|
node_names.add(item['Owning Library Name'])
|
|
|
|
node_names.add(item['Pickup Location'])
|
|
|
|
edges.append(item)
|
|
|
|
|
|
|
|
|
|
|
|
nodes = [{'name': n} for n in node_names]
|
|
|
|
|
|
|
|
print(f"{len(nodes)} nodes, {len(edges)} edges")
|
|
|
|
|
|
|
|
data = {
|
2024-04-12 15:31:55 +02:00
|
|
|
'nodes': list(libraries.values()), #nodes,
|
2024-04-05 18:32:15 +02:00
|
|
|
'edges': edges
|
|
|
|
}
|
|
|
|
|
|
|
|
fn = 'data/parsed_requests.json'
|
|
|
|
with open(fn, 'w') as fp:
|
|
|
|
json.dump(data, fp)
|
|
|
|
|
|
|
|
print(f"Written to {fn}")
|