-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeProblemSet.py
executable file
·79 lines (63 loc) · 2.59 KB
/
makeProblemSet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
import MySQLdb as mdb
import sys
import argparse
import string
import benchmarkingUtils as bu
DELIM=','
NAString='NA'
(server, user, password, database) = bu.loadConfiguration()
parser = argparse.ArgumentParser(description='Creates a problem set consisting of the benchmarks in the input file.')
parser.add_argument('-p','--problemset',type=int,
help='Problem set we are adding benchmarks to.')
parser.add_argument('-f','--file',type=str,
help='file containing the benchmark paths to add')
parser.add_argument('-a','--addbenchmarks',action='store_true', default=False,
help='Add benchmarks to data-base if they do not already exist (default false)')
args = parser.parse_args()
bench_file=args.file
problem_set= args.problemset
add_benchmarks = args.addbenchmarks
def addBenchmarks(cur, f):
infile = open(f, 'r')
bench_names = [bench_path.strip() for bench_path in infile]
infile.close()
for path in bench_names:
# print "Processing ", path
cur.execute("SELECT EXISTS(SELECT 1 FROM Problems WHERE path=%s);", (path))
result=cur.fetchone()
if (not result[0]):
print "Adding benchmark ", path
cur.execute("INSERT INTO Problems (path) VALUES (%s);", (path))
def selectBenchmarksFromFile(cur, f):
infile = open(f, 'r')
bench_names = [bench_path.strip() for bench_path in infile]
infile.close()
#collect the id of the benchmarks
bench_ids = []
bench_paths = []
for path in bench_names:
print path
cur.execute("SELECT MAX(id), path FROM Problems WHERE path like %s;", ('%'+path+'%'))
result=cur.fetchone()
bench_ids.append(result[0])
bench_paths.append(result[1])
return bench_ids, bench_paths
def addBenchmarksToProblemSet(cur, pb_set, bench_ids, bench_paths):
for i in range(len(bench_ids)):
bench_id = bench_ids[i]
bench_path = bench_paths[i]
print "Adding to problem set ", pb_set, " benchmark ", bench_path
cur.execute("INSERT INTO ProblemSetToProblem VALUES(%s, %s);", (pb_set, bench_id))
con = mdb.connect(server, user, password, database);
with con:
cur = con.cursor()
if (add_benchmarks):
addBenchmarks(cur, bench_file)
#select benchmarks
benchmark_ids, benchmark_paths = None, None
benchmark_ids, benchmark_paths = selectBenchmarksFromFile(cur, bench_file)
assert benchmark_ids != None
assert benchmark_paths != None
addBenchmarksToProblemSet(cur, problem_set, benchmark_ids, benchmark_paths);
con.close()