Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/tools/sumolib/statistics/runner.py
428387 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2026 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file runner.py
15
# @author Laura Bieker-Walz
16
# @date 14.9.2020
17
18
from __future__ import absolute_import
19
from __future__ import print_function
20
21
22
import os
23
import sys
24
if 'SUMO_HOME' in os.environ:
25
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
26
sys.path.append(tools)
27
else:
28
sys.exit("please declare environment variable 'SUMO_HOME'")
29
import sumolib.statistics # noqa
30
31
print(sumolib.statistics.round(1.5))
32
print(sumolib.statistics.round(-1.5))
33
print(sumolib.statistics.setPrecision("2.01%.2f", 3))
34
print(sumolib.statistics.geh(0, 0))
35
print(sumolib.statistics.geh(10, 1))
36
37
s = sumolib.statistics.Statistics(10)
38
print(s.toString())
39
s.add(1)
40
print(s.toString())
41
s2 = sumolib.statistics.Statistics(5)
42
s2.add(5)
43
s2.add(4)
44
s2.add(3)
45
print(s2.toString())
46
s.update(s2)
47
print(s.toString())
48
s.clear()
49
print(s.toString())
50
s.add(1)
51
s.add(10)
52
s.add(1)
53
s.add(1)
54
print(s.count())
55
print(s.avg())
56
print(s.avg_abs())
57
print("mean: %.3f, standard deviation: %.3f" % s.meanAndStdDev())
58
print(s.relStdDev())
59
print(s.mean())
60
print(s.mean_abs())
61
print(s.average_absolute_deviation_from_mean())
62
print(s.median())
63
print(s.median_abs())
64
print(s.quartiles())
65
print(s.rank(0.5))
66
print(s.histogram())
67
s3 = sumolib.statistics.Statistics(10, histogram=True)
68
for i in range(10):
69
s3.add(i)
70
i += 1
71
print(s3.histogram())
72
73