-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
56 lines (47 loc) · 1.44 KB
/
plot.py
File metadata and controls
56 lines (47 loc) · 1.44 KB
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
import csv
from .analysis import run_analysis
import requests
import tempfile
# from from bokeh.charts import Bar, output_file, show
from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource, HoverTool, Range1d, LabelSet, Label
def main(args):
run_analysis(get_file(args.pyfile ),"test.csv")
with open("test.csv") as f:
file_data = list(csv.reader(f))
plot(file_data,args.output)
def get_file(file_or_arg_url):
if file_or_arg_url.startswith('http'):
response = requests.get(file_or_arg_url)
response.raise_for_status()
temp = tempfile.mktemp()
with open(temp,"w") as f:
f.write(response.text)
return temp
return file_or_arg_url
def plot(data,file_output):
output_file(file_output)
source = create_data_source(data)
p = figure(title="File Data", tools=[HoverTool(
tooltips=[
("name","@method_name"),
("complexity","@complexity")
])])
p.line(source=source, y='line_num',x='complexity', line_width=2)
y_min = 0
y_max = max(source.data['line_num'])
p.y_range = Range1d(y_max,y_min)
show(p)
def create_data_source(data):
source = ColumnDataSource(data=dict(
line_num = [int(x[0]) for x in data],
complexity = [int(x[2]) for x in data],
method_name = [x[1] for x in data]))
return source
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("pyfile")
parser.add_argument("--output", default="plot.html")
args = parser.parse_args()
main(args)