Skip to content

Commit 02cbe0a

Browse files
committed
stop-registry-importer Quay shelter equipment
1 parent 0dc2ec6 commit 02cbe0a

1 file changed

Lines changed: 39 additions & 20 deletions

File tree

stop-registry-importer/importer.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
keyed by label.
1919
2020
Data Mapping:
21-
- quayInputForJore3Stop() — Transforms a single Jore3 stop row into the GraphQL QuayInput format, mapping fields
22-
like shelter type, electricity, condition, accessibility properties, and equipment using helper functions
21+
- quayInputForJore4Stop() — Transforms a single Jore3 stop row into the Jore4 GraphQL QuayInput format, mapping
22+
fields like shelter type, electricity, condition, accessibility properties, and equipment using helper functions
2323
(mapStopModel, mapStopType, mapStopElectricity, mapStopCondition, mapBoolean, toFloat).
2424
2525
Import Loop (main logic):
@@ -361,7 +361,41 @@ def toFloat(value):
361361
return float(jsonval)
362362
return None
363363

364-
def quayInputForJore3Stop(jore3row, label, validityStart, validityEnd, lon, lat):
364+
def getShelterEquipment(jore3row):
365+
# Build the shared shelter payload once; first shelter gets shelterExternalId separately.
366+
baseShelterEquipment = {
367+
# "shelterNumber": ???, # TODO: no candidate source confirmed yet
368+
"enclosed": jore3row['pysakkityyppi'] == '01' or jore3row['pysakkityyppi'] == '02',
369+
"shelterType": mapStopType(jore3row['pysakkityyppi']),
370+
"shelterElectricity": mapStopElectricity(jore3row['sahko']),
371+
# shelterLighting: primary jr_esteettomyys.valaistus, fallback inferred from jr_varustelutiedot_uusi.sahko
372+
"shelterLighting": mapBoolean(jore3row.get('valaistus')) if jore3row.get('valaistus') is not None else False,
373+
"shelterCondition": mapStopCondition(jore3row['katos_kunto']),
374+
"timetableCabinets": toFloat(jore3row['kpl_lisavarusteet']) if jore3row['lisavarusteet'] == '01' else 0,
375+
"trashCan": mapBoolean(jore3row['roska_astia']),
376+
"shelterHasDisplay": mapBoolean(jore3row['nayttolaitteet']),
377+
"bicycleParking": jore3row['lisavarusteet'] == '03' or jore3row['lisavarusteet'] == '04',
378+
# leaningRail: jr_esteettomyys.takakaide_korkeus used as presence proxy
379+
"leaningRail": jore3row.get('takakaide_korkeus') is not None,
380+
# outsideBench: jr_esteettomyys.penkki
381+
"outsideBench": mapBoolean(jore3row.get('penkki')),
382+
# "shelterFasciaBoardTaping": ???, # TODO: jr_varustelutiedot_uusi.ilme is potential proxy, pending code-value review
383+
# stepFree: jr_esteettomyys.esteeton_kulku
384+
"stepFree": mapBoolean(jore3row.get('esteeton_kulku')),
385+
# "seats": ???, # TODO: no numeric seat-count source; jr_esteettomyys.penkki is presence only
386+
}
387+
388+
shelterCount = jore3row['kpl_pysakkityyppi'] or 0
389+
shelterEquipment = None
390+
if shelterCount > 0:
391+
firstShelter = {
392+
"shelterExternalId": jore3row['jcd_nro'] + jore3row['cc_nro'],
393+
**baseShelterEquipment
394+
}
395+
shelterEquipment = [firstShelter] + [baseShelterEquipment.copy() for _ in range(shelterCount - 1)]
396+
return shelterEquipment
397+
398+
def quayInputForJore4Stop(jore3row, label, validityStart, validityEnd, lon, lat):
365399
return {
366400
"publicCode": label,
367401
"privateCode": {
@@ -443,22 +477,7 @@ def quayInputForJore3Stop(jore3row, label, validityStart, validityEnd, lon, lat)
443477
}
444478
},
445479
"placeEquipments": {
446-
"shelterEquipment": ([
447-
{
448-
"enclosed": jore3row['pysakkityyppi'] == '01' or jore3row['pysakkityyppi'] == '02',
449-
"shelterType": mapStopType(jore3row['pysakkityyppi']),
450-
"shelterElectricity": mapStopElectricity(jore3row['sahko']),
451-
"shelterLighting": True,
452-
"shelterCondition": mapStopCondition(jore3row['katos_kunto']),
453-
"timetableCabinets": toFloat(jore3row['kpl_lisavarusteet']) if jore3row['lisavarusteet'] == '01' else 0,
454-
"trashCan": mapBoolean(jore3row['roska_astia']),
455-
"shelterHasDisplay": mapBoolean(jore3row['nayttolaitteet']),
456-
"bicycleParking": jore3row['lisavarusteet'] == '03' or jore3row['lisavarusteet'] == '04',
457-
"leaningRail": False,
458-
"outsideBench": False,
459-
"shelterFasciaBoardTaping": False
460-
}
461-
] * jore3row['kpl_pysakkityyppi']) if jore3row['kpl_pysakkityyppi'] else None,
480+
"shelterEquipment": getShelterEquipment(jore3row),
462481
"generalSign": {
463482
"numberOfFrames": toFloat(jore3row['kpl_kilvet'])
464483
}
@@ -618,7 +637,7 @@ def update_stop_place(lat, lon, validityStart, validityEnd, jore3result, quayInp
618637
lon = j4stopPoint['lon']
619638
validityStart = j4stopPoint['validity_start']
620639
validityEnd = j4stopPoint['validity_end']
621-
quayInput.append(quayInputForJore3Stop(j3stop, j4stopPoint['label'], validityStart, validityEnd,
640+
quayInput.append(quayInputForJore4Stop(j3stop, j4stopPoint['label'], validityStart, validityEnd,
622641
lon, lat))
623642
latCoords.append(lat)
624643
lonCoords.append(lon)

0 commit comments

Comments
 (0)