slightly better neo4j import api that has provider prefix and what not be specified as an option

This commit is contained in:
Pagwin 2025-04-24 15:56:35 -04:00
parent c39cbab3dd
commit 9118e59b3a
No known key found for this signature in database
GPG key ID: 81137023740CA260

View file

@ -37,13 +37,13 @@ export async function graph_setup(
const jsonData = await Deno.readTextFile(OCCT_stops_json);
const locationNodes: LocationNode[] = JSON.parse(jsonData);
await stops_json_node_import(session, locationNodes);
await stops_json_node_import(session, locationNodes, { provider: "OCCT" });
const BCTStopsData = await Deno.readTextFile(BCT_GTFS_stops_txt);
const BCT_stops = await parse_gtfs_stops(BCTStopsData);
await stops_gtfs_node_import(session, BCT_stops);
await stops_gtfs_node_import(session, BCT_stops, { provider: "BCT" });
await session.close();
}
@ -51,7 +51,9 @@ export async function graph_setup(
async function stops_json_node_import(
session: Neo4j.Session,
stops: LocationNode[],
options: { provider: string },
) {
const { provider } = options;
for (const node of stops) {
await session.run(
`
@ -60,15 +62,15 @@ async function stops_json_node_import(
n.originalId = $originalId,
n.latitude = $lat,
n.longitude = $lng,
n.source = 'OCCT'
n.source = '${provider}'
ON MATCH SET
n.originalId = $originalId,
n.latitude = $lat,
n.longitude = $lng,
n.source = 'OCCT'
n.source = '${provider}'
`,
{
id: `OCCT_${node.id}`,
id: `${provider}_${node.id}`,
originalId: node.id,
lat: node.lat,
lng: node.lng,
@ -80,6 +82,8 @@ async function stops_json_node_import(
async function stops_gtfs_node_import(
session: Neo4j.Session,
stops: GTFSStop[],
// default provider is to avoid breaking upstream
options: { provider: string },
) {
// Add GTFS stops to Neo4j
for (const stop of stops) {
@ -89,7 +93,7 @@ async function stops_gtfs_node_import(
) {
continue;
}
const { provider } = options;
// Use MERGE to update existing nodes or create new ones
await session.run(
`
@ -102,7 +106,7 @@ async function stops_gtfs_node_import(
s.parentStation = $parentStation,
s.zoneId = $zoneId,
s.url = $url,
s.source = 'BCT'
s.source = '${provider}'
ON MATCH SET
s.name = $name,
s.latitude = $lat,
@ -111,10 +115,10 @@ async function stops_gtfs_node_import(
s.parentStation = $parentStation,
s.zoneId = $zoneId,
s.url = $url,
s.source = 'BCT'
s.source = '${provider}'
`,
{
id: "BCT_" + stop.stop_id,
id: `${provider}_` + stop.stop_id,
name: stop.stop_name,
lat: parseFloat(stop.stop_lat),
lng: parseFloat(stop.stop_lon),