"""compute person.walkfactor from walks in tripinfo-output"""
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..'))
from sumolib.output import parse
from sumolib.miscutils import Statistics
from sumolib.options import ArgumentParser
def parse_args():
optParser = ArgumentParser()
optParser.add_argument("tripinfos", category="input", type=optParser.file, help="Trip Info file")
optParser.add_argument("--length", type=float, default=0.1, help="length threshold (default: 0.1)")
return optParser.parse_args()
def main(tripinfos, lengthThreshold=0.1):
lengthThreshold = float(lengthThreshold)
stats = Statistics('walkfactor')
statsZeroDuration = Statistics('length of zero-duration walks')
statsShort = Statistics('duration of short walks (length <= %s)' % lengthThreshold)
numUnfinished = 0
for personinfo in parse(tripinfos, 'personinfo'):
if personinfo.hasChild('walk'):
for i, walk in enumerate(personinfo.walk):
if walk.arrival[0] == '-':
numUnfinished += 1
continue
walkID = "%s.%s" % (personinfo.id, i)
duration = float(walk.duration)
routeLength = float(walk.routeLength)
if duration > 0:
if routeLength <= lengthThreshold:
statsShort.add(duration, walkID)
else:
avgSpeed = routeLength / duration
walkFactor = avgSpeed / float(walk.maxSpeed)
stats.add(walkFactor, walkID)
else:
statsZeroDuration.add(routeLength, walkID)
print(stats)
if statsZeroDuration.count() > 0:
print(statsZeroDuration)
if statsShort.count() > 0:
print(statsShort)
if numUnfinished > 0:
print("unfinished walks: %s" % numUnfinished)
if __name__ == "__main__":
options = parse_args()
main(options.tripinfos, options.length)