Parse into libraries and nodes

This commit is contained in:
Ruben van de Ven 2024-04-12 15:31:55 +02:00
parent 91704bb741
commit 3312cb6f23
1 changed files with 28 additions and 1 deletions

View File

@ -4,6 +4,33 @@ import json
node_names = set()
edges = []
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
with open("data/requests.csv") as fp:
reader = csv.DictReader(fp, delimiter=";")
for item in reader:
@ -17,7 +44,7 @@ nodes = [{'name': n} for n in node_names]
print(f"{len(nodes)} nodes, {len(edges)} edges")
data = {
'nodes': nodes,
'nodes': list(libraries.values()), #nodes,
'edges': edges
}