Browse Source

filter.py and compare options

adaptedStrategy0
kaos 9 years ago
parent
commit
df10af9361
3 changed files with 83 additions and 3 deletions
  1. +1
    -2
      calculateAndSubmit
  2. +81
    -0
      filterResults.py
  3. +1
    -1
      icfp2015.cabal

+ 1
- 2
calculateAndSubmit View File

@ -3,12 +3,11 @@ if [ $# -lt 1 ]; then
echo "missing json filename"
exit 1
fi
OUTPUT=`vm/Main0 -f $1`
OUTPUT=`dist/build/icfp2015/icfp2015 -f $1|./filterResults.py`
if [ $? -eq 0 ]; then
read -p "Are you sure? [y/n]" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "submitting solution"
response=`curl --user :2aaFCkjNIDHAsAIh9iQHc+Y+FGhkM5Z0RQgpO6TL6EA= -X POST -H "Content-Type: application/json" -d $OUTPUT https://davar.icfpcontest.org/teams/235/solutions`
if [ "$response" == "created" ]; then
echo "submitted"


+ 81
- 0
filterResults.py View File

@ -0,0 +1,81 @@
#!/usr/bin/env python
import json
import sys
import glob
from datetime import datetime
solutionsDir = "solutions/"
resultsScore = {}
with open('scores') as f:
for line in f:
tmp = line.strip().split(' ')
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)
f.close()
if len(sys.argv) < 2 or sys.argv[1] != "compare":
results = json.loads(''.join(sys.stdin.readlines()))
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.write(json.dumps(results[i]))
out_file.close()
else:
print "Bellandi dio merda, ne manca uno!!!"
sys.exit(1)
else:
results=[{'problemId':''}]
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(".")]
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)))
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()
print 666
if err == None:
serverResults = {}
results = json.loads(out)
for result in results:
#2015-08-08T12:26:42.894Z
date_object = datetime.strptime(result['createdAt'], '%Y-%m-%dT%H:%M:%S.%fZ')
print str(date_object)
key = str(result['problemId'])+"."+str(result['seed'])
if not key in serverResults or serverResults[key]['createdAt'] < result['createdAt']:
serverResults[key] = result
print serverResults
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"
else:
if solutionToSend['solution'] != serverResults[key]['solution']:
print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " solution differ: " + solutionToSend['solution'] + " != " + serverResults[key]['solution'] + " (server)"
elif scores[key] != serverResults[key]['score']:
print str(solutionToSend['problemId'])+" "+str(solutionToSend['seed']) + " score differ: " + scores[key] + " != " + serverResults[key]['score'] + " (server)"
print scores
print type(out)
print json.dumps(serverResults)
print len(serverResults)
else:
print "error retriving results from server"
sys.exit(1)
sys.exit(0)

+ 1
- 1
icfp2015.cabal View File

@ -60,7 +60,7 @@ executable icfp2015
other-extensions: OverloadedStrings, DeriveGeneric, DeriveDataTypeable
-- Other library packages from which modules are imported.
build-depends: base >=4.6 && <4.9, hashable >=1.2 && <1.3, containers >=0.5 && <0.6, QuickCheck >=2.7 && <2.9, bytestring >=0.10 && <0.11, aeson >=0.8 && <0.9, json >=0.9 && <0.10
build-depends: base >=4.6 && <4.9, hashable >=1.2 && <1.3, containers >=0.5 && <0.6, QuickCheck >=2.7 && <2.9, bytestring >=0.10 && <0.11, aeson >=0.7 && <0.9, json >=0.4 && <0.10
-- Directories containing source files.
hs-source-dirs: src


Loading…
Cancel
Save