/usr/share/sumo/tools/output/netdumpmean.py is in sumo-tools 0.15.0~dfsg-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #!/usr/bin/env python
"""
@file netdumpmean.py
@author Daniel Krajzewicz
@author Michael Behrisch
@date 2007-10-25
@version $Id: netdumpmean.py 11671 2012-01-07 20:14:30Z behrisch $
This script reads two network dumps,
computes the mean values
and writes the results into the output file
SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
Copyright (C) 2008-2012 DLR (http://www.dlr.de/) and contributors
All rights reserved
"""
import os, string, sys
from optparse import OptionParser
from xml.sax import saxutils, make_parser, handler
from datetime import datetime
class WeightsReader(handler.ContentHandler):
"""Reads the dump file"""
def __init__(self):
self._id = ''
self._edgeValues = {}
self._intervalBegins = []
self._intervalEnds = []
def startElement(self, name, attrs):
if name == 'interval':
self._beginTime = int(attrs['begin'])
self._intervalBegins.append(self._beginTime)
self._intervalEnds.append(int(attrs['end']))
self._edgeValues[self._beginTime] = {}
if name == 'edge':
self._id = attrs['id']
self._edgeValues[self._beginTime][self._id] = {}
for attr in attrs.getQNames():
if attr!="id":
self._edgeValues[self._beginTime][self._id][attr] = float(attrs[attr])
def sub(self, weights, exclude):
for t in self._edgeValues:
for e in self._edgeValues[t]:
for a in self._edgeValues[t][e]:
if a not in exclude:
self._edgeValues[t][e][a] = (self._edgeValues[t][e][a] + weights._edgeValues[t][e][a]) / 2.
def write(self, options):
fd = open(options.output, "w")
fd.write("<?xml version=\"1.0\"?>\n\n")
fd.write("<!-- generated on %s by netdumpdiv.py \n" % datetime.now())
fd.write(" -1 %s\n" % options.dump1)
fd.write(" -2 %s\n" % options.dump2)
fd.write(" -o %s\n" % options.output)
fd.write("-->\n\n")
fd.write("<netstats>\n")
for i in range(0, len(self._intervalBegins)):
fd.write(" <interval begin=\"%s\" end=\"%s\">\n" % (self._intervalBegins[i], self._intervalEnds[i]))
t = self._intervalBegins[i]
for e in self._edgeValues[t]:
fd.write(" <edge id=\"%s\"" % e)
for a in self._edgeValues[t][e]:
fd.write(" %s=\"%s\"" % (a, self._edgeValues[t][e][a]))
fd.write("/>\n")
fd.write(" </interval>\n")
fd.write("</netstats>\n")
# initialise
optParser = OptionParser()
optParser.add_option("-v", "--verbose", action="store_true", dest="verbose",
default=False, help="tell me what you are doing")
# i/o
optParser.add_option("-1", "--dump1", dest="dump1",
help="First dump (mandatory)", metavar="FILE")
optParser.add_option("-2", "--dump2", dest="dump2",
help="Second dump (mandatory)", metavar="FILE")
optParser.add_option("-o", "--output", dest="output",
help="Name for the output", metavar="FILE")
optParser.add_option("-e", "--exclude", dest="exclude",
help="Exclude these values from being changed (stay as in 1)", metavar="FILE")
# parse options
(options, args) = optParser.parse_args()
parser = make_parser()
# read dump1
if options.verbose:
print "Reading dump1..."
weights1 = WeightsReader()
parser.setContentHandler(weights1)
parser.parse(options.dump1)
# read dump2
if options.verbose:
print "Reading dump2..."
weights2 = WeightsReader()
parser.setContentHandler(weights2)
parser.parse(options.dump2)
# process
if options.verbose:
print "Computing mean..."
exclude = []
if options.exclude:
exclude = options.exclude.split(",")
weights1.mean(weights2, exclude)
# save
if options.verbose:
print "Writing..."
weights1.write(options)
|