44import os
55
66
7+ MODE_TYPES = {
8+ "1" : "AUTO" ,
9+ "2" : "TRANSIT" ,
10+ "3" : "AUX_TRANSIT" ,
11+ "4" : "AUX_AUTO" ,
12+ }
13+
14+
715class MockProject :
816 """Mock-up version of `EmmeProject`.
917
@@ -87,7 +95,13 @@ def mode_transaction(self, transaction_file, revert_on_error=True,
8795 if f .readline () == "t modes\n " :
8896 break
8997 while True :
90- rec = f .readline ().split ()
98+ rec = f .readline ().split ("'" )
99+ if len (rec ) == 3 :
100+ rec = rec [0 ].split () + [rec [1 ]] + rec [2 ].split ()
101+ elif len (rec ) <= 1 :
102+ rec = rec [0 ].split ()
103+ else :
104+ raise SyntaxError ("Extra single quotes (') found in mode table" )
91105 if not rec :
92106 break
93107 if rec [0 ] == "c" :
@@ -97,11 +111,13 @@ def mode_transaction(self, transaction_file, revert_on_error=True,
97111 pass
98112 else :
99113 if rec [0 ] == "a" :
100- network .create_mode (mode_type = rec [3 ], idx = rec [1 ])
114+ mode = network .create_mode (
115+ mode_type = MODE_TYPES [rec [3 ]], idx = rec [1 ])
101116 elif rec [0 ] == "m" :
102- network .mode (idx = rec [1 ])
117+ mode = network .mode (idx = rec [1 ])
103118 else :
104119 raise SyntaxError ("Unknown update code" )
120+ mode .description = rec [2 ]
105121
106122 def base_network_transaction (self , transaction_file , revert_on_error = True ,
107123 scenario = None ):
@@ -490,7 +506,7 @@ def modes(self):
490506 def create_mode (self , mode_type , idx ):
491507 if not isinstance (idx , str ) or len (idx ) != 1 :
492508 raise Exception ("Invalid mode ID: " + idx )
493- mode = Mode (idx )
509+ mode = Mode (idx , mode_type )
494510 self ._modes [idx ] = mode
495511 return mode
496512
@@ -569,8 +585,10 @@ def create_transit_line(self, idx, transit_vehicle_id, itinerary):
569585
570586
571587class Mode :
572- def __init__ (self , idx ):
588+ def __init__ (self , idx , mode_type ):
573589 self .id = idx
590+ self .type = mode_type
591+ self .description = ""
574592
575593 def __str__ (self ):
576594 return self .id
0 commit comments