backend/hafas: combine walking legs
This commit is contained in:
parent
14aec20be3
commit
5a4147cfa0
|
@ -1,6 +1,7 @@
|
||||||
import ../types
|
import ../types
|
||||||
import json
|
import json
|
||||||
import leg
|
import leg
|
||||||
|
import options
|
||||||
|
|
||||||
proc mkParseJourney*(common: CommonData): proc =
|
proc mkParseJourney*(common: CommonData): proc =
|
||||||
proc parseJourney(j: JsonNode): Journey =
|
proc parseJourney(j: JsonNode): Journey =
|
||||||
|
@ -11,4 +12,23 @@ proc mkParseJourney*(common: CommonData): proc =
|
||||||
result.legs = j{"secL"}.getElems().map(mkParseLeg(common))
|
result.legs = j{"secL"}.getElems().map(mkParseLeg(common))
|
||||||
result.lastUpdated = common.timeStamp
|
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
|
return parseJourney
|
||||||
|
|
Loading…
Reference in a new issue