Skip to content

Commit 059ee5a

Browse files
committed
add support for artifacts/ folder and setup_artifacts.sh
1 parent aec9dd1 commit 059ee5a

File tree

6 files changed

+70
-20
lines changed

6 files changed

+70
-20
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ main.cfg
99
max.json
1010
runs
1111
best_runs
12+
artifacts

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Run a testinstance on the format `in/$testcase.in` with your own solver by:
2727
- `analyze.py` - easy access to the run folders and best run folder to analyze the output-file.
2828
- Bug in your scorer? Just remove `max.json` and rerun, now main.py will happliy overwrite the ans-files in the `submission` folder. If you accidentaly remove `max.json` you can recover your ans files form the `best_runs` folder or the `ans` folder.
2929
- `package.sh` create a zip folder with your solution
30-
- `cleanify.sh` removes `in/example_pizza.in`.
30+
- `setup.sh` removes `in/example_pizza.in` and creates a main.cfg.
3131
- Pass extra args to your solver with: `pypy3 main.py --solve_args N=10,M=Hello,X=-0.5` Filling the args-dict with `{"N" : "10", "M" : "Hello", "X" : "-0.5"}`.
3232

3333

all.sh

-6
This file was deleted.

cleanify.sh setup.sh

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ function rm_nice {
66
fi
77
}
88
rm_nice "in"/*pizza*
9-
rm_nice "max.json"
109
for f in "in"/* ; do
1110
if [ ${f: -4} == ".txt" ] ; then
1211
mv $f "${f%.txt}.in"

setup_artifacts.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
if ! test -d "artifacts" ; then
4+
echo "folder artifacts is not present create a link first"
5+
exit 1
6+
fi
7+
8+
initials=$1
9+
10+
echo "Initials: $initials"
11+
best_runs="artifacts/$initials"_best_runs
12+
max="artifacts/$initials"_max.json
13+
echo "will touch and link best_runs -> $best_runs"
14+
echo "will touch and link max.json -> $max"
15+
16+
read -p "Do you wish to continue? [y/N]: " -r
17+
echo # (optional) move to a new line
18+
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
19+
exit 1
20+
fi
21+
22+
set -x
23+
mkdir -p $best_runs
24+
touch $max
25+
ln -s $best_runs best_runs
26+
ln -s $max max.json

sum_score.py

+42-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
#!/user/bin/env pypy3
22
import glob
3-
from util import path, score2str
4-
try:
5-
import json
6-
j = json.loads(open('max.json', 'r').read())
7-
except:
8-
j = {}
3+
from util import score2str
4+
import json
5+
from pathlib import Path
6+
import argparse
7+
8+
def get_args():
9+
examples = """
10+
python3 sum_score.py
11+
python3 sum_score.py artifacts/*_max.json
12+
"""
13+
parser = argparse.ArgumentParser(
14+
epilog=examples,
15+
formatter_class=argparse.RawDescriptionHelpFormatter
16+
)
17+
parser.add_argument('max_files', nargs='*')
18+
return parser.parse_args()
19+
20+
args = get_args()
21+
if args.max_files:
22+
paths = args.max_files
23+
else:
24+
paths = ['max.json']
25+
26+
def loadj(text):
27+
try:
28+
return json.loads(text)
29+
except:
30+
return {}
31+
32+
all_results = [(p, loadj(Path(p).read_text())) for p in paths]
33+
collated = {}
34+
for (p, maxjson) in all_results:
35+
for name, v in maxjson.items():
36+
if name not in collated or v['score'] > collated[name]['score']:
37+
collated[name] = v
38+
collated[name]['path'] = p
39+
40+
j = collated
941

1042
S = 0
1143
for name in sorted(j.keys()):
1244
v = j[name]['score']
13-
f = j[name]['folder']
14-
pys = glob.glob('{}/*.py'.format(f))
15-
sol_name = ''
16-
if pys:
17-
sol_name = ' '.join(path(pyf).name for pyf in pys)
18-
print('{:25}: {:20} {:20} {}'.format(name, score2str(v), sol_name, f))
45+
p = j[name]['path']
46+
m = j[name]['module']
47+
who_max = Path(p).with_suffix('').name
48+
print('{:25}: {:22} {:15} {}'.format(name, score2str(v), m, Path(p).name))
1949
S += v
2050
print('{:25}: {:20}'.format('Total', score2str(S)))

0 commit comments

Comments
 (0)