You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.0 KiB

  1. #!/usr/bin/env python
  2. import json
  3. import sys
  4. import glob
  5. from datetime import datetime
  6. solutionsDir = "solutions/"
  7. resultsScore = {}
  8. with open('scores') as f:
  9. for line in f:
  10. tmp = line.strip().split(' ')
  11. key = tmp[0]+"."+tmp[1]
  12. if not key in resultsScore:
  13. resultsScore[key] = int(tmp[2])
  14. else:
  15. print "Bellandi dio merda, mi hai messo un doppione!!!"
  16. sys.exit(1)
  17. f.close()
  18. if len(sys.argv) < 2 or sys.argv[1] != "compare":
  19. results = json.loads(''.join(sys.stdin.readlines()))
  20. for i in range(0, len(results)):
  21. key = str(results[i]['problemId']) + "." + str(results[i]['seed'])
  22. if key in resultsScore:
  23. out_file = open(solutionsDir+str(results[i]['problemId'])+"."+str(results[i]['seed'])+"."+"%.110d"%resultsScore[key],"w")
  24. out_file.write(json.dumps(results[i]))
  25. out_file.close()
  26. else:
  27. print "Bellandi dio merda, ne manca uno!!!"
  28. sys.exit(1)
  29. else:
  30. results=[{'problemId':''}]
  31. solutionsToSend=[]
  32. scores = {}
  33. lastProblem = ""
  34. for solution in sorted(glob.glob(solutionsDir + str(results[0]['problemId']) + '*'), reverse=True):
  35. if lastProblem != solution[:solution.rfind(".")]:
  36. lastProblem = solution[:solution.rfind(".")]
  37. with open(solution) as json_data:
  38. partialSolution = json.load(json_data)
  39. json_data.close()
  40. solutionsToSend.append(partialSolution)
  41. scores[lastProblem.replace(solutionsDir, '')] = int(solution[solution.rfind(".") + 1:])
  42. if len(sys.argv) < 2 or sys.argv[1] != "compare":
  43. print json.dumps(list(reversed(solutionsToSend)))
  44. else:
  45. import subprocess
  46. process = subprocess.Popen(['curl --user :2aaFCkjNIDHAsAIh9iQHc+Y+FGhkM5Z0RQgpO6TL6EA= -X GET https://davar.icfpcontest.org/teams/235/solutions'], shell = True, stdout=subprocess.PIPE)
  47. out, err = process.communicate()
  48. print 666
  49. if err == None:
  50. serverResults = {}
  51. results = json.loads(out)
  52. for result in results:
  53. #2015-08-08T12:26:42.894Z
  54. date_object = datetime.strptime(result['createdAt'], '%Y-%m-%dT%H:%M:%S.%fZ')
  55. print str(date_object)
  56. key = str(result['problemId'])+"."+str(result['seed'])
  57. if not key in serverResults or serverResults[key]['createdAt'] < result['createdAt']:
  58. serverResults[key] = result
  59. print serverResults
  60. for solutionToSend in solutionsToSend:
  61. key = str(solutionToSend['problemId'])+"."+str(solutionToSend['seed'])
  62. if not key in serverResults:
  63. print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " not present on server"
  64. else:
  65. if solutionToSend['solution'] != serverResults[key]['solution']:
  66. print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " solution differ: " + solutionToSend['solution'] + " != " + serverResults[key]['solution'] + " (server)"
  67. elif scores[key] != serverResults[key]['score']:
  68. print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " score differ: " + scores[key] + " != " + serverResults[key]['score'] + " (server)"
  69. print scores
  70. print type(out)
  71. print json.dumps(serverResults)
  72. print len(serverResults)
  73. else:
  74. print "error retriving results from server"
  75. sys.exit(1)
  76. sys.exit(0)