Small changes to several things
[progcomp2012.git] / progcomp / judge / simulator / simulate.py
index 4429e4a..9b79194 100755 (executable)
@@ -65,10 +65,16 @@ if os.path.exists(managerPath) == False:
 
 if os.path.exists(resultsDirectory) == False:
        os.mkdir(resultsDirectory) #Make the results directory if it didn't exist
+''' 
+       Obselete older version doesn't work with new .html files
 #Identify the round number by reading the results directory
 totalRounds = len(os.listdir(resultsDirectory)) + 1
 if totalRounds > 1:
        totalRounds -= 1
+'''
+
+totalRounds = 1
+#TODO: Fix this bit!
 
 if os.path.exists(logDirectory) == False:
        os.mkdir(logDirectory) #Make the log directory if it didn't exist
@@ -179,7 +185,7 @@ for roundNumber in range(totalRounds, totalRounds + nRounds):
                os.mkdir(logDirectory + "round"+str(roundNumber)) #Check there is a directory for this round's logs
 
        for agent in agents:
-               agent.update({"name":agent["name"], "path":agent["path"],  "score":[0], "VICTORY":[], "DEFEAT":[], "DRAW":[], "ILLEGAL":[], "DEFAULT":[], "INTERNAL_ERROR":[], "SURRENDER":[], "DRAW_DEFAULT":[], "BOTH_ILLEGAL":[], "BAD_SETUP":[], "ALL":[], "totalScore":0, "Wins":0, "Losses":0, "Draws":0, "Illegal":0, "Errors":0})
+               agent.update({"name":agent["name"], "path":agent["path"],  "score":[0], "VICTORY":[], "DEFEAT":[], "DRAW":[], "ILLEGAL":[], "DEFAULT":[], "INTERNAL_ERROR":[], "SURRENDER":[], "DRAW_DEFAULT":[], "BOTH_ILLEGAL":[], "BAD_SETUP":[], "ALL":[]})
 
        
        print "Commencing ROUND " + str(roundNumber) + " combat!"
@@ -343,7 +349,20 @@ for roundNumber in range(totalRounds, totalRounds + nRounds):
                agentFile.write("</table>\n")
                agentFile.close()       
 
-               
+       #Update round file
+       roundFile = open(htmlDir + "round"+str(roundNumber)+".html", "w")
+       roundFile.write("<html>\n<head>\n <title> Round " +str(roundNumber)+ " Overview </title>\n</head>\n<body>\n")
+       roundFile.write("<h1> Round " +str(roundNumber)+ " Overview </h1>\n")
+       roundFile.write("<table border=\"0\" cellpadding=\"10\">\n")
+       roundFile.write("<tr> <th> Name </th> <th> Score </th> <th> Total Score </th> </tr>\n")
+       agents.sort(key = lambda e : e["score"][0], reverse=True)
+       for agent in agents:
+               roundFile.write("<tr> <td> <a href="+agent["name"]+".html>"+agent["name"] + " </a> </td> <td> " + str(agent["score"][0]) + " </td> <td> " + str(agent["totalScore"]) + " </td> </tr>\n")
+       roundFile.write("</table>\n</body>\n<!-- Results file for Round " + str(roundNumber) + " autogenerated by \"" + sys.argv[0] + "\" at time " + str(time()) + " -->\n</html>\n\n")
+       roundFile.close()
+
+
+       
        
 
 if verbose:
@@ -356,6 +375,20 @@ for agent in agents:
        agentFile.write("</body>\n<!-- Results file for \"" + agent["name"] + "\" autogenerated by \"" + sys.argv[0] + "\" at time " + str(time()) + " -->\n</html>\n\n")
        agentFile.close()
 
+       if os.path.exists(htmlDir + "total.html") == True:
+               os.remove(htmlDir + "total.html") #Delete the file
+
+totalFile = open(htmlDir + "total.html", "w")
+totalFile.write("<html>\n<head>\n <title> Total Overview </title>\n</head>\n<body>\n")
+totalFile.write("<h1> Total Overview </h1>\n")
+totalFile.write("<table border=\"0\" cellpadding=\"10\">\n")
+totalFile.write("<tr> <th> Name </th> <th> Total Score </th> </tr>\n")
+agents.sort(key = lambda e : e["totalScore"], reverse=True)
+for agent in agents:
+       totalFile.write("<tr> <td> <a href="+agent["name"]+".html>"+agent["name"] + " </a> </td> <td> " + str(agent["totalScore"]) + " </td> </tr>\n")
+totalFile.write("</table>\n</body>\n<!-- Total Results file autogenerated by \"" + sys.argv[0] + "\" at time " + str(time()) + " -->\n</html>\n\n")
+totalFile.close()
+
        
 if verbose:
        print "Done!"

UCC git Repository :: git.ucc.asn.au