Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/output/walkFactor.py
169674 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
4
# Copyright (C) 2012-2025 German Aerospace Center (DLR) and others.
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file walkFactor.py
16
# @author Jakob Erdmann
17
# @date 2017-12-04
18
19
"""compute person.walkfactor from walks in tripinfo-output"""
20
21
from __future__ import absolute_import
22
from __future__ import print_function
23
import os
24
import sys
25
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..'))
26
from sumolib.output import parse # noqa
27
from sumolib.miscutils import Statistics # noqa
28
from sumolib.options import ArgumentParser # noqa
29
30
31
def parse_args():
32
optParser = ArgumentParser()
33
optParser.add_argument("tripinfos", category="input", type=optParser.file, help="Trip Info file")
34
optParser.add_argument("--length", type=float, default=0.1, help="length threshold (default: 0.1)")
35
return optParser.parse_args()
36
37
38
def main(tripinfos, lengthThreshold=0.1):
39
lengthThreshold = float(lengthThreshold)
40
stats = Statistics('walkfactor')
41
statsZeroDuration = Statistics('length of zero-duration walks')
42
statsShort = Statistics('duration of short walks (length <= %s)' % lengthThreshold)
43
numUnfinished = 0
44
for personinfo in parse(tripinfos, 'personinfo'):
45
if personinfo.hasChild('walk'):
46
for i, walk in enumerate(personinfo.walk):
47
if walk.arrival[0] == '-':
48
numUnfinished += 1
49
continue
50
walkID = "%s.%s" % (personinfo.id, i)
51
duration = float(walk.duration)
52
routeLength = float(walk.routeLength)
53
if duration > 0:
54
if routeLength <= lengthThreshold:
55
statsShort.add(duration, walkID)
56
else:
57
avgSpeed = routeLength / duration
58
walkFactor = avgSpeed / float(walk.maxSpeed)
59
stats.add(walkFactor, walkID)
60
else:
61
statsZeroDuration.add(routeLength, walkID)
62
63
print(stats)
64
if statsZeroDuration.count() > 0:
65
print(statsZeroDuration)
66
if statsShort.count() > 0:
67
print(statsShort)
68
if numUnfinished > 0:
69
print("unfinished walks: %s" % numUnfinished)
70
71
72
if __name__ == "__main__":
73
options = parse_args()
74
main(options.tripinfos, options.length)
75
76