X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=judge%2Fsimulator%2Fsimulate.py;h=217a80eda54fc1cf96cd6ceec565563076206a48;hp=634e4247a43c6b8c0c9ed8a446830e2b5fc24d1e;hb=5f9adddd695f2664a0d690b59a779e40b51ade3d;hpb=476617a8222c8c56404c12a65dd75c55b8019542 diff --git a/judge/simulator/simulate.py b/judge/simulator/simulate.py index 634e424..217a80e 100755 --- a/judge/simulator/simulate.py +++ b/judge/simulator/simulate.py @@ -10,6 +10,7 @@ Now (sortof) generates .html files to display results in a prettiful manner. + THIS FILE IS TERRIBLE author Sam Moore (matches) [SZM] website http://matches.ucc.asn.au/stratego @@ -152,6 +153,26 @@ if verbose: print "Preparing .html results files..." +if os.path.exists(resultsDirectory + "index.html") == True: + os.remove(resultsDirectory + "index.html") #Delete the file +totalFile = open(resultsDirectory + "index.html", "w") +totalFile.write("\n\n Round in progress... \n\n\n") +if nRounds > 1: + totalFile.write("

Rounds " + str(totalRounds) + " to " + str(totalRounds + nRounds-1) + " in progress...

\n") +else: + totalFile.write("

Round " + str(totalRounds) + " in progress...

\n") +totalFile.write("

Please wait for the rounds to finish. You can view the current progress by watching the Log Files

") +if totalRounds > 1: + totalFile.write("

Round Summaries

\n") + totalFile.write("\n") + for i in range(1, totalRounds): + totalFile.write("\n") + totalFile.write("
Round " + str(i) + "
\n") + +totalFile.write("\n\n\n\n") +totalFile.close() + + for agent in agents: if os.path.exists(resultsDirectory+agent["name"] + ".html") == False: agentFile = open(resultsDirectory+agent["name"] + ".html", "w") @@ -173,19 +194,24 @@ for agent in agents: while line != "": #if verbose: # print "Interpreting line \"" + line.strip() + "\"" - if line.strip() == "": + if line.strip() == "" or line.strip() == "": break - elif line == " Score Wins Losses Draws Illegal Errors \n": + elif line == "

Round Overview

\n": agentFile.write(line) line = oldFile.readline() - - values = line.split(' ') - agent["totalScore"] += int(values[2].strip()) - agent["Wins"] += int(values[5].strip()) - agent["Losses"] += int(values[8].strip()) - agent["Draws"] += int(values[11].strip()) - agent["Illegal"] += int(values[14].strip()) - agent["Errors"] += int(values[17].strip()) + agentFile.write(line) + line = oldFile.readline() + if line == " Score Wins Losses Draws Illegal Errors \n": + #sys.stdout.write("Adding scores... " + line + "\n") + agentFile.write(line) + line = oldFile.readline() + values = line.split(' ') + agent["totalScore"] += int(values[2].strip()) + agent["Wins"] += int(values[5].strip()) + agent["Losses"] += int(values[8].strip()) + agent["Draws"] += int(values[11].strip()) + agent["Illegal"] += int(values[14].strip()) + agent["Errors"] += int(values[17].strip()) agentFile.write(line) line = oldFile.readline() @@ -233,6 +259,7 @@ for roundNumber in range(totalRounds, totalRounds + nRounds): errorLog = [logDirectory + "error/" + red["name"] + "."+str(gameID), logDirectory + "error/" + blue["name"] + "."+str(gameID)] #Run the game, outputting to logFile; stderr of (both) AI programs is directed to logFile.stderr outline = os.popen(managerPath + " -o " + logFile + " -T " + str(timeoutValue) + " \"" + red["path"] + "\" \"" + blue["path"] + "\" 2>> " + logFile+".stderr", "r").read() + #os.system("mv tmp.mp4 " + logFile + ".mp4") #If there were no errors, get rid of the stderr file if os.stat(logFile+".stderr").st_size <= 0: @@ -274,6 +301,13 @@ for roundNumber in range(totalRounds, totalRounds + nRounds): otherColour["score"].insert(0, otherColour["score"][0] + scores[results[2]][1]) otherColour[scores[results[2]][2]].append((endColour["name"], gameID, scores[results[2]][1])) otherColour["ALL"].append((endColour["name"], gameID, scores[results[2]][1], scores[results[2]][2], otherStr)) + #Write scores to raw text files + for agent in [endColour, otherColour]: + scoreFile = open(resultsDirectory + agent["name"] + ".scores", "a") + scoreFile.write(str(agent["totalScore"] + agent["score"][0]) + "\n") + scoreFile.close() + + if verbose: @@ -345,6 +379,9 @@ for roundNumber in range(totalRounds, totalRounds + nRounds): agentFile.write("\n") + + + agentFile.close() #Update round file @@ -357,7 +394,31 @@ for roundNumber in range(totalRounds, totalRounds + nRounds): for agent in agents: roundFile.write(" "+agent["name"] + " " + str(agent["score"][0]) + " " + str(agent["totalScore"]) + " \n") roundFile.write("\n") - roundFile.write("

