Changeset 641 in tmcsimulator for branches/LCSv2/controllers


Ignore:
Timestamp:
03/13/2021 05:17:45 PM (5 years ago)
Author:
jdalbey
Message:

LCSv2.default.py modified for #254. Changed studentnames file reading.

Location:
branches/LCSv2/controllers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/LCSv2/controllers/default.py

    r636 r641  
    11# added comments for testing 
    22# Constants 
    3 kLogfile = "samplelogfile.txt" 
     3kLogfile = "LCSlogfile.txt" 
    44kSimtimefile = "sim_elapsedtime.json"  #"../webapps/dynamicdata/sim_elapsed_time.json" 
    55hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605'] 
     
    77# Names to appear in the username dropdown box 
    88users = [] 
     9users.append('') 
    910# Show the login page 
    1011def index(): 
    1112    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 
    1420    form = FORM(LABEL('User:',_for='username', _class="label username-label"), 
    1521                #INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(), 
     
    1824    if form.process().accepted: 
    1925        # Put the username entry into the session variable 
    20         session.username = form.vars.username 
     26        session.username = reverseNameFields(form.vars.username) 
    2127        redirect(URL('home')) 
    2228    return dict(form=form) 
     
    376382        return "NO" 
    377383 
     384# Swap the fields in a name, changing lastname first to firstname first. 
     385def 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 
    378394# Convert the lanes closed checkboxes into a human readable string 
    379395# E.g.  #1 #3 of 4 
  • branches/LCSv2/controllers/default.py.bak

    r634 r641  
    22# Constants 
    33kLogfile = "samplelogfile.txt" 
    4 kSimtimefile = "sim_elapsedtime.json" 
     4kSimtimefile = "sim_elapsedtime.json"  #"../webapps/dynamicdata/sim_elapsed_time.json" 
    55hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605'] 
    66hwyDirections = ['','NB', 'SB', 'NB/SB','EB','WB','EB/WB'] 
    77# Names to appear in the username dropdown box 
    88users = [] 
     9users.append('') 
    910# Show the login page 
    1011def index(): 
    1112    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) 
    1419    form = FORM(LABEL('User:',_for='username', _class="label username-label"), 
    1520                #INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(), 
     
    1823    if form.process().accepted: 
    1924        # Put the username entry into the session variable 
    20         session.username = form.vars.username 
     25        session.username = reverseNameFields(form.vars.username) 
    2126        redirect(URL('home')) 
    2227    return dict(form=form) 
     
    192197            db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%H%M")}) 
    193198            # 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" 
    195200            text_file = open(kLogfile, "a") 
    196201            text_file.write(logmessage) 
     
    216221        currentSimTime = jsontime["elapsedtime"] 
    217222        timestamp = str(datetime.timedelta(seconds = int(currentSimTime))) 
    218         return timestamp 
     223        return '0'+timestamp  # assume simtime is < 10 and prefix a zero 
    219224    except: 
    220225        # Fallback if missing file, use current time  
     
    317322        session.flash = 'New lane closure added: ' + newID + ' ' + newLognum + ': ' + selectedlanes 
    318323        # 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" 
    320325        text_file = open(kLogfile, "a") 
    321326        text_file.write(logmessage) 
     
    376381        return "NO" 
    377382 
     383# Swap the fields in a name, changing lastname first to firstname first. 
     384def 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 
    378393# Convert the lanes closed checkboxes into a human readable string 
    379394# E.g.  #1 #3 of 4 
Note: See TracChangeset for help on using the changeset viewer.