Index: branches/LCSv2/controllers/default.py.bak
===================================================================
--- branches/LCSv2/controllers/default.py.bak	(revision 634)
+++ branches/LCSv2/controllers/default.py.bak	(revision 641)
@@ -2,14 +2,19 @@
 # Constants
 kLogfile = "samplelogfile.txt"
-kSimtimefile = "sim_elapsedtime.json"
+kSimtimefile = "sim_elapsedtime.json"  #"../webapps/dynamicdata/sim_elapsed_time.json"
 hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605']
 hwyDirections = ['','NB', 'SB', 'NB/SB','EB','WB','EB/WB']
 # Names to appear in the username dropdown box
 users = []
+users.append('')
 # Show the login page
 def index():
     userfile = open('student_names.txt','r')
-    users = [line.strip() for line in userfile.readlines()]
-    users.insert(0,'')
+    # read the file into a buffer
+    buffer = [line.strip() for line in userfile.readlines()]
+    # Append each name in the buffer to the users list, skipping blank lines
+    for item in buffer:
+        if len(item) > 0:
+            users.append(item)
     form = FORM(LABEL('User:',_for='username', _class="label username-label"),
                 #INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(),
@@ -18,5 +23,5 @@
     if form.process().accepted:
         # Put the username entry into the session variable
-        session.username = form.vars.username
+        session.username = reverseNameFields(form.vars.username)
         redirect(URL('home'))
     return dict(form=form)
@@ -192,5 +197,5 @@
             db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%H%M")})
             # Log the update to external file
-            logmessage = getSimTime() + " LCS status update: " + session.statustype[4:] + ", " + session.statustype[0:4] + ", " + session.statuser + " " + "\n"
+            logmessage = getSimTime() + ", LCS status update: " + session.username + ", " + session.statustype[4:] + ", " + session.statustype[0:4] + ", " + session.statuser + " " + "\n"
             text_file = open(kLogfile, "a")
             text_file.write(logmessage)
@@ -216,5 +221,5 @@
         currentSimTime = jsontime["elapsedtime"]
         timestamp = str(datetime.timedelta(seconds = int(currentSimTime)))
-        return timestamp
+        return '0'+timestamp  # assume simtime is < 10 and prefix a zero
     except:
         # Fallback if missing file, use current time 
@@ -317,5 +322,5 @@
         session.flash = 'New lane closure added: ' + newID + ' ' + newLognum + ': ' + selectedlanes
         # Log the new closure to external file. Username, closureID, route, dir, type of closure, type of work
-        logmessage = getSimTime() + " LCS new closure: " + session.username + newID + '.' + newLognum + ', ' + form.vars.route + form.vars.direction + ', ' + form.vars.closuretype + ', ' + form.vars.worktype + "\n"
+        logmessage = getSimTime() + ", LCS new closure: " + session.username + ", " + newID + '.' + newLognum + ', ' + form.vars.route + form.vars.direction + ', ' + form.vars.closuretype + ', ' + form.vars.worktype + "\n"
         text_file = open(kLogfile, "a")
         text_file.write(logmessage)
@@ -376,4 +381,14 @@
         return "NO"
 
+# Swap the fields in a name, changing lastname first to firstname first.
+def reverseNameFields(formattedname):
+    # Divide the name into last and first names
+    x = formattedname.split(',')
+    # If there isn't a comma, return the entire name
+    if len(x) == 1:
+        return x[0].strip()
+    else:  # return the swapped fields
+        return x[1].strip() + ' ' + x[0]
+
 # Convert the lanes closed checkboxes into a human readable string
 # E.g.  #1 #3 of 4
