forked from duckdb/duckdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_querygraph.py
58 lines (42 loc) · 1.36 KB
/
generate_querygraph.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
# generate_querygraph.py
# This script takes a json file as input that is the result of the QueryProfiler of duckdb
# and converts it into a Query Graph.
import os
import sys
sys.path.insert(0, 'benchmark')
import duckdb_query_graph
if len(sys.argv) <= 1:
print("Usage: python generate_querygraph.py [input.json] [output.html] [open={1,0}]")
exit(1)
input = sys.argv[1]
if len(sys.argv) <= 2:
if ".json" in input:
output = input.replace(".json", ".html")
else:
output = input + ".html"
else:
output = sys.argv[2]
open_output = True
if len(sys.argv) >= 4:
open_arg = sys.argv[3].lower()
if open_arg == "1" or open_arg == "true":
open_output = True
elif sys.argv[3] == "0" or open_arg == "false":
open_output = False
else:
print("Incorrect input for open_output, expected TRUE or FALSE")
exit(1)
duckdb_query_graph.generate(input, output)
with open(output, 'r') as f:
text = f.read()
#inline javascript files
with open('benchmark/raphael.js', 'r') as f:
raphael = f.read()
with open('benchmark/treant.js', 'r') as f:
treant = f.read()
text = text.replace('<script src="../../raphael.js"></script>', '<script>' + raphael + '</script>')
text = text.replace('<script src="../../treant.js"></script>', '<script>' + treant + '</script>')
with open(output, 'w+') as f:
f.write(text)
if open_output:
os.system('open "' + output.replace('"', '\\"') + '"')