Current Scoreboard

\n") + + command = "cp scores.plt " + resultsDirectory + "scores.plt;" + os.system(command) + + scorePlot = open(resultsDirectory + "scores.plt", "a") + scorePlot.write("plot ") + for i in range(0, len(agents)): + if i > 0: + scorePlot.write(", ") + scorePlot.write("\""+agents[i]["name"]+".scores\" using ($0+1):1 with linespoints title \""+agents[i]["name"]+"\"") + + scorePlot.write("\nexit\n") + scorePlot.close() + + command = "d=$(pwd); cd " + resultsDirectory + ";" + command += "gnuplot scores.plt;" + command += "rm -f scores.plt;" + command += "mv scores.png round"+str(roundNumber)+".png;" + command += "cd $d;" + os.system(command) + + roundFile.write("

Accumulated Scores - up to Round " + str(roundNumber)+"

\n") + roundFile.write("\"round"+str(roundNumber)+".png\"\n") + + roundFile.write("

Current Scoreboard

\n") roundFile.write("\n\n\n\n") roundFile.close() @@ -369,16 +430,32 @@ if verbose: print "Finalising .html files... " for agent in agents: agentFile = open(resultsDirectory + agent["name"]+".html", "a") - - #Write the "total" statistics + agentFile.write("\n") + #Write a graph + #Comment out if you don't have gnuplot + + command = "rm -f " + agent["name"] + ".png;" + command += "cp template.plt " + resultsDirectory + agent["name"] + ".plt;" + command += "d=$(pwd); cd " + resultsDirectory + ";" + command += "sed -i \"s:\[NAME\]:"+agent["name"]+":g\" " +resultsDirectory + agent["name"]+".plt;" + command += "gnuplot " + resultsDirectory + agent["name"]+".plt;" + command += "rm -f " + resultsDirectory + agent["name"] + ".plt;" + command += "cd $d;" + os.system(command) + agentFile.write("\n") + agentFile.write("

Score Graph

\n") + agentFile.write("\""+agent["name"]+".png\"\n") + + #Link to main file + agentFile.write("

Total Statistics

\n") agentFile.write("\n\n\n\n") agentFile.close() - if os.path.exists(resultsDirectory + "total.html") == True: - os.remove(resultsDirectory + "total.html") #Delete the file +if os.path.exists(resultsDirectory + "index.html") == True: + os.remove(resultsDirectory + "index.html") #Delete the file -totalFile = open(resultsDirectory + "total.html", "w") +totalFile = open(resultsDirectory + "index.html", "w") totalFile.write("\n\n Total Overview \n\n\n") totalFile.write("

Total Overview

\n") totalFile.write("\n") @@ -388,6 +465,19 @@ for agent in agents: totalFile.write("\n") totalFile.write("
"+agent["name"] + " " + str(agent["totalScore"]) + "
\n") +totalFile.write("

Score Graph

\n") + + +command = "d=$(pwd);" +command += "cd " + resultsDirectory + ";" +command += "rm -f scores.png;" +command += "cp round"+str(roundNumber)+".png scores.png;" +command += "cd $d;" +os.system(command) + +totalFile.write("\"scores.png\"\n") + + totalFile.write("

Round Summaries

\n") totalFile.write("\n") for i in range(1, totalRounds+1): @@ -397,6 +487,11 @@ totalFile.write("
\n") totalFile.write("\n\n\n\n") totalFile.close() +#Write results to a raw text file as well +textResults = open(resultsDirectory + "total.txt", "w") +for agent in agents: + textResults.write(agent["name"] + " " + str(agent["totalScore"]) + "\n") +textResults.close() if verbose: print "Done!"