/usr/share/sumo/tools/district/countConnectionsInDistricts.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 | #!/usr/bin/env python
from xml.sax import saxutils, make_parser, handler
from optparse import OptionParser
import math
# written into the net. All members are "private".
class NetDistrictConnectionCountingHandler(handler.ContentHandler):
def __init__(self):
self._currentID = ""
self._districtSinkNo = {}
self._districtSourceNo = {}
def startElement(self, name, attrs):
if name == 'district':
self._currentID = attrs['id']
elif name == 'dsink':
if self._currentID in self._districtSinkNo:
self._districtSinkNo[self._currentID] = self._districtSinkNo[self._currentID] + 1
else:
self._districtSinkNo[self._currentID] = 1
elif name == 'dsource':
if self._currentID in self._districtSinkNo:
self._districtSourceNo[self._currentID] = self._districtSourceNo[self._currentID] + 1
else:
self._districtSourceNo[self._currentID] = 1
def writeResults(self, output):
fd = open(output, "w")
for district in self._districtSourceNo:
fd.write(district + ";" + str(self._districtSourceNo[district ]) + ";" + str(self._districtSinkNo[district ]) + "\n")
fd.close()
optParser = OptionParser()
optParser.add_option("-v", "--verbose", action="store_true", dest="verbose",
default=False, help="tell me what you are doing")
optParser.add_option("-n", "--net-file", dest="netfile",
help="read SUMO network(s) from FILE(s) (mandatory)", metavar="FILE")
optParser.add_option("-o", "--output", dest="output",
help="read SUMO network(s) from FILE(s) (mandatory)", metavar="FILE")
(options, args) = optParser.parse_args()
parser = make_parser()
reader = NetDistrictConnectionCountingHandler()
parser.setContentHandler(reader)
if options.verbose:
print "Reading net '" + options.netfile + "'"
parser.parse(options.netfile)
reader.writeResults(options.output)
|