71 lines
2.4 KiB
Nim
71 lines
2.4 KiB
Nim
import ../types
|
|
import ./stopover
|
|
import ./msg
|
|
import ./date
|
|
import ./line
|
|
import json
|
|
import options
|
|
|
|
proc parseLegPart(common: CommonData, lp: JsonNode): LegPart =
|
|
let h = lp.to(HafasStopParams)
|
|
let plannedDepartureTime = parseDate(common, h.dTimeS, h.dTZOffset)
|
|
let plannedArrivalTime = parseDate(common, h.aTimeS, h.aTZOffset)
|
|
|
|
if h.dPlatfS.isSome: result.plannedPlatform = h.dPlatfS
|
|
elif h.aPlatfS.isSome: result.plannedPlatform = h.aPlatfS
|
|
if h.dPlatfR.isSome: result.prognosedPlatform = h.dPlatfR
|
|
elif h.aPlatfR.isSome: result.prognosedPlatform = h.aPlatfR
|
|
if h.dTimeR.isSome: result.prognosedTime = parseDate(common, h.dTimeR, h.dTZOffset)
|
|
elif h.aTimeR.isSome: result.prognosedTime = parseDate(common, h.aTimeR, h.aTZOffset)
|
|
|
|
if plannedDepartureTime.isSome: result.plannedTime = plannedDepartureTime.get
|
|
elif plannedArrivalTime.isSome: result.plannedTime = plannedArrivalTime.get
|
|
else: raise newException(CatchableError, "missing departure and arrival time for leg")
|
|
|
|
result.point = common.points[h.locX.get]
|
|
|
|
proc mkParseLeg*(common: CommonData): proc =
|
|
proc parseLeg(l: JsonNode): Leg =
|
|
|
|
if l{"jny"}{"polyG"}{"polyXL"}.getElems().len() > 0:
|
|
result.polyline = some(Polyline(
|
|
type: "FeatureCollection",
|
|
))
|
|
for n in l{"jny"}{"polyG"}{"polyXL"}.getElems():
|
|
result.polyline.get.features &= common.polylines[n.getInt()].features
|
|
|
|
let typeStr = l{"type"}.getStr()
|
|
|
|
echo typeStr
|
|
|
|
if typeStr == "JNY":
|
|
result.direction = some(l{"jny"}{"dirTxt"}.getStr())
|
|
result.tripId = some(l{"jny"}{"jid"}.getStr())
|
|
result.line = common.parseLine(l["jny"]["prodX"].getInt())
|
|
|
|
let stopovers = l{"jny"}{"stopL"}.getElems()
|
|
if stopovers.len > 0:
|
|
result.stopovers = some(stopovers.map(mkParseStopover(common)))
|
|
|
|
let remarks = l{"jny"}{"msgL"}.getElems()
|
|
if remarks.len > 0:
|
|
result.remarks = some(remarks.map(mkParseMsg(common)))
|
|
|
|
elif typeStr == "WALK":
|
|
result.isWalking = true
|
|
result.distance = some(l{"gis"}{"dist"}.getInt())
|
|
|
|
elif typeStr == "TRSF" or typeStr == "DEVI":
|
|
result.isTransfer = true
|
|
|
|
else:
|
|
raise newException(CatchableError, "Unimplemented hafas leg type: " & typeStr)
|
|
|
|
result.departure = common.parseLegPart(l{"dep"})
|
|
result.arrival = common.parseLegPart(l{"arr"})
|
|
|
|
result.cancelled = l{"dep"}{"dCncl"}.getBool(false) or l{"arr"}{"aCncl"}.getBool(false)
|
|
|
|
return parseLeg
|
|
|