55 lines
No EOL
1.3 KiB
Python
55 lines
No EOL
1.3 KiB
Python
import csv
|
|
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:
|
|
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 = {
|
|
'nodes': list(libraries.values()), #nodes,
|
|
'edges': edges
|
|
}
|
|
|
|
fn = 'data/parsed_requests.json'
|
|
with open(fn, 'w') as fp:
|
|
json.dump(data, fp)
|
|
|
|
print(f"Written to {fn}") |