commit 5a4147cfa0d21bc6be036f3c23aa3c2868bd7441
parent 14aec20be3cc97f25692ebbe14ce36de69eeceba
Author: Milan Pässler <me@pbb.lc>
Date: Sat, 8 Feb 2020 00:02:06 +0100
parent 14aec20be3cc97f25692ebbe14ce36de69eeceba
Author: Milan Pässler <me@pbb.lc>
Date: Sat, 8 Feb 2020 00:02:06 +0100
backend/hafas: combine walking legs
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/src/backend/hafas/parse/journey.nim b/src/backend/hafas/parse/journey.nim @@ -1,6 +1,7 @@ import ../types import json import leg +import options proc mkParseJourney*(common: CommonData): proc = proc parseJourney(j: JsonNode): Journey = @@ -11,4 +12,23 @@ proc mkParseJourney*(common: CommonData): proc = result.legs = j{"secL"}.getElems().map(mkParseLeg(common)) result.lastUpdated = common.timeStamp + # combine walking legs + var i = 0 + var firstWalking = -1 + while true: + inc(i) + if i >= len(result.legs): break + if result.legs[i].isWalking: + if firstWalking == -1: + firstWalking = i + continue + + else: + result.legs[firstWalking].arrival = result.legs[i].arrival + result.legs[firstWalking].distance.get += result.legs[i].distance.get + result.legs.delete(i) + dec(i) + else: + firstWalking = -1 + return parseJourney