|
|
@ -6,6 +6,19 @@ from datetime import datetime |
|
|
|
|
|
|
|
solutionsDir = "solutions/" |
|
|
|
|
|
|
|
class bcolors: |
|
|
|
HEADER = '\033[95m' |
|
|
|
OKBLUE = '\033[94m' |
|
|
|
OKGREEN = '\033[92m' |
|
|
|
WARNING = '\033[93m' |
|
|
|
FAIL = '\033[91m' |
|
|
|
ENDC = '\033[0m' |
|
|
|
BOLD = '\033[1m' |
|
|
|
UNDERLINE = '\033[4m' |
|
|
|
|
|
|
|
if len(sys.argv) < 2 or sys.argv[1] != "status": |
|
|
|
results = json.loads(''.join(sys.stdin.readlines())) |
|
|
|
|
|
|
|
resultsScore = {} |
|
|
|
with open('scores') as f: |
|
|
|
for line in f: |
|
|
@ -13,22 +26,20 @@ with open('scores') as f: |
|
|
|
key = tmp[0]+"."+tmp[1] |
|
|
|
if not key in resultsScore: |
|
|
|
resultsScore[key] = int(tmp[2]) |
|
|
|
else: |
|
|
|
print "Bellandi dio merda, mi hai messo un doppione!!!" |
|
|
|
sys.exit(1) |
|
|
|
#else: |
|
|
|
# print "Score alredy present for " + tmp[0] + " " + tmp[1] |
|
|
|
f.close() |
|
|
|
|
|
|
|
if len(sys.argv) < 2 or sys.argv[1] != "compare": |
|
|
|
results = json.loads(''.join(sys.stdin.readlines())) |
|
|
|
|
|
|
|
if len(sys.argv) < 2 or sys.argv[1] != "status": |
|
|
|
strategy = "unknown" if len(sys.argv) < 2 else sys.argv[1] |
|
|
|
for i in range(0, len(results)): |
|
|
|
key = str(results[i]['problemId']) + "." + str(results[i]['seed']) |
|
|
|
if key in resultsScore: |
|
|
|
out_file = open(solutionsDir+str(results[i]['problemId'])+"."+str(results[i]['seed'])+"."+"%.110d"%resultsScore[key],"w") |
|
|
|
out_file = open(solutionsDir+str(results[i]['problemId'])+"."+str(results[i]['seed'])+"."+"%.110d"%resultsScore[key]+"."+strategy,"w") |
|
|
|
out_file.write(json.dumps(results[i])) |
|
|
|
out_file.close() |
|
|
|
else: |
|
|
|
print "Bellandi dio merda, ne manca uno!!!" |
|
|
|
print "Missing score for " + str(results[i]['problemId']) + " " + str(results[i]['seed']) |
|
|
|
sys.exit(1) |
|
|
|
else: |
|
|
|
results=[{'problemId':''}] |
|
|
@ -37,21 +48,21 @@ solutionsToSend=[] |
|
|
|
scores = {} |
|
|
|
lastProblem = "" |
|
|
|
for solution in sorted(glob.glob(solutionsDir + str(results[0]['problemId']) + '*'), reverse=True): |
|
|
|
if lastProblem != solution[:solution.rfind(".")]: |
|
|
|
lastProblem = solution[:solution.rfind(".")] |
|
|
|
problemHash = solution[:solution.rfind(".", 0, solution.rfind(".")) if solution.count('.') == 3 else solution.rfind(".")] |
|
|
|
if lastProblem != problemHash: |
|
|
|
lastProblem = problemHash |
|
|
|
with open(solution) as json_data: |
|
|
|
partialSolution = json.load(json_data) |
|
|
|
json_data.close() |
|
|
|
solutionsToSend.append(partialSolution) |
|
|
|
scores[lastProblem.replace(solutionsDir, '')] = int(solution[solution.rfind(".") + 1:]) |
|
|
|
if len(sys.argv) < 2 or sys.argv[1] != "compare": |
|
|
|
print json.dumps(list(reversed(solutionsToSend))) |
|
|
|
scores[lastProblem.replace(solutionsDir, '')] = int(solution.split('.')[2]) |
|
|
|
if len(sys.argv) < 2 or sys.argv[1] != "status": |
|
|
|
print json.dumps(list(reversed(solutionsToSend))).replace(', ', ',').replace(': ', ':') |
|
|
|
else: |
|
|
|
import subprocess |
|
|
|
process = subprocess.Popen(['curl --user :2aaFCkjNIDHAsAIh9iQHc+Y+FGhkM5Z0RQgpO6TL6EA= -X GET https://davar.icfpcontest.org/teams/235/solutions'], shell = True, stdout=subprocess.PIPE) |
|
|
|
out, err = process.communicate() |
|
|
|
if err == None: |
|
|
|
print "Results:" |
|
|
|
serverResults = {} |
|
|
|
results = json.loads(out) |
|
|
|
for result in results: |
|
|
@ -61,18 +72,28 @@ else: |
|
|
|
key = str(result['problemId'])+"."+str(result['seed']) |
|
|
|
if not key in serverResults or serverResults[key]['createdAt'] < result['createdAt']: |
|
|
|
serverResults[key] = result |
|
|
|
# print serverResults |
|
|
|
#print results |
|
|
|
print "Submitted solution number: %d"%len(solutionsToSend) |
|
|
|
for solutionToSend in solutionsToSend: |
|
|
|
key = str(solutionToSend['problemId'])+"."+str(solutionToSend['seed']) |
|
|
|
if not key in serverResults: |
|
|
|
print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " not present on server" |
|
|
|
print bcolors.FAIL + str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " not present on server" + bcolors.ENDC |
|
|
|
else: |
|
|
|
if solutionToSend['solution'] != serverResults[key]['solution']: |
|
|
|
print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " solution differ: " + solutionToSend['solution'] + " != " + serverResults[key]['solution'] + " (server)" |
|
|
|
print bcolors.FAIL + str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " solution differ: " + solutionToSend['solution'] + " != " + serverResults[key]['solution'] + " (server)" + bcolors.ENDC |
|
|
|
print serverResults[key]['createdAt'] |
|
|
|
elif serverResults[key]['score'] == None: |
|
|
|
print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " solution evaluation pending" |
|
|
|
found = False |
|
|
|
for i in range(1, len(results) + 1): |
|
|
|
result = results[len(results)- i] |
|
|
|
if result['problemId'] == solutionToSend['problemId'] and result['seed'] == solutionToSend['seed'] and result['solution'] == solutionToSend['solution'] and scores[key] == result['score']: |
|
|
|
found = True |
|
|
|
print bcolors.WARNING + str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " " + bcolors.OKGREEN + "score " + result['score'] + " ok" + bcolors.ENDC + bcolors.WARNING + ", but solution evaluation pending" + bcolors.ENDC |
|
|
|
break |
|
|
|
if not found: |
|
|
|
print bcolors.WARNING + str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " solution evaluation pending" + bcolors.ENDC |
|
|
|
elif scores[key] != serverResults[key]['score']: |
|
|
|
print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " score differ: " + str(scores[key]) + " != " + str(serverResults[key]['score']) + " (server)" |
|
|
|
print bcolors.FAIL + str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " score differ: " + str(scores[key]) + " != " + str(serverResults[key]['score']) + " (server)" + bcolors.ENDC |
|
|
|
# print scores |
|
|
|
# print type(out) |
|
|
|
# print json.dumps(serverResults) |
|
|
|