Changeset 641 in tmcsimulator for branches/LCSv2/controllers
- Timestamp:
- 03/13/2021 05:17:45 PM (5 years ago)
- Location:
- branches/LCSv2/controllers
- Files:
-
- 2 edited
-
default.py (modified) (4 diffs)
-
default.py.bak (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/LCSv2/controllers/default.py
r636 r641 1 1 # added comments for testing 2 2 # Constants 3 kLogfile = " samplelogfile.txt"3 kLogfile = "LCSlogfile.txt" 4 4 kSimtimefile = "sim_elapsedtime.json" #"../webapps/dynamicdata/sim_elapsed_time.json" 5 5 hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605'] … … 7 7 # Names to appear in the username dropdown box 8 8 users = [] 9 users.append('') 9 10 # Show the login page 10 11 def index(): 11 12 userfile = open('student_names.txt','r') 12 users = [line.strip() for line in userfile.readlines()] 13 users.insert(0,'') 13 # read the file into a buffer 14 buffer = [line.strip() for line in userfile.readlines()] 15 # Append each name in the buffer to the users list, skipping blank lines 16 for item in buffer: 17 if len(item) > 0: 18 users.append(item) 19 # build the form 14 20 form = FORM(LABEL('User:',_for='username', _class="label username-label"), 15 21 #INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(), … … 18 24 if form.process().accepted: 19 25 # Put the username entry into the session variable 20 session.username = form.vars.username26 session.username = reverseNameFields(form.vars.username) 21 27 redirect(URL('home')) 22 28 return dict(form=form) … … 376 382 return "NO" 377 383 384 # Swap the fields in a name, changing lastname first to firstname first. 385 def reverseNameFields(formattedname): 386 # Divide the name into last and first names 387 x = formattedname.split(',') 388 # If there isn't a comma, return the entire name 389 if len(x) == 1: 390 return x[0].strip() 391 else: # return the swapped fields 392 return x[1].strip() + ' ' + x[0] 393 378 394 # Convert the lanes closed checkboxes into a human readable string 379 395 # E.g. #1 #3 of 4 -
branches/LCSv2/controllers/default.py.bak
r634 r641 2 2 # Constants 3 3 kLogfile = "samplelogfile.txt" 4 kSimtimefile = "sim_elapsedtime.json" 4 kSimtimefile = "sim_elapsedtime.json" #"../webapps/dynamicdata/sim_elapsed_time.json" 5 5 hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605'] 6 6 hwyDirections = ['','NB', 'SB', 'NB/SB','EB','WB','EB/WB'] 7 7 # Names to appear in the username dropdown box 8 8 users = [] 9 users.append('') 9 10 # Show the login page 10 11 def index(): 11 12 userfile = open('student_names.txt','r') 12 users = [line.strip() for line in userfile.readlines()] 13 users.insert(0,'') 13 # read the file into a buffer 14 buffer = [line.strip() for line in userfile.readlines()] 15 # Append each name in the buffer to the users list, skipping blank lines 16 for item in buffer: 17 if len(item) > 0: 18 users.append(item) 14 19 form = FORM(LABEL('User:',_for='username', _class="label username-label"), 15 20 #INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(), … … 18 23 if form.process().accepted: 19 24 # Put the username entry into the session variable 20 session.username = form.vars.username25 session.username = reverseNameFields(form.vars.username) 21 26 redirect(URL('home')) 22 27 return dict(form=form) … … 192 197 db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%H%M")}) 193 198 # Log the update to external file 194 logmessage = getSimTime() + " LCS status update:" + session.statustype[4:] + ", " + session.statustype[0:4] + ", " + session.statuser + " " + "\n"199 logmessage = getSimTime() + ", LCS status update: " + session.username + ", " + session.statustype[4:] + ", " + session.statustype[0:4] + ", " + session.statuser + " " + "\n" 195 200 text_file = open(kLogfile, "a") 196 201 text_file.write(logmessage) … … 216 221 currentSimTime = jsontime["elapsedtime"] 217 222 timestamp = str(datetime.timedelta(seconds = int(currentSimTime))) 218 return timestamp223 return '0'+timestamp # assume simtime is < 10 and prefix a zero 219 224 except: 220 225 # Fallback if missing file, use current time … … 317 322 session.flash = 'New lane closure added: ' + newID + ' ' + newLognum + ': ' + selectedlanes 318 323 # Log the new closure to external file. Username, closureID, route, dir, type of closure, type of work 319 logmessage = getSimTime() + " LCS new closure: " + session.username+ newID + '.' + newLognum + ', ' + form.vars.route + form.vars.direction + ', ' + form.vars.closuretype + ', ' + form.vars.worktype + "\n"324 logmessage = getSimTime() + ", LCS new closure: " + session.username + ", " + newID + '.' + newLognum + ', ' + form.vars.route + form.vars.direction + ', ' + form.vars.closuretype + ', ' + form.vars.worktype + "\n" 320 325 text_file = open(kLogfile, "a") 321 326 text_file.write(logmessage) … … 376 381 return "NO" 377 382 383 # Swap the fields in a name, changing lastname first to firstname first. 384 def reverseNameFields(formattedname): 385 # Divide the name into last and first names 386 x = formattedname.split(',') 387 # If there isn't a comma, return the entire name 388 if len(x) == 1: 389 return x[0].strip() 390 else: # return the swapped fields 391 return x[1].strip() + ' ' + x[0] 392 378 393 # Convert the lanes closed checkboxes into a human readable string 379 394 # E.g. #1 #3 of 4
Note: See TracChangeset
for help on using the changeset viewer.
