Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/coremodules/simulation/results.py
169689 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.
3
# SUMOPy module
4
# Copyright (C) 2012-2021 University of Bologna - DICAM
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 results.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
20
import os
21
import sys
22
import string
23
import types
24
from xml.sax import saxutils, parse, handler # , make_parser
25
from collections import OrderedDict
26
import numpy as np
27
28
29
from coremodules.modules_common import *
30
31
import agilepy.lib_base.classman as cm
32
import agilepy.lib_base.arrayman as am
33
import agilepy.lib_base.xmlman as xm
34
from agilepy.lib_base.geometry import *
35
36
from agilepy.lib_base.processes import Process, CmlMixin, ff, call, P
37
from coremodules.network.network import SumoIdsConf
38
from coremodules.demand.demandbase import RouteCounter, RouteReader
39
40
41
def load_results(filepath, parent=None, logger=None):
42
# typically parent is the SIMULATION
43
results = cm.load_obj(filepath, parent=parent)
44
if logger is not None:
45
results.set_logger(logger)
46
return results
47
48
49
class Connectionresults(am.ArrayObjman):
50
def __init__(self, ident, parent, trips, edges,
51
is_add_default=True,
52
name='Connection results',
53
info='Table with simulation results for each used connection. Consider only the finished trips',
54
**kwargs):
55
56
self._init_constants()
57
58
self._trips = trips
59
self._edges = edges
60
self._vtypes = trips.parent.vtypes
61
62
self._init_objman(ident=ident,
63
parent=parent, # main results object
64
info=info,
65
name=name,
66
**kwargs)
67
68
connections = edges.parent.connections
69
self.add_col(am.IdsArrayConf('ids_connection', connections,
70
groupnames=['state'],
71
is_index=True,
72
name='ID connection',
73
info='ID of connection.',
74
))
75
76
self.add_col(am.ArrayConf('total_flows', default=0,
77
dtype=np.float32,
78
groupnames=['results'],
79
name='Total flows',
80
unit='Veich.',
81
info='Total flow in the connection.',
82
))
83
84
self.add_col(am.ArrayConf('total_od_flows', 0,
85
dtype=np.float32,
86
groupnames=['results'],
87
name='Total OD flows',
88
unit='Veich.',
89
info='Total flow in the connection from OD trips.',
90
))
91
92
self.add_col(am.ArrayConf('total_vp_flows', 0,
93
dtype=np.float32,
94
groupnames=['results'],
95
name='Total vp flows',
96
unit='Veich.',
97
info='Total flow in the connection from virtual population.',
98
))
99
100
self.add_col(am.ArrayConf('total_ptline_flows', 0,
101
dtype=np.float32,
102
groupnames=['results'],
103
name='Total pt flows',
104
unit='Veich.',
105
info='Total public transport flow in the connection.',
106
))
107
108
self.add_col(am.ArrayConf('total_car_flows', 0,
109
dtype=np.float32,
110
groupnames=['results'],
111
name='Total car flows',
112
unit='Veich.',
113
info='Total car flow in the connection, taking into account all the od car and iauto.',
114
))
115
116
self.add_col(am.ArrayConf('total_bike_flows', 0,
117
dtype=np.float32,
118
groupnames=['results'],
119
name='Total bike flows',
120
unit='Veich.',
121
info='Total bike flow in the connection, taking into account all the od bike and ibike.',
122
))
123
124
self.add_col(am.ArrayConf('total_moto_flows', 0,
125
dtype=np.float32,
126
groupnames=['results'],
127
name='Total moto flows',
128
unit='Veich.',
129
info='Total moto flow in the connection, taking into account all the od moto and imoto.',
130
))
131
132
self.add_col(am.ArrayConf('total_iauto_flows', 0,
133
dtype=np.float32,
134
groupnames=['results'],
135
name='Total iauto flows',
136
unit='Veich.',
137
info='Total iauto flow in the connection.',
138
))
139
140
self.add_col(am.ArrayConf('total_ibike_flows', 0,
141
dtype=np.float32,
142
groupnames=['results'],
143
name='Total ibike flows',
144
unit='Veich.',
145
info='Total ibike flow in the connection.',
146
))
147
148
self.add_col(am.ArrayConf('total_imoto_flows', 0,
149
dtype=np.float32,
150
groupnames=['results'],
151
name='Total imoto flows',
152
unit='Veich.',
153
info='Total imoto flow in the connection.',
154
))
155
156
def _init_constants(self):
157
self._is_keep_right_car = False
158
self._is_keep_right_bus = True
159
self._is_keep_right_bike = True
160
self._is_keep_right_moto = False
161
self._is_keep_right_taxi = False
162
163
def evaluate_results(self, sumo, datapaths):
164
routeresults = self.parent.routeresults
165
ids_routeres = routeresults.get_ids()
166
# Consider warmup time
167
ids_routeres = ids_routeres[(routeresults.times_depart[ids_routeres] > sumo.time_warmup)]
168
# ids_routeres = ids_routeres[700:1000]
169
# print ids_routeres
170
ids_routeres_od = ids_routeres[(routeresults.ids_trip[ids_routeres] > 0)]
171
ids_od_modes = self._trips.parent.vtypes.ids_mode[self._trips.ids_vtype[routeresults.ids_trip[ids_routeres_od]]]
172
ids_routeres_od_auto = ids_routeres_od[(
173
ids_od_modes == self._edges.parent.modes.names.get_id_from_index('passenger'))]
174
ids_routeres_od_taxi = ids_routeres_od[(
175
ids_od_modes == self._edges.parent.modes.names.get_id_from_index('taxi'))]
176
ids_routeres_od_car = list(ids_routeres_od_auto)+list(ids_routeres_od_taxi)
177
ids_routeres_od_bike = ids_routeres_od[(
178
ids_od_modes == self._edges.parent.modes.names.get_id_from_index('bicycle'))]
179
ids_routeres_od_moto = ids_routeres_od[(
180
ids_od_modes == self._edges.parent.modes.names.get_id_from_index('motorcycle'))]
181
182
ids_routeres_iauto = ids_routeres[(routeresults.ids_iauto[ids_routeres] > 0)]
183
ids_routeres_ibike = ids_routeres[(routeresults.ids_ibike[ids_routeres] > 0)]
184
ids_routeres_imoto = ids_routeres[(routeresults.ids_imoto[ids_routeres] > 0)]
185
ids_routeres_vp = list(ids_routeres_iauto) + list(ids_routeres_ibike) + list(ids_routeres_imoto)
186
ids_routeres_ptlines = ids_routeres[(routeresults.ids_ptline[ids_routeres] > 0)]
187
ids_routeres_car = list(ids_routeres_od_car) + list(ids_routeres_iauto)
188
ids_routeres_bike = list(ids_routeres_od_bike) + list(ids_routeres_ibike)
189
ids_routeres_moto = list(ids_routeres_od_moto) + list(ids_routeres_imoto)
190
191
ids_edges = routeresults.ids_edges[ids_routeres]
192
ids_edges_od_car = routeresults.ids_edges[ids_routeres_od_car]
193
ids_edges_od = routeresults.ids_edges[ids_routeres_od]
194
ids_edges_iauto = routeresults.ids_edges[ids_routeres_iauto]
195
ids_edges_ibike = routeresults.ids_edges[ids_routeres_ibike]
196
ids_edges_imoto = routeresults.ids_edges[ids_routeres_imoto]
197
ids_edges_car = routeresults.ids_edges[ids_routeres_car]
198
ids_edges_bike = routeresults.ids_edges[ids_routeres_bike]
199
ids_edges_moto = routeresults.ids_edges[ids_routeres_moto]
200
ids_edges_ptline = routeresults.ids_edges[ids_routeres_ptlines]
201
ids_edges_vp = routeresults.ids_edges[ids_routeres_vp]
202
# print 'Routes:', len(ids_edges)
203
# print 'Car routes:', len(ids_edges_car)
204
# print 'OD Routes:', len(ids_edges_od)
205
# print 'VP routes:', len(ids_edges_vp)
206
# print 'iauto route:', len(ids_edges_iauto)
207
# print 'ibike routes:', len(ids_edges_ibike)
208
# print 'imoto routes:', len(ids_edges_imoto)
209
210
modes_od = []
211
modes_iauto = []
212
modes_ibike = []
213
modes_imoto = []
214
modes_car = []
215
modes_bike = []
216
modes_moto = []
217
modes_ptline = []
218
modes_vp = []
219
modes_tot = []
220
221
for trip in ids_routeres_od:
222
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[self._trips.ids_vtype[routeresults.ids_trip[trip]]]]
223
modes_od.append(mode)
224
225
for trip, id_iauto in zip(ids_routeres_iauto, routeresults.ids_iauto[ids_routeres_iauto]):
226
vtype = self._trips.parent.virtualpop.get_iautos().ids_vtype[id_iauto]
227
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
228
modes_iauto.append(mode)
229
230
for trip, id_ibike in zip(ids_routeres_ibike, routeresults.ids_ibike[ids_routeres_ibike]):
231
vtype = self._trips.parent.virtualpop.get_ibikes().ids_vtype[id_ibike]
232
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
233
modes_ibike.append(mode)
234
235
for trip, id_imoto in zip(ids_routeres_imoto, routeresults.ids_imoto[ids_routeres_imoto]):
236
vtype = self._trips.parent.virtualpop.get_imotos().ids_vtype[id_imoto]
237
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
238
modes_imoto.append(mode)
239
240
for trip in ids_routeres_car:
241
if routeresults.ids_iauto[trip] > 0:
242
id_iauto = routeresults.ids_iauto[trip]
243
vtype = self._trips.parent.virtualpop.get_iautos().ids_vtype[id_iauto]
244
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
245
elif routeresults.ids_trip[trip] > 0:
246
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[self._trips.ids_vtype[routeresults.ids_trip[trip]]]]
247
modes_car.append(mode)
248
249
for trip in ids_routeres_bike:
250
if routeresults.ids_ibike[trip] > 0:
251
id_ibike = routeresults.ids_ibike[trip]
252
vtype = self._trips.parent.virtualpop.get_ibikes().ids_vtype[id_ibike]
253
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
254
elif routeresults.ids_trip[trip] > 0:
255
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[self._trips.ids_vtype[routeresults.ids_trip[trip]]]]
256
modes_bike.append(mode)
257
258
for trip in ids_routeres_moto:
259
if routeresults.ids_imoto[trip] > 0:
260
id_imoto = routeresults.ids_imoto[trip]
261
vtype = self._trips.parent.virtualpop.get_imotos().ids_vtype[id_imoto]
262
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
263
elif routeresults.ids_trip[trip] > 0:
264
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[self._trips.ids_vtype[routeresults.ids_trip[trip]]]]
265
modes_moto.append(mode)
266
267
for trip in ids_routeres_ptlines:
268
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[self._trips.parent.ptlines.ids_vtype[routeresults.ids_ptline[trip]]]]
269
modes_ptline.append(mode)
270
271
for trip in ids_routeres_vp:
272
if routeresults.ids_iauto[trip] > 0:
273
id_iauto = routeresults.ids_iauto[trip]
274
vtype = self._trips.parent.virtualpop.get_iautos().ids_vtype[id_iauto]
275
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
276
elif routeresults.ids_ibike[trip] > 0:
277
id_ibike = routeresults.ids_ibike[trip]
278
vtype = self._trips.parent.virtualpop.get_ibikes().ids_vtype[id_ibike]
279
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
280
elif routeresults.ids_imoto[trip] > 0:
281
id_imoto = routeresults.ids_imoto[trip]
282
vtype = self._trips.parent.virtualpop.get_imotos().ids_vtype[id_imoto]
283
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
284
285
modes_vp.append(mode)
286
287
for trip in ids_routeres:
288
if routeresults.ids_iauto[trip] > 0 or routeresults.ids_ibike[trip] > 0 or routeresults.ids_imoto[trip] > 0:
289
if routeresults.ids_iauto[trip] > 0:
290
id_iauto = routeresults.ids_iauto[trip]
291
vtype = self._trips.parent.virtualpop.get_iautos().ids_vtype[id_iauto]
292
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
293
elif routeresults.ids_ibike[trip] > 0:
294
id_ibike = routeresults.ids_ibike[trip]
295
vtype = self._trips.parent.virtualpop.get_ibikes().ids_vtype[id_ibike]
296
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
297
elif routeresults.ids_imoto[trip] > 0:
298
id_imoto = routeresults.ids_imoto[trip]
299
vtype = self._trips.parent.virtualpop.get_imotos().ids_vtype[id_imoto]
300
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[vtype]]
301
elif routeresults.ids_trip[trip] > 0:
302
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[self._trips.ids_vtype[routeresults.ids_trip[trip]]]]
303
elif routeresults.ids_ptline[trip] > 0:
304
mode = self._edges.parent.modes.names[self._trips.parent.vtypes.ids_mode[self._trips.parent.ptlines.ids_vtype[routeresults.ids_ptline[trip]]]]
305
else:
306
print 'WARNING: there is a not considered route typology'
307
modes_tot.append(mode)
308
309
print 'n route', len(modes_tot)
310
if len(modes_tot) != len(ids_edges):
311
print 'WARNING: modes and ids_edges have a different length - total flow'
312
print 'n car routes', len(modes_car)
313
if len(modes_car) != len(ids_edges_car):
314
print 'WARNING: modes and ids_edges have a different length - car'
315
print 'n bike routes', len(modes_bike)
316
if len(modes_bike) != len(ids_edges_bike):
317
print 'WARNING: modes and ids_edges have a different length - bike'
318
print 'n moto routes', len(modes_moto)
319
if len(modes_moto) != len(ids_edges_moto):
320
print 'WARNING: modes and ids_edges have a different length - moto'
321
print 'n od routes', len(modes_od)
322
if len(modes_od) != len(ids_edges_od):
323
print 'WARNING: modes and ids_edges have a different length - od'
324
print 'n od car routes', modes_od.count('passenger')
325
print 'n od taxi routes', modes_od.count('taxi')
326
print 'n od bike routes', modes_od.count('bicycle')
327
print 'n od moto routes', modes_od.count('motorcycle')
328
print 'n vp routes', len(modes_vp)
329
if len(modes_vp) != len(ids_edges_vp):
330
print 'WARNING: modes and ids_edges have a different length - vp'
331
print 'n iauto routes', len(modes_iauto)
332
if len(modes_iauto) != len(ids_edges_iauto):
333
print 'WARNING: modes and ids_edges have a different length - iauto'
334
print 'n ibike routes', len(modes_ibike)
335
if len(modes_ibike) != len(ids_edges_ibike):
336
print 'WARNING: modes and ids_edges have a different length - ibike'
337
print 'n imoto routes', len(modes_imoto)
338
if len(modes_imoto) != len(ids_edges_imoto):
339
print 'WARNING: modes and ids_edges have a different length - imoto'
340
print 'n pt routes', len(modes_ptline)
341
if len(modes_ptline) != len(ids_edges_ptline):
342
print 'WARNING: modes and ids_edges have a different length - bus'
343
344
ids_connections_tot, flows_tot = self.evaluate_connection_flows('tot', modes_tot, ids_edges)
345
self.add_rows(ids_connection=ids_connections_tot, total_flows=flows_tot)
346
347
ids_connections_car, flows_car = self.evaluate_connection_flows('car', modes_car, ids_edges_car)
348
ids_connections_bike, flows_bike = self.evaluate_connection_flows('bike', modes_bike, ids_edges_bike)
349
ids_connections_moto, flows_moto = self.evaluate_connection_flows('moto', modes_moto, ids_edges_moto)
350
ids_connections_od, flows_od = self.evaluate_connection_flows('od', modes_od, ids_edges_od)
351
ids_connections_vp, flows_vp = self.evaluate_connection_flows('vp', modes_vp, ids_edges_vp)
352
ids_connections_iauto, flows_iauto = self.evaluate_connection_flows('iauto', modes_iauto, ids_edges_iauto)
353
ids_connections_ibike, flows_ibike = self.evaluate_connection_flows('ibike', modes_ibike, ids_edges_ibike)
354
ids_connections_imoto, flows_imoto = self.evaluate_connection_flows('imoto', modes_imoto, ids_edges_imoto)
355
ids_connections_ptline, flows_ptline = self.evaluate_connection_flows('pt', modes_ptline, ids_edges_ptline)
356
357
for connection, flow in zip(ids_connections_car, flows_car):
358
self.total_car_flows[self.ids_connection.get_id_from_index(connection)] = flow
359
360
for connection, flow in zip(ids_connections_bike, flows_bike):
361
self.total_bike_flows[self.ids_connection.get_id_from_index(connection)] = flow
362
363
for connection, flow in zip(ids_connections_moto, flows_moto):
364
self.total_moto_flows[self.ids_connection.get_id_from_index(connection)] = flow
365
366
for connection, flow in zip(ids_connections_od, flows_od):
367
self.total_od_flows[self.ids_connection.get_id_from_index(connection)] = flow
368
369
for connection, flow in zip(ids_connections_vp, flows_vp):
370
self.total_vp_flows[self.ids_connection.get_id_from_index(connection)] = flow
371
372
for connection, flow in zip(ids_connections_iauto, flows_iauto):
373
self.total_iauto_flows[self.ids_connection.get_id_from_index(connection)] = flow
374
375
for connection, flow in zip(ids_connections_ibike, flows_ibike):
376
self.total_ibike_flows[self.ids_connection.get_id_from_index(connection)] = flow
377
378
for connection, flow in zip(ids_connections_imoto, flows_imoto):
379
self.total_imoto_flows[self.ids_connection.get_id_from_index(connection)] = flow
380
381
for connection, flow in zip(ids_connections_ptline, flows_ptline):
382
self.total_ptline_flows[self.ids_connection.get_id_from_index(connection)] = flow
383
384
def evaluate_connection_flows(self, ident, modes, routes):
385
'''
386
Evaluate connection flows from a list of routes, each composed by a list of edges.
387
Sometimes many maneuvers connect the same couple of edges: you can
388
choose to either keep the rightmost lane or split homogeneously the flow in
389
the available maneuvers, between the connections allowed for the specific MODE.
390
Return both the traveled connections and the related flows
391
'''
392
print 'analyzing', ident, 'routes'
393
edges = self._edges
394
lanes = edges.parent.lanes
395
connections = edges.parent.connections
396
ids_connection = connections.get_ids()
397
connection_flows = np.zeros(len(ids_connection)+1, dtype=np.float32)
398
ids_traveled_connections = []
399
n_wrong_connections = 0
400
n_good_connections = 0
401
n_wrong_connections_moto = 0
402
n_wrong_connections_auto = 0
403
n_wrong_connections_bike = 0
404
n_wrong_connections_bus = 0
405
for route, mode in zip(routes, modes):
406
for i in range(len(route)-1):
407
edge_from = route[i]
408
edge_to = route[i+1]
409
ids_lane_from_all = edges.ids_lanes[edge_from]
410
ids_lane_to_all = edges.ids_lanes[edge_to]
411
ids_lane_from = []
412
ids_lane_to = []
413
# print 'ids_lane_from_all', ids_lane_from_all
414
# print 'ids_lane_to_all', ids_lane_to_all
415
for id_lane in ids_lane_from_all:
416
if len(edges.parent.lanes.ids_modes_allow[id_lane]) > 0:
417
if mode in self._edges.parent.modes.names[edges.parent.lanes.ids_modes_allow[id_lane]]:
418
ids_lane_from.append(id_lane)
419
elif len(edges.parent.lanes.ids_modes_disallow[id_lane]) > 0:
420
if mode not in self._edges.parent.modes.names[edges.parent.lanes.ids_modes_disallow[id_lane]]:
421
ids_lane_from.append(id_lane)
422
elif not len(edges.parent.lanes.ids_modes_allow[id_lane]) > 0 and not len(edges.parent.lanes.ids_modes_disallow[id_lane]) > 0:
423
ids_lane_from.append(id_lane)
424
# print 'allow from lane', id_lane, self._edges.parent.modes.names[edges.parent.lanes.ids_modes_allow[id_lane]]
425
# print 'disallow from lane', id_lane, self._edges.parent.modes.names[edges.parent.lanes.ids_modes_disallow[id_lane]]
426
for id_lane in ids_lane_to_all:
427
if len(edges.parent.lanes.ids_modes_allow[id_lane]) > 0:
428
if mode in self._edges.parent.modes.names[edges.parent.lanes.ids_modes_allow[id_lane]]:
429
ids_lane_to.append(id_lane)
430
elif len(edges.parent.lanes.ids_modes_disallow[id_lane]) > 0:
431
if mode not in self._edges.parent.modes.names[edges.parent.lanes.ids_modes_disallow[id_lane]]:
432
ids_lane_to.append(id_lane)
433
elif not len(edges.parent.lanes.ids_modes_allow[id_lane]) > 0 and not len(edges.parent.lanes.ids_modes_disallow[id_lane]) > 0:
434
ids_lane_to.append(id_lane)
435
# print 'ids_lane_from', ids_lane_from
436
# print 'ids_lane_to', ids_lane_to
437
438
possible_connections_from = []
439
possible_connections_to = []
440
connections_list = []
441
for id_lane_from in ids_lane_from:
442
poss_connections_from = ids_connection[(connections.ids_fromlane[ids_connection] == id_lane_from)]
443
for poss_connection_from in poss_connections_from:
444
possible_connections_from.append(poss_connection_from)
445
for id_lane_to in ids_lane_to:
446
poss_connections_to = ids_connection[(connections.ids_tolane[ids_connection] == id_lane_to)]
447
for poss_connection_to in poss_connections_to:
448
possible_connections_to.append(poss_connection_to)
449
for element in possible_connections_from:
450
if element in possible_connections_to:
451
connections_list.append(element)
452
453
if connections_list == []:
454
print 'Warning: no connections between a couple of successive edges for mode', mode
455
print 'ids_lane_from_all', ids_lane_from_all
456
print 'ids_lane_to_all', ids_lane_to_all
457
n_wrong_connections += 1
458
if mode == 'motorcycle':
459
n_wrong_connections_moto += 1
460
if mode == 'passenger':
461
n_wrong_connections_auto += 1
462
if mode == 'bicycle':
463
n_wrong_connections_bike += 1
464
if mode == 'bus':
465
n_wrong_connections_bus += 1
466
467
else:
468
469
if mode == 'motorcycle':
470
keep_right = self._is_keep_right_moto
471
elif mode == 'passenger':
472
keep_right = self._is_keep_right_car
473
elif mode == 'bicycle':
474
keep_right = self._is_keep_right_bike
475
elif mode == 'bus':
476
keep_right = self._is_keep_right_bus
477
elif mode == 'taxi':
478
keep_right = self._is_keep_right_taxi
479
else:
480
print 'WARNING - Not recognized mode'
481
keep_right = True
482
483
n_good_connections += 1
484
if keep_right == False:
485
for connection in connections_list:
486
if connection not in ids_traveled_connections:
487
ids_traveled_connections.append(connection)
488
connection_flows[connection] += 1./len(connections_list)
489
490
elif keep_right == True:
491
lane_index_connections = lanes.indexes[connections.ids_fromlane[connections_list]
492
] + lanes.indexes[connections.ids_tolane[connections_list]]
493
connection = connections_list[np.argmin(lane_index_connections)]
494
if connection not in ids_traveled_connections:
495
ids_traveled_connections.append(connection)
496
connection_flows[connection] += 1.
497
# print ids_traveled_connections, connection_flows[ids_traveled_connections]
498
print 'n_good_connections:', n_good_connections
499
print 'n_wrong_connections:', n_wrong_connections
500
# print 'n_wrong_connections_moto:', n_wrong_connections_moto
501
# print 'n_wrong_connections_auto:', n_wrong_connections_auto
502
# print 'n_wrong_connections_bike:', n_wrong_connections_bike
503
# print 'n_wrong_connections_bus:', n_wrong_connections_bus
504
##
505
return ids_traveled_connections, connection_flows[ids_traveled_connections]
506
507
508
class Routeresults(am.ArrayObjman):
509
def __init__(self, ident, parent, trips, edges, datapathkey='routesdatapath',
510
is_add_default=True,
511
name='Route results',
512
info='Table with simulation results for each route made.Consider only the finished trips',
513
**kwargs):
514
self._trips = trips
515
self._init_objman(ident=ident,
516
parent=parent, # main results object
517
info=info,
518
name=name,
519
**kwargs)
520
521
self.add(cm.AttrConf('datapathkey', datapathkey,
522
groupnames=['_private'],
523
name='data pathkey',
524
info="key of data path",
525
))
526
527
self.add_col(am.IdsArrayConf('ids_trip', trips,
528
groupnames=['state'],
529
is_index=True,
530
name='ID trip',
531
info='ID of trip.',
532
))
533
534
self.add_col(am.IdsArrayConf('ids_iauto', trips.parent.virtualpop.get_iautos(),
535
groupnames=['state'],
536
is_index=True,
537
name='ID iauto',
538
info='ID of iauto trip from the virtual population.',
539
))
540
541
self.add_col(am.IdsArrayConf('ids_imoto', trips.parent.virtualpop.get_imotos(),
542
groupnames=['state'],
543
is_index=True,
544
name='ID imoto',
545
info='ID of trip imoto from the virtual population.',
546
))
547
548
self.add_col(am.IdsArrayConf('ids_ibike', trips.parent.virtualpop.get_ibikes(),
549
groupnames=['state'],
550
is_index=True,
551
name='ID ibike',
552
info='ID of trip ibike from the virtual population.',
553
))
554
555
self.add_col(am.IdsArrayConf('ids_ptline', trips.parent.ptlines,
556
groupnames=['state'],
557
is_index=True,
558
name='ID ptline',
559
info='ID of the public transportation line.',
560
))
561
562
attrinfos = OrderedDict([
563
564
('times_depart', {'name': 'Time depart', 'xmltag': 'times_depart', 'unit': 's',
565
'default': 0.0, 'info': 'Depart time', 'groupnames': ['routedata']}),
566
567
('times_arrival', {'name': 'Time arrival', 'xmltag': 'times_arrival', 'unit': 's',
568
'default': 0.0, 'info': 'Arrival time', 'groupnames': ['routedata']}),
569
570
('type', {'name': 'Vehicle type', 'xmltag': 'type', 'unit': None,
571
'default': np.object, 'info': 'Vehicle type', 'groupnames': ['routedata']}),
572
573
('ids_edge_depart', {'name': 'ID Edge depart', 'xmltag': 'ids_edge_depart', 'unit': None,
574
'default': 0, 'info': 'Depart edege', 'groupnames': ['routedata']}),
575
576
('ids_edge_arrival', {'name': 'ID Edge arrival', 'xmltag': 'ids_edge_arrival', 'unit': None,
577
'default': 0, 'info': 'Arrival edge', 'groupnames': ['routedata']}),
578
579
('inds_lane_depart', {'name': 'ID lane depart', 'xmltag': 'inds_lane_depart', 'unit': None,
580
'default': 0, 'info': 'Depart lane ', 'groupnames': ['routedata']}),
581
582
('positions_depart', {'name': 'Position depart', 'xmltag': 'positions_depart', 'unit': 'm',
583
'default': 0.0, 'info': 'Position depart', 'groupnames': ['routedata']}),
584
585
('speeds_depart', {'name': 'Speed depart', 'xmltag': 'speeds_depart', 'unit': 'm/s',
586
'default': 0.0, 'info': 'Depart speed', 'groupnames': ['routedata']}),
587
588
('inds_lane_arrival', {'name': 'ID Lane arrival', 'xmltag': 'inds_lane_arrival', 'unit': None,
589
'default': 0, 'info': 'Arrival lane', 'groupnames': ['routedata']}),
590
591
('positions_arrival', {'name': 'Position arrival', 'xmltag': 'positions_arrival', 'unit': 'm',
592
'default': 0.0, 'info': 'Arrival position', 'groupnames': ['routedata']}),
593
594
('speeds_arrival', {'name': 'Speed arrival', 'xmltag': 'speeds_arrival', 'unit': 'm/s',
595
'default': 0.0, 'info': 'Arrival speed', 'groupnames': ['routedata']}),
596
])
597
598
for attrname, kwargs in attrinfos.iteritems():
599
self.add_resultattr(attrname, **kwargs)
600
601
# this is special for route info
602
self.add_col(am.IdlistsArrayConf('ids_edges', edges,
603
name='Edge IDs',
604
groupnames=['routedata'],
605
info='List of edge IDs constituting the actually taken route.',
606
xmltag='edges',
607
))
608
609
def add_resultattr(self, attrname, **kwargs):
610
611
# default cannot be kwarg
612
default = kwargs['default']
613
del kwargs['default']
614
if kwargs.has_key('groupnames'):
615
kwargs['groupnames'].append('results')
616
else:
617
kwargs['groupnames'] = ['results']
618
619
self.add_col(am.ArrayConf(attrname, default, **kwargs))
620
621
# def import_routesdata(self, filepath):
622
# # TODO
623
# pass
624
625
# def import_tripdata(self, filepath):
626
# #print 'import_tripdata',filepath,self.get_group('tripdata')
627
# self.import_sumoxml(filepath,self.get_group('tripdata'))
628
629
def import_xml(self, sumo, datapaths):
630
datapathkey = self.datapathkey.get_value()
631
if datapaths.has_key(datapathkey):
632
self.import_sumoxml(datapaths[datapathkey], sumo, self.get_group('routedata'))
633
634
def import_sumoxml(self, filepath, sumo, attrconfigs):
635
element = 'route'
636
# print 'Tripresults.import_sumoxml',self.get_trips().ident, element,filepath
637
#id_type = 'edge',
638
#reader = 'interval',
639
640
results = read_routeresult(filepath, sumo, self._trips, element, attrconfigs)
641
ids_raw = results['ids_sumo']
642
643
# print ' ids_raw',ids_raw
644
# print ' results.keys()',results.keys()
645
# print ' results',results
646
647
# this procedure is necessary to create new result ids only
648
# for trips that are not yet in the database
649
n = len(ids_raw[(ids_raw != '')])
650
# print ' number of rows',n
651
ind_range = np.arange(n, dtype=np.int32)
652
ids = np.zeros(n, dtype=np.int32)
653
for i in ind_range:
654
655
id_trip = ids_raw[i]
656
# if self.ids_trip.has_index(id_trip):
657
## ids[i] = self.ids_trip.get_id_from_index(id_trip)
658
# else:
659
if 'iauto' in id_trip:
660
ids[i] = self.add_row(ids_iauto=int(id_trip.split('.')[1]))
661
# print int(id_trip.split('.')[1]), id_trip.split('.')[1], id_trip
662
elif 'imoto' in id_trip:
663
ids[i] = self.add_row(ids_imoto=int(id_trip.split('.')[1]))
664
elif 'ibike' in id_trip:
665
ids[i] = self.add_row(ids_ibike=int(id_trip.split('.')[1]))
666
elif 'ptline' in id_trip:
667
668
ids[i] = self.add_row(ids_ptline=int(id_trip.split('.')[1]))
669
else:
670
# print 'WARNING:', id_trip, 'not recognized trip'
671
ids[i] = self.add_row(ids_trip=int(id_trip))
672
673
for attrconfig in attrconfigs:
674
attrname = attrconfig.attrname
675
if attrname != 'ids_sumo':
676
default = attrconfig.get_default()
677
if type(default) in (types.IntType, types.LongType):
678
conversion = 'i' # int
679
values_attr = np.zeros(n, int)
680
elif type(default) in (types.FloatType, types.ComplexType):
681
conversion = 'f' # float
682
values_attr = np.zeros(n, dtype=np.float32)
683
if type(default) in (types.BooleanType,):
684
conversion = 'b' # str
685
values_attr = np.zeros(n, dtype=np.bool)
686
else:
687
conversion = 's' # str
688
values_attr = np.zeros(n, dtype=np.object)
689
690
is_average = False
691
if hasattr(attrconfig, 'is_average'):
692
is_average = attrconfig.is_average
693
# this is a tricky way to read the data stored in
694
# dictionarie into array tructures as used in results
695
# problem is that not all dictionaries have all ids
696
for i in ind_range:
697
# print ' check',ids_raw[i],results[attrname].get(ids_raw[i],'No data')
698
699
val = results[attrname][i]
700
# print val, results[attrname][i]
701
if conversion == 'i':
702
val = int(val)
703
else:
704
values_attr[i] = val
705
# print ' ',i,ids[i],attrname,conversion,val,type(val),is_average
706
values_attr[i] = val
707
if attrname == 'ids_edges':
708
for i in ind_range:
709
values_attr[i] = results[attrname][i]
710
# print ' attrname',attrname
711
# print ' ids',type(ids),ids
712
# print ' values_attr',type(values_attr),values_attr
713
attrconfig.set(ids, values_attr)
714
715
716
class Tripresults(am.ArrayObjman):
717
def __init__(self, ident, parent, trips, edges, # datapathkey = 'tripdatapath',
718
is_add_default=True,
719
name='Trip results',
720
info='Table with simulation results for each trip made.',
721
**kwargs):
722
723
self._init_objman(ident=ident,
724
parent=parent, # main results object
725
info=info,
726
name=name,
727
**kwargs)
728
729
# self.add(cm.AttrConf( 'datapathkey',datapathkey,
730
# groupnames = ['_private'],
731
# name = 'data pathkey',
732
# info = "key of data path",
733
# ))
734
735
self.add_col(am.IdsArrayConf('ids_trip', trips,
736
groupnames=['state'],
737
is_index=True,
738
name='ID trip',
739
info='ID of trip.',
740
))
741
attrinfos = OrderedDict([
742
('duration', {'name': 'Duration', 'xmltag': 'duration', 'unit': 's',
743
'default': 0, 'info': 'Trip duration', 'groupnames': ['tripdata']}),
744
('depart', {'name': 'Dep. time', 'xmltag': 'depart', 'unit': 's', 'default': 0,
745
'info': 'Departure time', 'groupnames': ['tripdata'], 'is_average': True}),
746
('arrival', {'name': 'Arr. time', 'xmltag': 'arrival', 'unit': 's', 'default': 0,
747
'info': 'Arrival time', 'groupnames': ['tripdata'], 'is_average': True}),
748
('routeLength', {'name': 'Length', 'xmltag': 'routeLength', 'unit': 'm',
749
'default': 0.0, 'info': 'Route length', 'groupnames': ['tripdata']}),
750
('departdelays', {'name': 'Dep. delay', 'xmltag': 'departDelay', 'unit': 's', 'default': 0,
751
'info': 'The time the vehicle had to wait before it could start his journey', 'groupnames': ['tripdata'], 'is_average': True}),
752
('waittimes', {'name': 'Wait time', 'xmltag': 'waitingTime', 'unit': 's', 'default': 0,
753
'info': 'The time in which the vehicle speed was below 0.1m/s (scheduled stops do not count) ', 'groupnames': ['tripdata'], 'is_average': True}),
754
('stoptimes', {'name': 'Stop time', 'xmltag': 'stopTime', 'unit': 's', 'default': 0,
755
'info': 'The time in which the vehicle was taking a planned stop', 'groupnames': ['tripdata'], 'is_average': True}),
756
('timelosses', {'name': 'Timeloss', 'xmltag': 'timeLoss', 'unit': 's', 'default': 0,
757
'info': 'The time lost due to driving below the ideal speed. (ideal speed includes the individual speedFactor; slowdowns due to intersections etc. will incur timeLoss, scheduled stops do not count)', 'groupnames': ['tripdata'], 'is_average': True}),
758
('departPos', {'name': 'depart pos', 'xmltag': 'departPos', 'unit': 'm',
759
'default': 0.0, 'info': 'depart position', 'groupnames': ['tripdata'], 'is_average': True}),
760
('arrivalPos', {'name': 'arrival pos', 'xmltag': 'arrivalPos', 'unit': 'm',
761
'default': 0.0, 'info': 'arrival position', 'groupnames': ['tripdata'], 'is_average': True}),
762
('speedfactors', {'name': 'Speedfactor', 'xmltag': 'speedFactor', 'default': 0.0,
763
'info': 'The individual speed factor of the vehicle (possibly drawn from a speed distribution at the start of the simulation)', 'groupnames': ['tripdata'], }),
764
('are_vaporized', {'name': 'vaporized', 'xmltag': 'vaporized', 'default': False,
765
'info': 'Whether the vehicle was removed from the simulation before reaching its destination', 'groupnames': ['tripdata'], }),
766
('waitSteps', {'name': 'wait steps', 'xmltag': 'waitingCount', 'unit': None, 'default': 0,
767
'info': 'Count of time steps, the vehicle has been waiting during its trip', 'groupnames': ['tripdata']}),
768
('rerouteNo', {'name': 'reroute No', 'xmltag': 'rerouteNo', 'unit': None,
769
'default': 0, 'info': 'Number of re-routes', 'groupnames': ['tripdata']}),
770
('waitSteps', {'name': 'wait steps', 'xmltag': 'waitSteps', 'unit': None, 'default': 0,
771
'info': 'Time steps, the vehicle has been waiting during its trip', 'groupnames': ['tripdata']}),
772
('consumptions', {'name': 'Consumption', 'xmltag': 'Consum', 'unit': 'Ws',
773
'default': 0.0, 'info': 'Electrical energy consumption', 'groupnames': ['electricenergydata']}),
774
#('speeds_av', {'name':'Average speeds', 'xmltag':'speed', 'unit':'m/s', 'default':0, 'info':'Average speed','groupnames':['tripdata'],'is_average' : True}),
775
])
776
777
for attrname, kwargs in attrinfos.iteritems():
778
self.add_resultattr(attrname, **kwargs)
779
780
# this is special for route info
781
self.add_col(am.IdlistsArrayConf('ids_edges', edges,
782
name='Edge IDs',
783
groupnames=['routeinfo'],
784
info='List of edge IDs constituting the actually taken route.',
785
xmltag='edges',
786
))
787
788
def get_trips(self):
789
return self.ids_trip.get_linktab()
790
791
def add_resultattr(self, attrname, **kwargs):
792
793
# default cannot be kwarg
794
default = kwargs['default']
795
del kwargs['default']
796
if kwargs.has_key('groupnames'):
797
kwargs['groupnames'].append('results')
798
else:
799
kwargs['groupnames'] = ['results']
800
801
self.add_col(am.ArrayConf(attrname, default, **kwargs))
802
803
# def import_routesdata(self, filepath):
804
# # TODO
805
# pass
806
807
# def import_tripdata(self, filepath):
808
# #print 'import_tripdata',filepath,self.get_group('tripdata')
809
# self.import_sumoxml(filepath,self.get_group('tripdata'))
810
811
def import_xml(self, sumo, datapaths):
812
print 'Tripresults.import_xml datapaths', datapaths
813
datapathkey = 'tripdatapath'
814
if datapaths.has_key(datapathkey):
815
self.import_tripdata_sumoxml(datapaths[datapathkey], sumo)
816
817
#datapathkey = 'electricenergypath'
818
# if datapaths.has_key(datapathkey):
819
# self.import_electricenergy_sumoxml(datapaths[datapathkey],sumo)
820
821
def import_electricenergy_sumoxml_broke(self, filepath, sumo):
822
element = 'vehicle'
823
print 'Tripresults.import_electricenergy_sumoxml', self.get_trips().ident, element, filepath
824
#id_type = 'edge',
825
#reader = 'interval',
826
attrconfigs = self.get_group('electricenergydata')
827
# print 'import_sumoxml',element
828
#id_type = 'edge',
829
#reader = 'interval',
830
ids_sumo, results, interval = read_interval2(
831
filepath, sumo, element, attrconfigs)
832
# print ' ids_sumo',ids_sumo
833
# print ' results.keys()',results.keys()
834
# print ' results',results
835
# create ids for all colums
836
# if fileinfo['id_type']=='edge':
837
838
# this procedure is necessary to create new result ids only
839
# for edges that are not yet in the database
840
ids_sumotrip = self.ids_trip.get_linktab().ids_sumo
841
n = len(ids_sumo)
842
# print ' n',n
843
ind_range = np.arange(n, dtype=np.int32)
844
ids = np.zeros(n, dtype=np.int32)
845
for i in ind_range:
846
id_trip = ids_sumotrip.get_id_from_index(ids_sumo[i])
847
if self.ids_trip.has_index(id_trip):
848
ids[i] = self.ids_trip.get_id_from_index(id_edge)
849
else:
850
ids[i] = self.add_row(ids_trip=id_edge)
851
852
# ids = self.add_row()# here the ids_sumo can be strings too
853
# elif fileinfo['id_type']=='trip':
854
# ids = self.tripresults.add_rows_keyrecycle(keys = ids_sumo)#
855
# print ' ids=',ids
856
857
for attrconfig in attrconfigs:
858
859
attrname = attrconfig.attrname
860
861
default = attrconfig.get_default()
862
if type(default) in (types.IntType, types.LongType):
863
conversion = 'i' # int
864
values_attr = np.zeros(n, int)
865
elif type(default) in (types.FloatType, types.ComplexType):
866
conversion = 'f' # float
867
values_attr = np.zeros(n, float)
868
else:
869
conversion = 's' # str
870
values_attr = np.zeros(n, obj)
871
872
is_average = False
873
if hasattr(attrconfig, 'is_average'):
874
is_average = attrconfig.is_average
875
# print ' copy',attrname,'is_average',is_average
876
# this is a tricky way to read the data stored in
877
# dictionarie into array tructures as used in results
878
# problem is that not all dictionaries have all ids
879
for i in ind_range:
880
if is_average:
881
valcum, num = results[attrname].get(ids_sumo[i], (default, 1))
882
val = valcum/float(num) # average over measurements!
883
else:
884
val = results[attrname].get(ids_sumo[i], default)
885
886
if conversion == 'i':
887
val = int(val)
888
# else:
889
# values_attr[i]=val
890
# print ' attrname',attrname,conversion,val,is_average,type(val)
891
values_attr[i] = val
892
893
# print ' attrname',attrname
894
# print ' ids',type(ids),ids
895
# print ' values_attr',type(values_attr),values_attr
896
attrconfig.set(ids, values_attr)
897
898
def import_tripdata_sumoxml(self, filepath, sumo):
899
element = 'tripinfo'
900
print 'Tripresults.import_tripdata_sumoxml', self.get_trips().ident, 'element', element, filepath
901
#id_type = 'edge',
902
#reader = 'interval',
903
attrconfigs = self.get_group('tripdata')
904
ids_raw, results = read_tripresult(filepath, sumo, self.get_trips(), element, attrconfigs)
905
906
# print ' ids_raw',ids_raw
907
# print ' results.keys()',results.keys()
908
# print ' results',results
909
910
# this procedure is necessary to create new result ids only
911
# for trips that are not yet in the database
912
n = len(ids_raw)
913
# print ' number of rows',n
914
ind_range = np.arange(n, dtype=np.int32)
915
ids = np.zeros(n, dtype=np.int32)
916
for i in ind_range:
917
918
id_trip = int(ids_raw[i])
919
if self.ids_trip.has_index(id_trip):
920
ids[i] = self.ids_trip.get_id_from_index(id_trip)
921
else:
922
ids[i] = self.add_row(ids_trip=id_trip)
923
924
for attrconfig in attrconfigs:
925
attrname = attrconfig.attrname
926
default = attrconfig.get_default()
927
if type(default) in (types.IntType, types.LongType):
928
conversion = 'i' # int
929
values_attr = np.zeros(n, int)
930
elif type(default) in (types.FloatType, types.ComplexType):
931
conversion = 'f' # float
932
values_attr = np.zeros(n, dtype=np.float32)
933
if type(default) in (types.BooleanType,):
934
conversion = 'b' # str
935
values_attr = np.zeros(n, dtype=np.bool)
936
else:
937
conversion = 's' # str
938
values_attr = np.zeros(n, dtype=np.object)
939
940
is_average = False
941
if hasattr(attrconfig, 'is_average'):
942
is_average = attrconfig.is_average
943
# this is a tricky way to read the data stored in
944
# dictionarie into array tructures as used in results
945
# problem is that not all dictionaries have all ids
946
for i in ind_range:
947
# print ' check',ids_raw[i],results[attrname].get(ids_raw[i],'No data')
948
if is_average:
949
valcum, num = results[attrname].get(ids_raw[i], (default, 1))
950
val = valcum/float(num) # average!
951
else:
952
val = results[attrname].get(ids_raw[i], default)
953
954
if conversion == 'i':
955
val = int(val)
956
else:
957
values_attr[i] = val
958
# print ' ',i,ids[i],attrname,conversion,val,type(val),is_average
959
values_attr[i] = val
960
961
# print ' attrname',attrname
962
# print ' ids',type(ids),ids
963
# print ' values_attr',type(values_attr),values_attr
964
attrconfig.set(ids, values_attr)
965
966
967
class Edgeresults(am.ArrayObjman):
968
def __init__(self, parent, edges, is_add_default=True, **kwargs):
969
970
self._init_objman(ident='edgeresults',
971
parent=parent, # main results object
972
name='Edge results',
973
info='Table with simulation results for each network edge.',
974
#xmltag = ('vtypes','vtype','ids_sumo'),
975
**kwargs)
976
977
self.add_col(am.IdsArrayConf('ids_edge', edges,
978
groupnames=['state'],
979
is_index=True,
980
name='ID edge',
981
info='ID of edge.',
982
))
983
self._init_attributes()
984
985
def _init_attributes(self):
986
# print 'Edgeresults._init_attributes'
987
# print ' ',self,id(self),hasattr(self,'import_marouterxml')
988
989
attrinfos = OrderedDict([
990
991
992
('detectorflows', {'name': 'Detector flows', 'unit': None, 'default': 0.,
993
'info': 'Flows measured by detectors', 'xmltag': 'detectorflows', 'groupnames': ['edgedata']}),
994
('entered', {'name': 'Entered', 'unit': None, 'default': 0,
995
'info': 'Entered number of vehicles', 'xmltag': 'entered', 'groupnames': ['edgedata']}),
996
('entered_est', {'name': 'Entered est', 'default': 0,
997
'info': 'Estimated number of entered vehicles.', 'groupnames': ['analysis'], }),
998
('left', {'name': 'Left', 'unit': None, 'default': 0,
999
'info': 'Left number of vehicles', 'xmltag': 'left', 'groupnames': ['edgedata']}),
1000
('arrived', {'name': 'Arrived', 'unit': None, 'default': 0,
1001
'info': 'Arrived number of vehicles', 'xmltag': 'arrived', 'groupnames': ['edgedata']}),
1002
('departed', {'name': 'Departed', 'unit': None, 'default': 0,
1003
'info': 'Departed number of vehicles', 'xmltag': 'departed', 'groupnames': ['edgedata']}),
1004
('traveltime', {'name': 'Av. times', 'unit': 's', 'default': 0.0, 'info': 'Av. Travel times',
1005
'xmltag': 'traveltime', 'groupnames': ['edgedata'], 'is_average': True}),
1006
('density', {'name': 'Av. Densities', 'unit': 'veh/km', 'default': 0.0,
1007
'info': 'Av. Density in vehicles of vehicles on this Edge/Lane', 'xmltag': 'density', 'groupnames': ['edgedata'], 'is_average': True}),
1008
('waitingTime', {'name': 'Av. waits', 'unit': 's', 'default': 0.0, 'info': 'Av. Waiting times of vehicles on this Edge/Lane',
1009
'xmltag': 'waitingTime', 'groupnames': ['edgedata'], 'is_average': True}),
1010
('speed', {'name': 'Av. speeds', 'unit': 'm/s', 'default': 0.0,
1011
'info': 'Av. velocity of vehicles on this Edge/Lane', 'xmltag': 'speed', 'groupnames': ['edgedata'], 'is_average': True}),
1012
('fuel_abs', {'name': 'Abs. Fuel', 'unit': 'ml', 'default': 0.0,
1013
'info': 'Absolute fuel consumption of vehicles on this Edge/Lane', 'xmltag': 'fuel_abs', 'groupnames': ['edgeemissions']}),
1014
('CO_abs', {'name': 'Abs. CO', 'unit': 'mg', 'default': 0.0,
1015
'info': 'Absolute CO emission of vehicles on this Edge/Lane', 'xmltag': 'CO_abs', 'groupnames': ['edgeemissions']}),
1016
('CO2_abs', {'name': 'Abs. CO2', 'unit': 'mg', 'default': 0.0,
1017
'info': 'Absolute CO2 emission of vehicles on this Edge/Lane', 'xmltag': 'CO2_abs', 'groupnames': ['edgeemissions']}),
1018
('NOx_abs', {'name': 'Abs. NOx', 'unit': 'mg', 'default': 0.0,
1019
'info': 'Absolute NOx emission of vehicles on this Edge/Lane', 'xmltag': 'NOx_abs', 'groupnames': ['edgeemissions']}),
1020
('PMx_abs', {'name': 'Abs. PMx', 'unit': 'mg', 'default': 0.0,
1021
'info': 'Absolute PMx emission (Particle matter, all sizes) of vehicles on this Edge/Lane', 'xmltag': 'PMx_abs', 'groupnames': ['edgeemissions']}),
1022
('fuel_normed', {'name': 'Specific fuel', 'unit': 'l/km/h', 'default': 0.0,
1023
'info': 'Specific fuel consumption of vehicles on this Edge/Lane', 'xmltag': 'fuel_normed', 'groupnames': ['edgeemissions'], 'is_average': True}),
1024
('CO_normed', {'name': 'Specific CO', 'unit': 'g/km/h', 'default': 0.0,
1025
'info': 'Normalized CO emission of vehicles on this Edge/Lane', 'xmltag': 'CO_normed', 'groupnames': ['edgeemissions'], 'is_average': True}),
1026
('CO2_normed', {'name': 'Specific CO2', 'unit': 'g/km/h', 'default': 0.0,
1027
'info': 'Normalized CO2 emission of vehicles on this Edge/Lane', 'xmltag': 'CO2_normed', 'groupnames': ['edgeemissions'], 'is_average': True}),
1028
('NOx_normed', {'name': 'Specific NOx', 'unit': 'g/km/h', 'default': 0.0,
1029
'info': 'Normalized NOx emission of vehicles on this Edge/Lane', 'xmltag': 'NOx_normed', 'groupnames': ['edgeemissions'], 'is_average': True}),
1030
('PMx_normed', {'name': 'Specific PMx', 'unit': 'g/km/h', 'default': 0.0,
1031
'info': 'Normalized PMx emission of vehicles on this Edge/Lane', 'xmltag': 'PMx_normed', 'groupnames': ['edgeemissions'], 'is_average': True}),
1032
('fuel_perVeh', {'name': 'Fuel per veh.', 'unit': 'ml/veh', 'default': 0.0,
1033
'info': 'Absolute fuel consumption of vehicles on this Edge/Lane', 'xmltag': 'fuel_perVeh', 'groupnames': ['edgeemissions'], 'is_average': True}),
1034
('CO_perVeh', {'name': 'CO per veh.', 'unit': 'mg/veh', 'default': 0.0,
1035
'info': 'CO emission per vehicle on this Edge/Lane', 'xmltag': 'CO_perVeh', 'groupnames': ['edgeemissions'], 'is_average': True}),
1036
('CO2_perVeh', {'name': 'CO2 per veh.', 'unit': 'mg/veh', 'default': 0.0,
1037
'info': 'CO2 emission per vehicle on this Edge/Lane', 'xmltag': 'CO2_perVeh', 'groupnames': ['edgeemissions'], 'is_average': True}),
1038
('NOx_perVeh', {'name': 'NOx per veh.', 'unit': 'mg/veh', 'default': 0.0,
1039
'info': 'NOx emission per vehicle on this Edge/Lane', 'xmltag': 'NOx_perVeh', 'groupnames': ['edgeemissions'], 'is_average': True}),
1040
('PMx_perVeh', {'name': 'PMx per veh.', 'unit': 'mg/veh', 'default': 0.0,
1041
'info': 'PMx emission per vehicle on this Edge/Lane', 'xmltag': 'PMx_perVeh', 'groupnames': ['edgeemissions'], 'is_average': True}),
1042
('noise', {'name': 'Noise', 'unit': 'dB', 'default': 0.0,
1043
'info': 'Noise of vehicles on this Edge/Lane', 'xmltag': 'noise', 'groupnames': ['edgenoise'], 'is_average': True}),
1044
('total_flows', {'name': 'Total flows', 'unit': None, 'default': 0,
1045
'info': 'Total flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_flows']}),
1046
('total_od_flows', {'name': 'Total OD flows', 'unit': None, 'default': 0,
1047
'info': 'Total OD flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_od_flows']}),
1048
('total_vp_flows', {'name': 'Total VP flows', 'unit': None, 'default': 0,
1049
'info': 'Total VP flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_vp_flows']}),
1050
('total_ptline_flows', {'name': 'Total pt flows', 'unit': None, 'default': 0,
1051
'info': 'Total pt flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_ptline_flows']}),
1052
('total_car_flows', {'name': 'Total car flows', 'unit': None, 'default': 0,
1053
'info': 'Total car flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_car_flows']}),
1054
('total_bike_flows', {'name': 'Total bike flows', 'unit': None, 'default': 0,
1055
'info': 'Total bike flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_bike_flows']}),
1056
('total_moto_flows', {'name': 'Total moto flows', 'unit': None, 'default': 0,
1057
'info': 'Total moto flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_moto_flows']}),
1058
('total_iauto_flows', {'name': 'Total iauto flows', 'unit': None, 'default': 0,
1059
'info': 'Total iauto flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_iauto_flows']}),
1060
('total_ibike_flows', {'name': 'Total ibike flows', 'unit': None, 'default': 0,
1061
'info': 'Total ibike flow in the edge', 'xmltag': 'entered', 'groupnames': ['total_ibike_flows']}),
1062
('total_imoto_flows', {'name': 'Total imoto flows', 'unit': None, 'default': 0,
1063
'info': 'Total imoto flow in the edge.', 'xmltag': 'entered', 'groupnames': ['total_imoto_flows']}),
1064
1065
#
1066
])
1067
1068
for attrname, kwargs in attrinfos.iteritems():
1069
self.add_resultattr(attrname, **kwargs)
1070
1071
def add_resultattr(self, attrname, **kwargs):
1072
1073
# default cannot be kwarg
1074
default = kwargs['default']
1075
del kwargs['default']
1076
if kwargs.has_key('groupnames'):
1077
kwargs['groupnames'].append('results')
1078
else:
1079
kwargs['groupnames'] = ['results']
1080
1081
self.add_col(am.ArrayConf(attrname, default, **kwargs))
1082
1083
def add_edgelength(self):
1084
edges = self.parent.get_scenario().net.edges
1085
self.add_col(am.ArrayConf('lengths', 0.0,
1086
groupnames=[],
1087
perm='r',
1088
unit='m',
1089
name='Edge length',
1090
info='Edge length.'))
1091
ids = self.get_ids()
1092
self.lengths[ids] = edges.lengths[self.ids_edge[ids]]
1093
1094
def add_entered_est(self, ids_edge, entered_vec):
1095
self.entered_est.reset()
1096
ids_results = np.zeros(len(ids_edge), dtype=np.int32)
1097
i = 0
1098
for id_edge, entered in zip(ids_edge, entered_vec):
1099
if self.ids_edge.has_index(id_edge):
1100
id_res = self.ids_edge.get_id_from_index(id_edge)
1101
self.entered_est[id_res] = entered
1102
else:
1103
id_res = self.add_row(ids_edge=id_edge, entered_est=entered)
1104
ids_results[i] = id_res
1105
i += 1
1106
1107
return ids_results
1108
1109
def filter_zoneedges(self, ids_zone, is_invert=False):
1110
"""
1111
Keep only results of edges that belong to zone id_zone
1112
"""
1113
print 'filter_zoneedges', ids_zone
1114
1115
zones = self.parent.parent.parent.landuse.zones
1116
ids_zoneedge = set()
1117
for id_zone in ids_zone:
1118
if not (zones.ids_edges_orig[id_zone] is None):
1119
ids_zoneedge.update(zones.ids_edges_orig[id_zone])
1120
1121
if len(ids_zoneedge) > 0:
1122
1123
ids_res = self.get_ids()
1124
inds = np.zeros(len(ids_res), dtype=np.bool)
1125
for i, id_res, id_edge in zip(xrange(len(ids_res)), ids_res, self.ids_edge[ids_res]):
1126
inds[i] = id_edge in ids_zoneedge
1127
if not is_invert:
1128
inds = np.logical_not(inds)
1129
1130
self.del_rows(ids_res[inds])
1131
1132
def import_edgedata(self, sumo, filepath):
1133
print 'import_edgedata', filepath
1134
# print ' group',self.get_group('edgedata')
1135
#attrnames_data = ['entered','left','arrived','departed']
1136
#attrnames_averaged = ['traveltime','density','waitingTime','speed',]
1137
self.import_sumoxml(filepath, sumo, self.get_group('edgedata'))
1138
1139
def import_edgeflows(self, sumo, filepath):
1140
1141
routeresults = self.parent.routeresults
1142
net = self.parent.parent.parent.net
1143
demand = self.parent.parent.parent.demand
1144
ids_routeres = routeresults.get_ids()
1145
# Consider warmup time
1146
ids_routeres = ids_routeres[(routeresults.times_depart[ids_routeres] > sumo.time_warmup)]
1147
# ids_routeres = ids_routeres[700:1000]
1148
# print ids_routeres
1149
ids_routeres_od = ids_routeres[(routeresults.ids_trip[ids_routeres] > 0)]
1150
ids_od_modes = demand.vtypes.ids_mode[demand.trips.ids_vtype[routeresults.ids_trip[ids_routeres_od]]]
1151
ids_routeres_od_auto = ids_routeres_od[(ids_od_modes == net.modes.names.get_id_from_index('passenger'))]
1152
ids_routeres_od_taxi = ids_routeres_od[(ids_od_modes == net.modes.names.get_id_from_index('taxi'))]
1153
ids_routeres_od_car = list(ids_routeres_od_auto)+list(ids_routeres_od_taxi)
1154
ids_routeres_od_bike = ids_routeres_od[(ids_od_modes == net.modes.names.get_id_from_index('bicycle'))]
1155
ids_routeres_od_moto = ids_routeres_od[(ids_od_modes == net.modes.names.get_id_from_index('motorcycle'))]
1156
1157
ids_routeres_iauto = ids_routeres[(routeresults.ids_iauto[ids_routeres] > 0)]
1158
ids_routeres_ibike = ids_routeres[(routeresults.ids_ibike[ids_routeres] > 0)]
1159
ids_routeres_imoto = ids_routeres[(routeresults.ids_imoto[ids_routeres] > 0)]
1160
ids_routeres_vp = list(ids_routeres_iauto) + list(ids_routeres_ibike) + list(ids_routeres_imoto)
1161
ids_routeres_ptlines = ids_routeres[(routeresults.ids_ptline[ids_routeres] > 0)]
1162
ids_routeres_car = list(ids_routeres_od_car) + list(ids_routeres_iauto)
1163
ids_routeres_bike = list(ids_routeres_od_bike) + list(ids_routeres_ibike)
1164
ids_routeres_moto = list(ids_routeres_od_moto) + list(ids_routeres_imoto)
1165
1166
ids_edges = routeresults.ids_edges[ids_routeres]
1167
ids_edges_od_car = routeresults.ids_edges[ids_routeres_od_car]
1168
ids_edges_od = routeresults.ids_edges[ids_routeres_od]
1169
ids_edges_iauto = routeresults.ids_edges[ids_routeres_iauto]
1170
ids_edges_ibike = routeresults.ids_edges[ids_routeres_ibike]
1171
ids_edges_imoto = routeresults.ids_edges[ids_routeres_imoto]
1172
ids_edges_car = routeresults.ids_edges[ids_routeres_car]
1173
ids_edges_bike = routeresults.ids_edges[ids_routeres_bike]
1174
ids_edges_moto = routeresults.ids_edges[ids_routeres_moto]
1175
ids_edges_ptline = routeresults.ids_edges[ids_routeres_ptlines]
1176
ids_edges_vp = routeresults.ids_edges[ids_routeres_vp]
1177
1178
total_flows = np.zeros(len(net.edges.get_ids())+1, dtype=np.float32)
1179
total_od_flows = np.zeros(len(total_flows), dtype=np.float32)
1180
total_vp_flows = np.zeros(len(total_flows), dtype=np.float32)
1181
total_ptline_flows = np.zeros(len(total_flows), dtype=np.float32)
1182
total_car_flows = np.zeros(len(total_flows), dtype=np.float32)
1183
total_bike_flows = np.zeros(len(total_flows), dtype=np.float32)
1184
total_moto_flows = np.zeros(len(total_flows), dtype=np.float32)
1185
total_iauto_flows = np.zeros(len(total_flows), dtype=np.float32)
1186
total_ibike_flows = np.zeros(len(total_flows), dtype=np.float32)
1187
total_imoto_flows = np.zeros(len(total_flows), dtype=np.float32)
1188
1189
for ids_edge in ids_edges:
1190
for id_edge in ids_edge:
1191
total_flows[id_edge] += 1
1192
1193
for ids_edge in ids_edges_od:
1194
for id_edge in ids_edge:
1195
total_od_flows[id_edge] += 1
1196
1197
for ids_edge in ids_edges_iauto:
1198
for id_edge in ids_edge:
1199
total_iauto_flows[id_edge] += 1
1200
1201
for ids_edge in ids_edges_ibike:
1202
for id_edge in ids_edge:
1203
total_ibike_flows[id_edge] += 1
1204
1205
for ids_edge in ids_edges_imoto:
1206
for id_edge in ids_edge:
1207
total_imoto_flows[id_edge] += 1
1208
1209
for ids_edge in ids_edges_car:
1210
for id_edge in ids_edge:
1211
total_car_flows[id_edge] += 1
1212
1213
for ids_edge in ids_edges_bike:
1214
for id_edge in ids_edge:
1215
total_bike_flows[id_edge] += 1
1216
1217
for ids_edge in ids_edges_moto:
1218
for id_edge in ids_edge:
1219
total_moto_flows[id_edge] += 1
1220
1221
for ids_edge in ids_edges_ptline:
1222
for id_edge in ids_edge:
1223
total_ptline_flows[id_edge] += 1
1224
1225
for ids_edge in ids_edges_vp:
1226
for id_edge in ids_edge:
1227
total_vp_flows[id_edge] += 1
1228
1229
ids_edgeres = self.get_ids()
1230
1231
self.total_flows[ids_edgeres] = total_flows[self.ids_edge[ids_edgeres]]
1232
self.total_od_flows[ids_edgeres] = total_od_flows[self.ids_edge[ids_edgeres]]
1233
self.total_vp_flows[ids_edgeres] = total_vp_flows[self.ids_edge[ids_edgeres]]
1234
self.total_ptline_flows[ids_edgeres] = total_ptline_flows[self.ids_edge[ids_edgeres]]
1235
self.total_car_flows[ids_edgeres] = total_car_flows[self.ids_edge[ids_edgeres]]
1236
self.total_bike_flows[ids_edgeres] = total_bike_flows[self.ids_edge[ids_edgeres]]
1237
self.total_moto_flows[ids_edgeres] = total_moto_flows[self.ids_edge[ids_edgeres]]
1238
self.total_iauto_flows[ids_edgeres] = total_iauto_flows[self.ids_edge[ids_edgeres]]
1239
self.total_ibike_flows[ids_edgeres] = total_ibike_flows[self.ids_edge[ids_edgeres]]
1240
self.total_imoto_flows[ids_edgeres] = total_imoto_flows[self.ids_edge[ids_edgeres]]
1241
1242
return True
1243
1244
def import_edgenoise(self, sumo, filepath):
1245
print 'import_edgenoise', filepath
1246
self.import_sumoxml(filepath, sumo, self.get_group('edgenoise'))
1247
1248
def import_edgeemissions(self, sumo, filepath):
1249
print 'import_edgeemissions', filepath
1250
#attrnames_data = ['fuel_abs','CO_abs','CO2_abs','NOx_abs','PMx_abs']
1251
#attrnames_averaged = ['fuel_normed','CO_normed','CO2_normed',]
1252
self.import_sumoxml(filepath, sumo, self.get_group('edgeemissions'))
1253
1254
def import_sumoxml(self, filepath, sumo, attrconfigs):
1255
element = 'edge'
1256
# print 'import_sumoxml',element
1257
#id_type = 'edge',
1258
#reader = 'interval',
1259
ids_sumo, results, interval = read_interval2(
1260
filepath, sumo, element, attrconfigs)
1261
# print ' ids_sumo',ids_sumo
1262
# print ' results.keys()',results.keys()
1263
# print ' results',results
1264
# create ids for all colums
1265
# if fileinfo['id_type']=='edge':
1266
1267
# this procedure is necessary to create new result ids only
1268
# for edges that are not yet in the database
1269
ids_sumoedge = self.ids_edge.get_linktab().ids_sumo
1270
n = len(ids_sumo)
1271
# print ' n',n
1272
ind_range = np.arange(n, dtype=np.int32)
1273
ids = np.zeros(n, dtype=np.int32)
1274
for i in ind_range:
1275
id_edge = ids_sumoedge.get_id_from_index(ids_sumo[i])
1276
if self.ids_edge.has_index(id_edge):
1277
ids[i] = self.ids_edge.get_id_from_index(id_edge)
1278
else:
1279
ids[i] = self.add_row(ids_edge=id_edge)
1280
1281
# ids = self.add_row()# here the ids_sumo can be strings too
1282
# elif fileinfo['id_type']=='trip':
1283
# ids = self.tripresults.add_rows_keyrecycle(keys = ids_sumo)#
1284
# print ' ids=',ids
1285
1286
for attrconfig in attrconfigs:
1287
1288
attrname = attrconfig.attrname
1289
1290
default = attrconfig.get_default()
1291
if type(default) in (types.IntType, types.LongType):
1292
conversion = 'i' # int
1293
values_attr = np.zeros(n, int)
1294
elif type(default) in (types.FloatType, types.ComplexType):
1295
conversion = 'f' # float
1296
values_attr = np.zeros(n, float)
1297
else:
1298
conversion = 's' # str
1299
values_attr = np.zeros(n, obj)
1300
1301
is_average = False
1302
if hasattr(attrconfig, 'is_average'):
1303
is_average = attrconfig.is_average
1304
# print ' copy',attrname,'is_average',is_average
1305
# this is a tricky way to read the data stored in
1306
# dictionarie into array tructures as used in results
1307
# problem is that not all dictionaries have all ids
1308
for i in ind_range:
1309
if is_average:
1310
valcum, num = results[attrname].get(ids_sumo[i], (default, 1))
1311
val = valcum/float(num) # average over measurements!
1312
else:
1313
val = results[attrname].get(ids_sumo[i], default)
1314
1315
if conversion == 'i':
1316
val = int(val)
1317
# else:
1318
# values_attr[i]=val
1319
# print ' attrname',attrname,conversion,val,is_average,type(val)
1320
values_attr[i] = val
1321
1322
# print ' attrname',attrname
1323
# print ' ids',type(ids),ids
1324
# print ' values_attr',type(values_attr),values_attr
1325
attrconfig.set(ids, values_attr)
1326
1327
def import_marouterxml(self, filepath, marouter):
1328
1329
if not self.has_attrname('entered_mar'):
1330
# add marouter result attributes
1331
# traveltime="14.01" speed="5.56" entered="0.00" flowCapacityRatio="0.00"/>
1332
attrinfos = OrderedDict([
1333
('entered_mar', {'name': 'Entered Marouter',
1334
# 'symbol':'F_{MA}',
1335
'unit': None,
1336
'default': 0,
1337
'info': 'Entered number of vehicles',
1338
'xmltag': 'entered',
1339
'groupnames': ['marouter']
1340
}),
1341
('speeds_mar', {'name': 'Av. speeds Marouter',
1342
'unit': 'm/s',
1343
'default': 0.0,
1344
'info': 'Av. velocity of vehicles on this Edge',
1345
'xmltag': 'speed',
1346
'groupnames': ['marouter'],
1347
'is_average': True
1348
}),
1349
('flow_capacity_ratios', {'name': 'Saturation',
1350
'default': 0.0,
1351
'unit': '%',
1352
'info': 'Ratio between simulated flows and edge capacity determined by marouter.',
1353
'xmltag': 'flowCapacityRatio',
1354
'groupnames': ['marouter']
1355
}),
1356
])
1357
1358
for attrname, kwargs in attrinfos.iteritems():
1359
self.add_resultattr(attrname, **kwargs)
1360
1361
attrconfigs = self.get_group('marouter')
1362
1363
self.import_sumoxml(filepath, marouter, attrconfigs)
1364
1365
1366
class EdgeresultFilter(Process):
1367
def __init__(self, edgeresults, logger=None, **kwargs):
1368
print 'EdgeresultFilter.__init__'
1369
1370
# TODO: let this be independent, link to it or child??
1371
1372
self._init_common(ident='edgeresultfilter',
1373
parent=edgeresults,
1374
name='Edgeresult Filter',
1375
logger=logger,
1376
info='Filters the result of specific edges.',
1377
)
1378
1379
attrsman = self.set_attrsman(cm.Attrsman(self))
1380
zones = self.parent.parent.parent.parent.landuse.zones
1381
ids_zone = zones.get_ids()
1382
zonechoices = {}
1383
for id_zone, name_zone in zip(ids_zone, zones.ids_sumo[ids_zone]):
1384
zonechoices[name_zone] = id_zone
1385
print ' zonechoices', zonechoices
1386
# make for each possible pattern a field for prob
1387
# if len(zonechoices) > 0:
1388
self.ids_zone = attrsman.add(cm.ListConf('ids_zone', [],
1389
groupnames=['options'],
1390
choices=zonechoices,
1391
name='Zones',
1392
info="""Retain edge result if edge is within these zones.""",
1393
))
1394
# else:
1395
# self.ids_zone = []
1396
# self.id_zone = attrsman.add(cm.AttrConf( 'id_zone',kwargs.get('id_zone',1),
1397
# groupnames = ['options'],
1398
# perm='rw',
1399
# name = 'Zone ID',
1400
# info = """Retain edge result if edge is within this zone.""",
1401
# ))
1402
1403
self.is_invert = attrsman.add(cm.AttrConf('is_invert', kwargs.get('is_invert', False),
1404
groupnames=['options'],
1405
perm='rw',
1406
name='invert filter',
1407
info="""Invert filter results.""",
1408
))
1409
1410
def do(self):
1411
print 'EdgeresultFilter'
1412
# links
1413
edgeresults = self.parent
1414
edgeresults.filter_zoneedges(self.ids_zone, self.is_invert)
1415
return True
1416
1417
# TODO: generate and assign additional vehicles
1418
# to satisfy prescribes ownership
1419
1420
1421
class TrajectoryResults(am.ArrayObjman):
1422
"""Collects trajectories for all vehicles with a battery device."""
1423
1424
def __init__(self, parent, datapathkey='trajectorypath',
1425
is_add_default=True,
1426
name='Trajectory results',
1427
info='Table with trajectory and speed data of individual vehicles. Either all vehicles or vehicles with a fcd device.',
1428
**kwargs):
1429
1430
self._init_objman(ident='trajectory_results',
1431
parent=parent, # main results object
1432
info=info,
1433
name=name,
1434
**kwargs)
1435
1436
self.add(cm.AttrConf('datapathkey', datapathkey,
1437
groupnames=['_private'],
1438
name='data pathkey',
1439
info="key of data path",
1440
))
1441
1442
self.add(cm.AttrConf('times', np.array([], dtype=np.float32),
1443
groupnames=['_private'],
1444
name='Times',
1445
info="Times steps for energy measurements",
1446
))
1447
1448
self.add_col(am.ListArrayConf('trajectories',
1449
groupnames=['_private'],
1450
name='Trajectories',
1451
info="x,y,z, trajectories of all vehicles during each time step",
1452
))
1453
1454
self.add_col(am.ListArrayConf('angles',
1455
groupnames=['_private'],
1456
name='Angle',
1457
info="Angles of all vehicles during each time step",
1458
))
1459
1460
self.add_col(am.ListArrayConf('speeds',
1461
groupnames=['_private'],
1462
name='Speed',
1463
info="Speed of all vehicles during each time step",
1464
))
1465
1466
# self.add(cm.FuncConf( 'energy_total','on_energy_total', 0.0,
1467
# groupnames = ['summary'],
1468
# name = 'Total energy consumption',
1469
# unit = 'KWh',
1470
# info = 'Total electrical energy consumpton of all vehicles.',
1471
# ))
1472
1473
self.add_col(SumoIdsConf('vehicle',
1474
#name ='SUMO vehicle ID',
1475
info='SUMO vehicle ID, as used in route files.',
1476
perm='r'))
1477
1478
def import_xml(self, sumo, datapaths):
1479
datapathkey = self.datapathkey.get_value()
1480
print 'TrajectoryResults.import_xml datapathkey', datapathkey, datapaths.has_key(datapathkey)
1481
if datapaths.has_key(datapathkey):
1482
self.import_trajectories_sumoxml(datapaths[datapathkey], sumo)
1483
1484
def import_trajectories_sumoxml(self, filepath, sumo):
1485
element = 'vehicle'
1486
print 'TrajectoryResults.import_trajectories_sumoxml', element, filepath
1487
1488
ids_sumo, times, trajectories, angles, speeds = read_trajectories(
1489
filepath, sumo, element)
1490
1491
n = len(ids_sumo)
1492
ids_res = self.add_rows(n=n, ids_sumo=ids_sumo)
1493
self.times.set_value(times)
1494
self.trajectories[ids_res] = trajectories
1495
self.angles[ids_res] = angles
1496
self.speeds[ids_res] = speeds
1497
# self.print_trajectories()
1498
1499
def print_trajectories(self):
1500
ids_res = self.get_ids()
1501
times = self.times.get_value()
1502
for i, t in zip(xrange(len(times)), times):
1503
print 79*'-'
1504
print 'time=', t, 's', len(times)
1505
for id_res, id_sumo_veh, traj, a, v in zip(ids_res, self.ids_sumo[ids_res], self.trajectories[ids_res], self.angles[ids_res], self.speeds[ids_res]):
1506
# print ' id_sumo_veh',id_sumo_veh,id_res
1507
# print ' v',v[i]
1508
# print ' traj',traj[i]
1509
# print ' a',a[i]
1510
print ' id_sumo_veh', id_sumo_veh, ': (x,y)', traj[i], 'a=%.2f', a[i], ' v=%.2fm/s' % v[i], len(a), len(v), len(traj)
1511
1512
1513
class ElectricEnergyVehicleResults(am.ArrayObjman):
1514
"""Collects electric energy results for all vehicles with a battery device."""
1515
1516
def __init__(self, parent, datapathkey='electricenergypath',
1517
is_add_default=True,
1518
name='Electric energy vehicle results',
1519
info='Table with electric energy consumption data for each vehicle with a battery device.',
1520
**kwargs):
1521
1522
self._init_objman(ident='electricenergy_vehicleresults',
1523
parent=parent, # main results object
1524
info=info,
1525
name=name,
1526
**kwargs)
1527
1528
self.add(cm.AttrConf('datapathkey', datapathkey,
1529
groupnames=['_private'],
1530
name='data pathkey',
1531
info="key of data path",
1532
))
1533
1534
self.add(cm.AttrConf('times', np.array([], dtype=np.float32),
1535
groupnames=['_private'],
1536
name='Times',
1537
info="Times steps for energy measurements",
1538
))
1539
1540
self.add(cm.AttrConf('energies', np.array([], dtype=np.float32),
1541
groupnames=['_private'],
1542
name='Energies',
1543
info="Energy consumptions of all vehicles during each time step",
1544
))
1545
1546
self.add(cm.FuncConf('energy_total', 'on_energy_total', 0.0,
1547
groupnames=['summary'],
1548
name='Total energy consumption',
1549
unit='KWh',
1550
info='Total electrical energy consumpton of all vehicles.',
1551
))
1552
1553
self.add_col(SumoIdsConf('vehicle',
1554
#name ='SUMO vehicle ID',
1555
info='SUMO vehicle ID, as used in route files.',
1556
perm='r'))
1557
1558
attrinfos = OrderedDict([
1559
('consumptions', {'name': 'Consumption', 'xmltag': 'energyConsumed', 'unit': 'Ws',
1560
'default': 0.0, 'info': 'Total electrical energy consumption.', 'groupnames': ['electricenergydata']}),
1561
('charges_station', {'name': 'Charged at station', 'xmltag': 'energyCharged', 'unit': 'Ws', 'default': 0.0,
1562
'info': 'Total electrical energy charged at charging stations.', 'groupnames': ['electricenergydata']}),
1563
('charges_av', {'name': 'Average charge', 'xmltag': 'actualBatteryCapacity', 'unit': 'Ws', 'default': 0.0,
1564
'info': 'Average level of battery charge', 'groupnames': ['electricenergydata'], 'is_average': True}),
1565
('speeds_av', {'name': 'Average speeds', 'xmltag': 'speed', 'unit': 'm/s', 'default': 0.0,
1566
'info': 'Average speed', 'groupnames': ['electricenergydata'], 'is_average': True}),
1567
])
1568
1569
for attrname, kwargs in attrinfos.iteritems():
1570
self.add_resultattr(attrname, **kwargs)
1571
1572
def on_energy_total(self):
1573
"""Returns total energy consumption"""
1574
return np.sum(self.consumptions.get_value())/10.0**3
1575
1576
def add_resultattr(self, attrname, **kwargs):
1577
1578
# default cannot be kwarg
1579
default = kwargs['default']
1580
del kwargs['default']
1581
if kwargs.has_key('groupnames'):
1582
kwargs['groupnames'].append('results')
1583
else:
1584
kwargs['groupnames'] = ['results']
1585
1586
self.add_col(am.ArrayConf(attrname, default, **kwargs))
1587
1588
# def import_routesdata(self, filepath):
1589
# # TODO
1590
# pass
1591
1592
# def import_tripdata(self, filepath):
1593
# #print 'import_tripdata',filepath,self.get_group('tripdata')
1594
# self.import_sumoxml(filepath,self.get_group('tripdata'))
1595
1596
def import_xml(self, sumo, datapaths):
1597
datapathkey = self.datapathkey.get_value()
1598
if datapaths.has_key(datapathkey):
1599
self.import_electricenergy_sumoxml(datapaths[datapathkey], sumo)
1600
1601
def import_electricenergy_sumoxml(self, filepath, sumo):
1602
element = 'vehicle'
1603
print 'ElectricEnergyresults.import_electricenergy_sumoxml', element, filepath
1604
#id_type = 'edge',
1605
#reader = 'interval',
1606
attrconfigs = self.get_group('electricenergydata')
1607
# print 'import_sumoxml',element
1608
#id_type = 'edge',
1609
#reader = 'interval',
1610
ids_sumo, results, interval, times, energies = read_electrical_energy(
1611
filepath, sumo, element, attrconfigs)
1612
1613
self.times.set_value(times)
1614
self.energies.set_value(energies)
1615
1616
print ' times=\n', self.times.get_value()
1617
print ' energies=\n', self.energies.get_value()
1618
1619
# print ' ids_sumo',ids_sumo
1620
# print ' results.keys()',results.keys()
1621
# print ' results',results
1622
# create ids for all colums
1623
# if fileinfo['id_type']=='edge':
1624
1625
# this procedure is necessary to create new result ids only
1626
# for edges that are not yet in the database
1627
#ids_sumotrip = self.ids_trip.get_linktab().ids_sumo
1628
n = len(ids_sumo)
1629
ids = self.add_rows(n=n, ids_sumo=ids_sumo)
1630
print ' n', n
1631
ind_range = np.arange(n, dtype=np.int32)
1632
1633
#ids = np.zeros(n, dtype=np.int32)
1634
# for i in ind_range:
1635
# id_trip = ids_sumotrip.get_id_from_index(ids_sumo[i])
1636
# if self.ids_trip.has_index(id_trip):
1637
# ids[i] = self.ids_trip.get_id_from_index(id_edge)
1638
# else:
1639
# ids[i] = self.add_row(ids_trip = id_edge)
1640
1641
# ids = self.add_row()# here the ids_sumo can be strings too
1642
# elif fileinfo['id_type']=='trip':
1643
# ids = self.tripresults.add_rows_keyrecycle(keys = ids_sumo)#
1644
# print ' ids=',ids
1645
1646
for attrconfig in attrconfigs:
1647
1648
attrname = attrconfig.attrname
1649
1650
default = attrconfig.get_default()
1651
if type(default) in (types.IntType, types.LongType):
1652
conversion = 'i' # int
1653
values_attr = np.zeros(n, int)
1654
elif type(default) in (types.FloatType, types.ComplexType):
1655
conversion = 'f' # float
1656
values_attr = np.zeros(n, float)
1657
else:
1658
conversion = 's' # str
1659
values_attr = np.zeros(n, obj)
1660
1661
is_average = False
1662
if hasattr(attrconfig, 'is_average'):
1663
is_average = attrconfig.is_average
1664
# print ' copy',attrname,'is_average',is_average
1665
# this is a tricky way to read the data stored in
1666
# dictionarie into array tructures as used in results
1667
# problem is that not all dictionaries have all ids
1668
for i in ind_range:
1669
if is_average:
1670
valcum, num = results[attrname].get(ids_sumo[i], (default, 1))
1671
val = valcum/float(num) # average over measurements!
1672
else:
1673
val = results[attrname].get(ids_sumo[i], default)
1674
1675
if conversion == 'i':
1676
val = int(val)
1677
# else:
1678
# values_attr[i]=val
1679
# print ' attrname',attrname,conversion,val,is_average,type(val)
1680
values_attr[i] = val
1681
1682
# print ' attrname',attrname
1683
# print ' ids',type(ids),ids
1684
# print ' values_attr',type(values_attr),values_attr
1685
attrconfig.set(ids, values_attr)
1686
1687
1688
class Simresults(cm.BaseObjman):
1689
def __init__(self, ident='simresults', parent=None,
1690
name='Simulation results',
1691
info='Results of SUMO simulation run.',
1692
outfile_prefix='out',
1693
scenario=None,
1694
**kwargs):
1695
1696
# either scenario must be provided or
1697
# parent must provide method get_scenario
1698
if scenario is None:
1699
scenario = parent.get_scenario()
1700
# print 'Network.__init__',name,kwargs
1701
rootname = scenario.get_rootfilename()
1702
rootdirpath = scenario.get_workdirpath()
1703
1704
self._init_objman(ident=ident, parent=parent, name=name,
1705
info=info, **kwargs)
1706
attrsman = self.set_attrsman(cm.Attrsman(self))
1707
1708
self._init_attributes()
1709
1710
def _init_attributes(self):
1711
attrsman = self.get_attrsman()
1712
scenario = self.get_scenario()
1713
self.edgeresults = attrsman.add(cm.ObjConf(Edgeresults(self, scenario.net.edges),
1714
groupnames=['Edge results'],
1715
))
1716
self.connectionresults = attrsman.add(cm.ObjConf(Connectionresults('connectionresults', self, scenario.demand.trips,
1717
scenario.net.edges), groupnames=['Connection results']))
1718
1719
self.routeresults = attrsman.add(cm.ObjConf(Routeresults('routeresults', self, scenario.demand.trips,
1720
scenario.net.edges), groupnames=['Route results']))
1721
# add trip results from all demand objects
1722
print 'Simresults._init_attributes'
1723
print ' scenario.demand.get_demandobjects()', scenario.demand.get_demandobjects()
1724
for demandobj in scenario.demand.get_demandobjects():
1725
demandobj.config_results(self)
1726
1727
for simobj in self.parent.get_simobjects():
1728
simobj.config_simresults(self)
1729
1730
self.electricenergy_vehicleresults = attrsman.add(cm.ObjConf(ElectricEnergyVehicleResults(self),
1731
groupnames=['Results'],
1732
))
1733
1734
self.trajectory_results = attrsman.add(cm.ObjConf(TrajectoryResults(self),
1735
groupnames=['Results'],
1736
))
1737
1738
def clear_results(self):
1739
for resultobj in self.get_attrsman().get_group('Results'):
1740
resultobj.clear()
1741
self.connectionresults.clear_rows()
1742
self.routeresults.clear_rows()
1743
self.edgeresults.clear_rows()
1744
1745
def get_resultobj(self, ident):
1746
# print 'get_resultobj',hasattr(self,ident)
1747
if hasattr(self, ident):
1748
return getattr(self, ident)
1749
1750
else:
1751
return None
1752
1753
def add_resultobj(self, resultobj, **kwargs):
1754
# print 'RESULTS:add_resultobj',resultobj.ident
1755
# attention: need to check whether already set
1756
# because setattr is set explicitely after add
1757
if hasattr(self, resultobj.get_ident()):
1758
# self.get_attrsman().delete(resultobj.get_ident())
1759
getattr(self, resultobj.get_ident()).clear()
1760
1761
if not hasattr(self, resultobj.get_ident()):
1762
if kwargs.has_key('groupnames'):
1763
kwargs['groupnames'].append('Results')
1764
else:
1765
kwargs['groupnames'] = ['Results']
1766
attrsman = self.get_attrsman()
1767
attrsman.add(cm.ObjConf(resultobj, **kwargs))
1768
setattr(self, resultobj.get_ident(), resultobj)
1769
1770
# for resultobj in self.get_attrsman().get_group_attrs('Results').values():
1771
# print ' check resultobject',resultobj.get_ident_abs()
1772
1773
# def import_xml(self, edgedatapath=None, edgenoisepath=None, edgeemissionspath = None, routesdatapath=None, tripdatapath=None):
1774
1775
# def get_path(self, datapath):
1776
# #edgedatapath=None, edgenoisepath=None, edgeemissionspath = None, routesdatapath=None, tripdatapath=None
1777
1778
def import_xml(self, sumo, **datapaths):
1779
print 'Simresults.import_xml', self.get_ident_abs()
1780
# print ' datapaths',datapaths
1781
# import first all edge oriented results for the whole net
1782
if datapaths.has_key('edgedatapath'):
1783
print 'import edge data'
1784
self.edgeresults.import_edgedata(sumo, datapaths['edgedatapath'])
1785
1786
if datapaths.has_key('edgenoisepath'):
1787
print 'import edge noise'
1788
self.edgeresults.import_edgenoise(sumo, datapaths['edgenoisepath'])
1789
1790
if datapaths.has_key('edgeemissionspath'):
1791
print 'import edge emissons'
1792
self.edgeresults.import_edgeemissions(sumo, datapaths['edgeemissionspath'])
1793
1794
# import all other resultobjects
1795
for resultobj in self.get_attrsman().get_group_attrs('Results').values():
1796
print ' import other resultobject', resultobj.ident
1797
resultobj.import_xml(sumo, datapaths)
1798
1799
if datapaths.has_key('routesdatapath'):
1800
print 'import route results'
1801
self.routeresults.import_xml(sumo, datapaths)
1802
print 'importedge flows'
1803
self.edgeresults.import_edgeflows(sumo, datapaths['edgedatapath'])
1804
print 'import connection flows'
1805
self.connectionresults.evaluate_results(sumo, datapaths)
1806
1807
# def process(self, process = None):
1808
# print 'Simresults.process'
1809
# for demandobj in self.parent.demand.get_demandobjects():
1810
# print ' process_results',demandobj
1811
# demandobj.process_results(self, process)
1812
1813
def get_tripresults(self):
1814
return self.get_attrsman().get_group_attrs('Trip results').values()
1815
1816
# def import_routesdata(self, routesdatapath):
1817
# for tripresult in self.get_tripresults():
1818
# tripresult.import_routesdata(routesdatapath)
1819
1820
# def import_tripdata(self, tripdatapath):
1821
# for tripresult in self.get_tripresults():
1822
# tripresult.import_tripdata(tripdatapath)
1823
1824
def save(self, filepath=None, is_not_save_parent=True):
1825
if filepath is None:
1826
self.get_scenario().get_rootfilepath()+'.res.obj'
1827
cm.save_obj(self, filepath, is_not_save_parent=is_not_save_parent)
1828
1829
def get_scenario(self):
1830
return self.parent.parent
1831
1832
1833
class MarouterLoadReader(handler.ContentHandler):
1834
"""
1835
Reads edge based load results of Marouter.
1836
1837
"""
1838
1839
def __init__(self, marouter, attrsconfigs_cumulative, attrsconfigs_average):
1840
self._marouter = marouter
1841
self._attrconfigs = attrconfigs
1842
self._element = 'edge'
1843
self._time_begin = None
1844
self._time_inter_begin = 0.0
1845
self._time_inter_end = 0.0
1846
self._time_tot = 0.0
1847
self._n_inter = 0
1848
self._values = {}
1849
self._ids = []
1850
1851
def startElement(self, name, attrs):
1852
# <edge id="-120634989" traveltime="6.74" speed="13.89" entered="0.00" flowCapacityRatio="0.00"/>
1853
# if attrs.has_key('id'):
1854
# print 'startElement',name,name == self._element,self._element
1855
if name == 'interval':
1856
time_inter_begin = float(attrs['begin'])
1857
# print 79*'-'
1858
# print 'startElement interval',self.is_inter_valid,' time_inter_begin',time_inter_begin,'is_valid',time_inter_begin >= self._sumo.time_warmup
1859
self.is_inter_valid = True
1860
time_inter_end = float(attrs['end'])
1861
1862
self._time_inter = int(time_inter_end)-int(time_inter_begin)
1863
# here we just take the start and end time ofthe whole
1864
# measurement period
1865
if self._time_begin is None: # take very first time only
1866
self._time_begin = int(time_inter_begin)
1867
self._time_end = int(time_inter_end)
1868
self._time_tot += self._time_inter
1869
self._n_inter += 1
1870
1871
if name == self._element:
1872
if not self.is_inter_valid:
1873
return # no interval initialized
1874
1875
id_elem = attrs.get('id', None)
1876
# print 'startElement ---id_elem',id_elem
1877
if id_elem is None:
1878
return # id did not fit requested trip type
1879
1880
if id_elem not in self._ids:
1881
self._ids.append(id_elem)
1882
1883
# no arrival data availlable if trip has not been finished!!
1884
for attrsconfig in self._attrsconfigs_cumulative:
1885
xmltag = attrsconfig.xmltag
1886
attrname = attrsconfig.attrname
1887
1888
if attrs.has_key(xmltag):
1889
# print ' attrname cum',attrname,attrs.has_key(attrname),'*'+attrs[attrname]+'*'
1890
a = attrs[xmltag]
1891
1892
if a.strip() != '':
1893
if self._values[attrname].has_key(id_elem):
1894
self._values[attrname][id_elem] += float(a)
1895
# print ' added val',xmltag,attrname,self._values[attrname][id_elem],'val',float(a)
1896
else:
1897
self._values[attrname][id_elem] = float(a)
1898
# print ' set val',xmltag,attrname,self._values[attrname][id_elem],'val',float(a)
1899
1900
# if (id in ('1/0to1/1','1/0to2/0')) & (attrname == 'entered'):
1901
# self.n_test+=int(attrs[attrname])
1902
# print ' -read ',id,attrname,attrs[attrname],self.n_test,self._values[attrname][id]
1903
#
1904
# if (id in ('0/0to1/0')) & (attrname == 'left'):
1905
# self.n_test2+=int(attrs[attrname])
1906
# print ' +read ',id,attrname,attrs[attrname],self.n_test2,self._values[attrname][id]
1907
1908
for attrsconfig in self._attrsconfigs_average:
1909
xmltag = attrsconfig.xmltag
1910
attrname = attrsconfig.attrname
1911
if attrs.has_key(xmltag):
1912
# print ' attrname',attrname,attrs.has_key(attrname),'*'+attrs[attrname]+'*'
1913
# n=float(self.n_inter)
1914
a = attrs[xmltag]
1915
if a.strip() != '':
1916
if self._values[attrname].has_key(id_elem):
1917
valcum, n = self._values[attrname][id_elem]
1918
valcum += float(a)
1919
n += 1
1920
#self._values[attrname][id_elem] = ( (n-1)*self._values[attrname][id_elem] + float(a))/n
1921
#self._values[attrname][id] += float(a)/self._time_inter
1922
#self._n_values[attrname][id] += 1
1923
else:
1924
valcum = float(a)
1925
n = 1
1926
#self._values[attrname][id_elem] = float(a)
1927
#self._values[attrname][id_elem] = float(a)/self._time_inter
1928
#self._n_values[attrname][id] = 1
1929
# print ' added cumval',xmltag,attrname,valcum,'val',float(a)
1930
self._values[attrname][id_elem] = (valcum, n)
1931
1932
1933
class IntervalAvReader2(handler.ContentHandler):
1934
"""
1935
Reads edge or lane based intervals
1936
and returns time averaged values for each attribute name.
1937
1938
"""
1939
1940
def __init__(self, element, sumo, attrsconfigs_cumulative, attrsconfigs_average):
1941
"""
1942
element is "lane" or "edge" or "tripinfo"
1943
attrnames is a list of attribute names to read.
1944
"""
1945
print 'IntervalAvReader2', element
1946
# print ' attrsconfigs_cumulative'
1947
# for attrconfig in attrsconfigs_cumulative: print ' ',attrconfig.attrname
1948
1949
# print ' attrsconfigs_average'
1950
# for attrconfig in attrsconfigs_average: print ' ',attrconfig.attrname
1951
self._element = element
1952
self._sumo = sumo # the sumo process generating the data
1953
self._time_start_recording = sumo.simtime_start + sumo.time_warmup
1954
self._attrsconfigs_cumulative = attrsconfigs_cumulative
1955
self._attrsconfigs_average = attrsconfigs_average
1956
self._time_begin = None
1957
self._time_end = None
1958
self._values = {}
1959
self._ids = []
1960
#self._n_values= {}
1961
self.is_inter_valid = False
1962
self.n_inter = 0
1963
self.n_test = 0
1964
self.n_test2 = 0
1965
1966
# TODO: if we knew here all ids then we
1967
# could create a numeric array per attribute
1968
# idea: pass ids as input arg
1969
for attrsconfig in attrsconfigs_cumulative+attrsconfigs_average:
1970
self._values[attrsconfig.attrname] = {}
1971
# print ' init',attrsconfig.attrname
1972
#self._n_values= {}
1973
1974
def get_id_elem(self, attrs):
1975
"""
1976
Returns the trip ID as integer if the desired trip type has been read.
1977
Otherwise -1 is returned.
1978
"""
1979
return attrs['id']
1980
1981
def startElement(self, name, attrs):
1982
# if attrs.has_key('id'):
1983
# print ' parse',name,self._element,name == self._element,self.is_inter_valid, 'id=',attrs.get('id','-')
1984
# print 'startElement',name,name == self._element,self._element
1985
1986
# if name == 'timestep':
1987
1988
if name == 'interval':
1989
time_inter_begin = float(attrs['begin'])
1990
# print 79*'-'
1991
# print 'startElement interval',self.is_inter_valid,' time_inter_begin',time_inter_begin,'is_valid',time_inter_begin >= self._sumo.time_warmup
1992
if time_inter_begin >= self._sumo.time_warmup:
1993
self.is_inter_valid = True
1994
time_inter_end = float(attrs['end'])
1995
1996
self._time_inter = int(time_inter_end)-int(time_inter_begin)
1997
# here we just take the start and end time ofthe whole
1998
# measurement period
1999
if self._time_begin is None: # take very first time only
2000
self._time_begin = int(time_inter_begin)
2001
self._time_end = int(time_inter_end)
2002
self.n_inter += 1
2003
else:
2004
self.is_inter_valid = False
2005
2006
if name == self._element:
2007
if not self.is_inter_valid:
2008
return # no interval initialized
2009
2010
id_elem = self.get_id_elem(attrs)
2011
# print 'startElement ---id_elem',id_elem
2012
if id_elem == -1:
2013
return # id did not fit requested trip type
2014
2015
if id_elem not in self._ids:
2016
self._ids.append(id_elem)
2017
2018
# no arrival data availlable if trip has not been finished!!
2019
for attrsconfig in self._attrsconfigs_cumulative:
2020
xmltag = attrsconfig.xmltag
2021
attrname = attrsconfig.attrname
2022
2023
if attrs.has_key(xmltag):
2024
# print ' attrname cum',attrname,attrs.has_key(attrname),'*'+attrs[attrname]+'*'
2025
a = attrs[xmltag]
2026
2027
if a.strip() != '':
2028
if self._values[attrname].has_key(id_elem):
2029
self._values[attrname][id_elem] += float(a)
2030
# print ' added val',xmltag,attrname,self._values[attrname][id_elem],'val',float(a)
2031
else:
2032
self._values[attrname][id_elem] = float(a)
2033
# print ' set val',xmltag,attrname,self._values[attrname][id_elem],'val',float(a)
2034
2035
# if (id in ('1/0to1/1','1/0to2/0')) & (attrname == 'entered'):
2036
# self.n_test+=int(attrs[attrname])
2037
# print ' -read ',id,attrname,attrs[attrname],self.n_test,self._values[attrname][id]
2038
#
2039
# if (id in ('0/0to1/0')) & (attrname == 'left'):
2040
# self.n_test2+=int(attrs[attrname])
2041
# print ' +read ',id,attrname,attrs[attrname],self.n_test2,self._values[attrname][id]
2042
2043
for attrsconfig in self._attrsconfigs_average:
2044
xmltag = attrsconfig.xmltag
2045
attrname = attrsconfig.attrname
2046
if attrs.has_key(xmltag):
2047
# print ' attrname',attrname,attrs.has_key(attrname),'*'+attrs[attrname]+'*'
2048
# n=float(self.n_inter)
2049
a = attrs[xmltag]
2050
if a.strip() != '':
2051
if self._values[attrname].has_key(id_elem):
2052
valcum, n = self._values[attrname][id_elem]
2053
valcum += float(a)
2054
n += 1
2055
#self._values[attrname][id_elem] = ( (n-1)*self._values[attrname][id_elem] + float(a))/n
2056
#self._values[attrname][id] += float(a)/self._time_inter
2057
#self._n_values[attrname][id] += 1
2058
else:
2059
valcum = float(a)
2060
n = 1
2061
#self._values[attrname][id_elem] = float(a)
2062
#self._values[attrname][id_elem] = float(a)/self._time_inter
2063
#self._n_values[attrname][id] = 1
2064
# print ' added cumval',xmltag,attrname,valcum,'val',float(a)
2065
self._values[attrname][id_elem] = (valcum, n)
2066
2067
def get_data(self):
2068
return self._values
2069
2070
def get_interval(self):
2071
# returns time interval between first and last measurement
2072
return (self._time_begin, self._time_end)
2073
2074
def get_ids(self):
2075
return self._ids
2076
2077
2078
class ElectricalEnergyReader(IntervalAvReader2):
2079
"""
2080
Reads intervals of the electrcal energy file and cumulates data.
2081
"""
2082
2083
def __init__(self, element, sumo, attrsconfigs_cumulative, attrsconfigs_average):
2084
"""
2085
element is "lane" or "edge" or "tripinfo"
2086
attrnames is a list of attribute names to read.
2087
"""
2088
print 'ElectricalEnergyReader', element
2089
# print ' attrsconfigs_cumulative',attrsconfigs_cumulative
2090
# print ' attrsconfigs_average',attrsconfigs_average
2091
IntervalAvReader2.__init__(self, element, sumo, attrsconfigs_cumulative, attrsconfigs_average)
2092
self.time_lastint = -1.0
2093
2094
self.times = []
2095
self.energies = []
2096
self._energy_step = 0.0 # energy os all vehicles during last step
2097
self._consumptionsname = "consumptions"
2098
2099
def startElement(self, name, attrs):
2100
# print 'startElement',name,name == self._element,'time_lastint', self.time_lastint,'is_inter_valid',self.is_inter_valid,'e=',self._energy_step
2101
2102
if name == 'timestep':
2103
if self.time_lastint < 0:
2104
# print ' set time_lastint to ',float(attrs['time'])
2105
self.time_lastint = float(attrs['time'])
2106
self.is_inter_valid = False
2107
else:
2108
2109
time_inter_begin = self.time_lastint
2110
# print 79*'-'
2111
# print ' time_inter_begin',time_inter_begin,'is_valid',time_inter_begin >= self._sumo.time_warmup
2112
if time_inter_begin >= self._sumo.time_warmup:
2113
self.is_inter_valid = True
2114
time_inter_end = float(attrs['time'])
2115
self.times.append(time_inter_end)
2116
self.energies.append(self._energy_step)
2117
self._energy_step = 0.0
2118
2119
self._time_inter = int(time_inter_end)-int(time_inter_begin)
2120
# here we just take the start and end time ofthe whole
2121
# measurement period
2122
if self._time_begin is None: # take very first time only
2123
self._time_begin = int(time_inter_begin)
2124
self._time_end = int(time_inter_end)
2125
self.n_inter += 1
2126
else:
2127
self.is_inter_valid = False
2128
2129
if name == self._element:
2130
if not self.is_inter_valid:
2131
return # no interval initialized
2132
2133
id_elem = self.get_id_elem(attrs)
2134
# print ' ---id_veh_sumo',id_elem
2135
if id_elem == -1:
2136
return # id did not fit requested trip type
2137
2138
if id_elem not in self._ids:
2139
self._ids.append(id_elem)
2140
2141
for attrsconfig in self._attrsconfigs_cumulative:
2142
xmltag = attrsconfig.xmltag
2143
attrname = attrsconfig.attrname
2144
# print ' attrname (cum)',attrname,xmltag,attrs.has_key(xmltag)
2145
if attrs.has_key(xmltag):
2146
2147
a = attrs[xmltag]
2148
2149
if a.strip() != '':
2150
a = float(a)
2151
if self._values[attrname].has_key(id_elem):
2152
self._values[attrname][id_elem] += a
2153
# print ' added val',xmltag,attrname,self._values[attrname][id_elem],'val',float(a)
2154
else:
2155
self._values[attrname][id_elem] = a
2156
# print ' set val',xmltag,attrname,self._values[attrname][id_elem],'val',float(a)
2157
2158
if attrname == self._consumptionsname:
2159
self._energy_step += a
2160
2161
for attrsconfig in self._attrsconfigs_average:
2162
xmltag = attrsconfig.xmltag
2163
attrname = attrsconfig.attrname
2164
# print ' attrname (av)',attrname,xmltag,attrs.has_key(xmltag)
2165
if attrs.has_key(xmltag):
2166
2167
a = attrs[xmltag]
2168
if a.strip() != '':
2169
a = float(a)
2170
if self._values[attrname].has_key(id_elem):
2171
valcum, n = self._values[attrname][id_elem]
2172
# print ' add val', float(a),'to',valcum
2173
valcum += a
2174
n += 1
2175
else:
2176
valcum = a
2177
n = 1
2178
# print ' set val',valcum
2179
# print ' added cumval',xmltag,attrname,valcum,'val',float(a)
2180
self._values[attrname][id_elem] = (valcum, n)
2181
2182
def get_times(self):
2183
return np.array(self.times, dtype=np.float32)
2184
2185
def get_energies(self):
2186
return np.array(self.energies, dtype=np.float32)
2187
2188
2189
class TripresultReader(IntervalAvReader2):
2190
def __init__(self, trips, element, sumo, attrsconfigs_cumulative, attrsconfigs_average):
2191
"""
2192
element is "lane" or "edge" or "tripinfo" or "personinfo"
2193
attrnames is a list of attribute names to read.
2194
2195
"""
2196
self._trips = trips
2197
#IntervalAvReader2.__init__(self, element,sumo, attrsconfigs_cumulative, attrsconfigs_average)
2198
self._element = element
2199
self._sumo = sumo # the sumo process generating the data
2200
self._attrsconfigs_cumulative = attrsconfigs_cumulative
2201
self._attrsconfigs_average = attrsconfigs_average
2202
#self._time_begin = None
2203
#self._time_end = None
2204
self._values = {}
2205
self._ids = []
2206
#self._n_values= {}
2207
#self.is_inter_valid = False
2208
#self.n_inter = 0
2209
#self.n_test = 0
2210
#self.n_test2 = 0
2211
2212
# TODO: if we knew here all ids then we
2213
# could create a numeric array per attribute
2214
# idea: pass ids as input arg
2215
for attrsconfig in attrsconfigs_cumulative+attrsconfigs_average:
2216
self._values[attrsconfig.attrname] = {}
2217
# print ' init',attrsconfig.attrname
2218
#self._n_values= {}
2219
2220
def get_id_elem(self, attrs):
2221
"""
2222
Returns the trip ID as integer if the desired trip type has been read.
2223
Otherwise -1 is returned.
2224
"""
2225
# print 'get_id_elem check id=',attrs['id'],self._trips,id(self._trips)
2226
return self._trips.get_id_from_id_sumo(attrs['id'])
2227
2228
def startElement(self, name, attrs):
2229
# if attrs.has_key('id'):
2230
# print ' parse',name,self._element,name == self._element,'id=',attrs.get('id','-')
2231
2232
if name == self._element:
2233
2234
id_elem = self.get_id_elem(attrs)
2235
# print ' ---id_elem',id_elem
2236
if id_elem == -1:
2237
return # id did not fit requested trip type
2238
2239
if id_elem not in self._ids:
2240
self._ids.append(id_elem)
2241
2242
# no arrival data availlable if trip has not been finished!!
2243
for attrsconfig in self._attrsconfigs_cumulative:
2244
xmltag = attrsconfig.xmltag
2245
attrname = attrsconfig.attrname
2246
2247
if attrs.has_key(xmltag):
2248
# print ' attrname',attrname,attrs.has_key(attrname)
2249
if attrs.has_key(attrname):
2250
2251
# print ' val *'+attrs[xmltag]+'*'
2252
a = attrs[xmltag]
2253
2254
if a.strip() != '':
2255
if self._values[attrname].has_key(id_elem):
2256
self._values[attrname][id_elem] += float(a)
2257
else:
2258
self._values[attrname][id_elem] = float(a)
2259
2260
# if (id in ('1/0to1/1','1/0to2/0')) & (attrname == 'entered'):
2261
# self.n_test+=int(attrs[attrname])
2262
# print ' -read ',id,attrname,attrs[attrname],self.n_test,self._values[attrname][id]
2263
#
2264
# if (id in ('0/0to1/0')) & (attrname == 'left'):
2265
# self.n_test2+=int(attrs[attrname])
2266
# print ' +read ',id,attrname,attrs[attrname],self.n_test2,self._values[attrname][id]
2267
2268
for attrsconfig in self._attrsconfigs_average:
2269
xmltag = attrsconfig.xmltag
2270
attrname = attrsconfig.attrname
2271
if attrs.has_key(xmltag):
2272
# n=float(self.n_inter)
2273
a = attrs[xmltag]
2274
if a.strip() != '':
2275
if self._values[attrname].has_key(id_elem):
2276
valcum, n = self._values[attrname][id_elem]
2277
valcum += float(a)
2278
n += 1
2279
#self._values[attrname][id_elem] = ( (n-1)*self._values[attrname][id_elem] + float(a))/n
2280
#self._values[attrname][id] += float(a)/self._time_inter
2281
#self._n_values[attrname][id] += 1
2282
else:
2283
valcum = float(a)
2284
n = 1
2285
#self._values[attrname][id_elem] = float(a)
2286
#self._values[attrname][id_elem] = float(a)/self._time_inter
2287
#self._n_values[attrname][id] = 1
2288
self._values[attrname][id_elem] = (valcum, n)
2289
2290
def get_data(self):
2291
return self._values
2292
2293
def get_ids(self):
2294
return self._ids
2295
2296
2297
def read_electrical_energy(filepath, sumo, element, attrsconfigs):
2298
print 'read_electrical_energy'
2299
attrsconfigs_cumulative = []
2300
attrsconfigs_average = []
2301
for attrsconfig in attrsconfigs:
2302
# print ' check',attrsconfig.attrname
2303
if hasattr(attrsconfig, 'is_average'):
2304
if attrsconfig.is_average:
2305
attrsconfigs_average.append(attrsconfig)
2306
else:
2307
attrsconfigs_cumulative.append(attrsconfig)
2308
else:
2309
attrsconfigs_cumulative.append(attrsconfig)
2310
2311
reader = ElectricalEnergyReader(element, sumo, attrsconfigs_cumulative, attrsconfigs_average)
2312
parse(filepath, reader)
2313
return reader.get_ids(), reader.get_data(), reader.get_interval(), reader.get_times(), reader.get_energies()
2314
2315
2316
class ElectricalEnergyReader(IntervalAvReader2):
2317
"""
2318
Reads intervals of the electrcal energy file and cumulates data.
2319
"""
2320
2321
def __init__(self, element, sumo, attrsconfigs_cumulative, attrsconfigs_average):
2322
"""
2323
element is "lane" or "edge" or "tripinfo"
2324
attrnames is a list of attribute names to read.
2325
"""
2326
print 'ElectricalEnergyReader', element
2327
# print ' attrsconfigs_cumulative',attrsconfigs_cumulative
2328
# print ' attrsconfigs_average',attrsconfigs_average
2329
IntervalAvReader2.__init__(self, element, sumo, attrsconfigs_cumulative, attrsconfigs_average)
2330
self.time_lastint = -1.0
2331
2332
self.times = []
2333
self.energies = []
2334
self._energy_step = 0.0 # energy os all vehicles during last step
2335
self._consumptionsname = "consumptions"
2336
2337
def startElement(self, name, attrs):
2338
# print 'startElement',name,name == self._element,'time_lastint', self.time_lastint,'is_inter_valid',self.is_inter_valid,'e=',self._energy_step
2339
2340
if name == 'timestep':
2341
if self.time_lastint < 0:
2342
# print ' set time_lastint to ',float(attrs['time'])
2343
self.time_lastint = float(attrs['time'])
2344
self.is_inter_valid = False
2345
else:
2346
2347
time_inter_begin = self.time_lastint
2348
# print 79*'-'
2349
# print ' time_inter_begin',time_inter_begin,'is_valid',time_inter_begin >= self._sumo.time_warmup
2350
if time_inter_begin >= self._sumo.time_warmup:
2351
self.is_inter_valid = True
2352
time_inter_end = float(attrs['time'])
2353
self.times.append(time_inter_end)
2354
self.energies.append(self._energy_step)
2355
self._energy_step = 0.0
2356
2357
self._time_inter = int(time_inter_end)-int(time_inter_begin)
2358
# here we just take the start and end time ofthe whole
2359
# measurement period
2360
if self._time_begin is None: # take very first time only
2361
self._time_begin = int(time_inter_begin)
2362
self._time_end = int(time_inter_end)
2363
self.n_inter += 1
2364
else:
2365
self.is_inter_valid = False
2366
2367
if name == self._element:
2368
if not self.is_inter_valid:
2369
return # no interval initialized
2370
2371
id_elem = self.get_id_elem(attrs)
2372
# print ' ---id_veh_sumo',id_elem
2373
if id_elem == -1:
2374
return # id did not fit requested trip type
2375
2376
if id_elem not in self._ids:
2377
self._ids.append(id_elem)
2378
2379
for attrsconfig in self._attrsconfigs_cumulative:
2380
xmltag = attrsconfig.xmltag
2381
attrname = attrsconfig.attrname
2382
# print ' attrname (cum)',attrname,xmltag,attrs.has_key(xmltag)
2383
if attrs.has_key(xmltag):
2384
2385
a = attrs[xmltag]
2386
2387
if a.strip() != '':
2388
a = float(a)
2389
if self._values[attrname].has_key(id_elem):
2390
self._values[attrname][id_elem] += a
2391
# print ' added val',xmltag,attrname,self._values[attrname][id_elem],'val',float(a)
2392
else:
2393
self._values[attrname][id_elem] = a
2394
# print ' set val',xmltag,attrname,self._values[attrname][id_elem],'val',float(a)
2395
2396
if attrname == self._consumptionsname:
2397
self._energy_step += a
2398
2399
for attrsconfig in self._attrsconfigs_average:
2400
xmltag = attrsconfig.xmltag
2401
attrname = attrsconfig.attrname
2402
# print ' attrname (av)',attrname,xmltag,attrs.has_key(xmltag)
2403
if attrs.has_key(xmltag):
2404
2405
a = attrs[xmltag]
2406
if a.strip() != '':
2407
a = float(a)
2408
if self._values[attrname].has_key(id_elem):
2409
valcum, n = self._values[attrname][id_elem]
2410
# print ' add val', float(a),'to',valcum
2411
valcum += a
2412
n += 1
2413
else:
2414
valcum = a
2415
n = 1
2416
# print ' set val',valcum
2417
# print ' added cumval',xmltag,attrname,valcum,'val',float(a)
2418
self._values[attrname][id_elem] = (valcum, n)
2419
2420
def get_times(self):
2421
return np.array(self.times, dtype=np.float32)
2422
2423
def get_energies(self):
2424
return np.array(self.energies, dtype=np.float32)
2425
2426
2427
class TrajectoryReader(IntervalAvReader2):
2428
"""
2429
Read trajectories, angles and speeds from a FCD XLM file
2430
2431
"""
2432
2433
def __init__(self, element, sumo):
2434
"""
2435
element is "lane" or "edge" or "tripinfo"
2436
attrnames is a list of attribute names to read.
2437
"""
2438
print 'TrajectoryReader', element
2439
# print ' attrsconfigs_cumulative',attrsconfigs_cumulative
2440
# print ' attrsconfigs_average',attrsconfigs_average
2441
IntervalAvReader2.__init__(self, element, sumo, [], [])
2442
#self.time_lastint = -1.0
2443
self.n_inter = 0
2444
self.times = []
2445
self.trajectories = {}
2446
self.angles = {}
2447
self.speeds = {}
2448
2449
#self._attrnames = ()
2450
self._xname = "x"
2451
self._yname = "y"
2452
self._anglename = "angle"
2453
self._speedname = "speed"
2454
2455
def startElement(self, name, attrs):
2456
# print 'startElement',name,name == self._element,'is_inter',self.n_inter
2457
2458
# <vehicle id="<VEHICLE_ID>" x="<VEHICLE_POS_X>" y="<VEHICLE_POS_Y>" angle="<VEHICLE_ANGLE>" type="<VEHICLE_TYPE>" speed="<VEHICLE_SPEED>"/>
2459
if name == 'timestep':
2460
# if self.time_lastint < 0:
2461
# #print ' set time_lastint to ',float(attrs['time'])
2462
# self.time_lastint = float(attrs['time'])
2463
# self.is_inter_valid = False
2464
# else:
2465
2466
#time_inter_begin = self.time_lastint
2467
# print 79*'-'
2468
# print ' time_inter_begin',time_inter_begin,'is_valid',time_inter_begin >= self._sumo.time_warmup
2469
# if time_inter_begin >= self._sumo.time_warmup:
2470
#self.is_inter_valid = True
2471
time_inter_end = float(attrs['time'])
2472
self.times.append(time_inter_end)
2473
# self.energies.append(self._energy_step)
2474
#self._energy_step = 0.0
2475
2476
#self._time_inter = int(time_inter_end)-int(time_inter_begin)
2477
# here we just take the start and end time ofthe whole
2478
# measurement period
2479
# if self._time_begin is None:# take very first time only
2480
# self._time_begin = int(time_inter_begin)
2481
#self._time_end = int(time_inter_end)
2482
self.n_inter += 1
2483
# else:
2484
# self.is_inter_valid = False
2485
2486
if name == self._element:
2487
# if not self.is_inter_valid: return # no interval initialized
2488
2489
id_elem = self.get_id_elem(attrs) # id_sumo
2490
# print ' ---id_veh_sumo',id_elem
2491
if id_elem == -1:
2492
return # id did not fit requested trip type
2493
2494
if id_elem not in self._ids:
2495
self._ids.append(id_elem)
2496
2497
self.trajectories[id_elem] = (self.n_inter-1)*[(np.nan, np.nan)]
2498
self.angles[id_elem] = (self.n_inter-1)*[np.nan]
2499
self.speeds[id_elem] = (self.n_inter-1)*[np.nan]
2500
2501
self.trajectories[id_elem].append([float(attrs[self._xname].strip()), float(attrs[self._yname].strip())])
2502
self.angles[id_elem].append(float(attrs[self._anglename].strip()))
2503
self.speeds[id_elem].append(float(attrs[self._speedname].strip()))
2504
# print ' trajectories',[float(attrs[self._xname].strip()),float(attrs[self._yname].strip())]
2505
# print ' id_sumo_veh',id_elem,'n_inter',self.n_inter,'len(angles)',len(self.angles[id_elem]),'len(traj)',len(self.trajectories[id_elem])
2506
2507
def endElement(self, name):
2508
if name == 'timestep':
2509
# print 'endElement',self.times[-1],len(self.times)
2510
for id_sumo_veh in self._ids:
2511
# print ' id_sumo_veh',id_sumo_veh,'n_inter',self.n_inter,'len(angles)',len(self.angles[id_sumo_veh]),'len(traj)',len(self.trajectories[id_sumo_veh])
2512
if len(self.trajectories[id_sumo_veh]) < self.n_inter:
2513
self.trajectories[id_sumo_veh].append((np.nan, np.nan))
2514
if len(self.angles[id_sumo_veh]) < self.n_inter:
2515
self.angles[id_sumo_veh].append(np.nan)
2516
if len(self.speeds[id_sumo_veh]) < self.n_inter:
2517
self.speeds[id_sumo_veh].append(np.nan)
2518
2519
2520
def read_trajectories(filepath, sumo, element):
2521
print 'read_trajectories', element
2522
2523
reader = TrajectoryReader(element, sumo)
2524
parse(filepath, reader)
2525
ids_sumo = reader.get_ids()
2526
times = np.array(reader.times, dtype=np.float32)
2527
n_veh = len(ids_sumo)
2528
trajectories = np.ones(n_veh, dtype=np.object)
2529
angles = np.ones(n_veh, dtype=np.object)
2530
speeds = np.ones(n_veh, dtype=np.object)
2531
2532
for i, id_sumo in zip(xrange(n_veh), ids_sumo):
2533
trajectories[i] = reader.trajectories[id_sumo]
2534
angles[i] = reader.angles[id_sumo]
2535
speeds[i] = reader.speeds[id_sumo]
2536
2537
return ids_sumo, times, trajectories, angles, speeds
2538
2539
2540
def read_interval2(filepath, sumo, element, attrsconfigs):
2541
# print 'read_interval2'
2542
attrsconfigs_cumulative = []
2543
attrsconfigs_average = []
2544
for attrsconfig in attrsconfigs:
2545
# print ' check',attrsconfig.attrname
2546
if hasattr(attrsconfig, 'is_average'):
2547
if attrsconfig.is_average:
2548
attrsconfigs_average.append(attrsconfig)
2549
else:
2550
attrsconfigs_cumulative.append(attrsconfig)
2551
else:
2552
attrsconfigs_cumulative.append(attrsconfig)
2553
2554
reader = IntervalAvReader2(element, sumo, attrsconfigs_cumulative, attrsconfigs_average)
2555
#parser = make_parser()
2556
# parser.setContentHandler(reader)
2557
#fn = '"'+filepath+'"'
2558
# print 'read_interval >'+fn+'<'
2559
# print ' >'+filepath+'<'
2560
# parser.parse(filepath)
2561
parse(filepath, reader)
2562
return reader.get_ids(), reader.get_data(), reader.get_interval()
2563
2564
2565
def read_tripresult(filepath, sumo, trips, element, attrsconfigs):
2566
print 'read_tripresult', filepath, trips.ident, 'element', element
2567
attrsconfigs_cumulative = []
2568
attrsconfigs_average = []
2569
for attrsconfig in attrsconfigs:
2570
# print ' check',attrsconfig.attrname
2571
if hasattr(attrsconfig, 'is_average'):
2572
if attrsconfig.is_average:
2573
attrsconfigs_average.append(attrsconfig)
2574
else:
2575
attrsconfigs_cumulative.append(attrsconfig)
2576
else:
2577
attrsconfigs_cumulative.append(attrsconfig)
2578
2579
reader = TripresultReader(trips, element, sumo, attrsconfigs_cumulative, attrsconfigs_average)
2580
#parser = make_parser()
2581
# parser.setContentHandler(reader)
2582
#fn = '"'+filepath+'"'
2583
# print 'read_interval >'+fn+'<'
2584
# print ' start parse >'+filepath+'<'
2585
# parser.parse(filepath)
2586
parse(filepath, reader)
2587
# print ' end',len(reader._ids)
2588
return reader.get_ids(), reader.get_data()
2589
2590
2591
def read_routeresult(filepath, sumo, trips, element, attrsconfigs):
2592
# print 'read_tripresult',filepath,trips.ident
2593
attrsconfigs_cumulative = []
2594
attrsconfigs_average = []
2595
for attrsconfig in attrsconfigs:
2596
# print ' check',attrsconfig.attrname
2597
if hasattr(attrsconfig, 'is_average'):
2598
if attrsconfig.is_average:
2599
attrsconfigs_average.append(attrsconfig)
2600
else:
2601
attrsconfigs_cumulative.append(attrsconfig)
2602
else:
2603
attrsconfigs_cumulative.append(attrsconfig)
2604
2605
counter = RouteCounter()
2606
parse(filepath, counter)
2607
reader = RouteReader(trips, counter) # parser = make_parser()
2608
# parser.setContentHandler(reader)
2609
#fn = '"'+filepath+'"'
2610
# print 'read_interval >'+fn+'<'
2611
# print ' start parse >'+filepath+'<'
2612
# parser.parse(filepath)
2613
parse(filepath, reader)
2614
# print ' end',len(reader._ids)
2615
return reader._get_kwargs()
2616
2617