-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
118 lines (108 loc) · 4.21 KB
/
Copy pathreport.py
File metadata and controls
118 lines (108 loc) · 4.21 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from bokeh.plotting import curdoc, figure
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, Range1d, LinearAxis, Whisker, Span, Div
from bokeh.io import show, output_file, save
from bokeh.transform import factor_cmap
from colour import Color
import utils
class Report():
models = {"Div": Div, "Span": Span, "Range1d": Range1d, "ColumnDataSource": ColumnDataSource}
layouts = {"column": column, "row": row}
figure = figure
Color = Color
def __init__(self, *args): # title, file_name = None
self.figures = []
self.doc = curdoc()
self.doc.theme = 'dark_minimal'
self.doc_root_attached = False
# args could be (title, file_name) or (title, file_name_pattern, file_descriptor)
if len(args) == 2:
self.title = args[0]
self.file_name = args[1]
elif len(args) == 3:
self.title = args[0]
self.file_name = None
self.file_name_pattern = args[1]
self.file_descriptor = args[2]
else:
raise "Constructor needs args of (title, file_name) or (title, file_name_pattern, file_descriptor)"
def add_figure(self, figure):
self.figures.append(figure)
def render_to_file(self):
if self.doc_root_attached == False:
globalcss = Div(text="""
<style>
.bk-root {
background-color: #202020;
// border-color: #000000;
color: #d0d0d0
}
body {
display: block;
background-color: #202020;
margin: 8px;
}
h1 {
margin-top: 0px;
}
</style>
""")
self.doc.add_root(column(*[globalcss,*self.figures])) # row(fig1, fig2, ) , background="black"
self.doc_root_attached = True
if self.file_name != None:
print("here")
#we should use the file name provided directly
output_file(filename=self.file_name, title=self.title)
save(self.doc)
return None
elif self.file_name_pattern != None or self.file_descriptor != None:
print("here2")
# we should save a random file name and keep the details within an id file
rid = utils.random_id()
report_file_name = (self.file_name_pattern + ".html") % (rid)
report_id_file_name = (self.file_name_pattern + ".id") % (rid)
with open(report_id_file_name, "w") as fid:
fid.write(self.file_descriptor)
output_file(filename=report_file_name, title=self.title)
save(self.doc)
return report_file_name
else:
raise "Bad arguments"
"""
from bokeh.plotting import curdoc, figure
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, Range1d, LinearAxis, Whisker, Span, Div
from bokeh.io import show, output_file, save
from bokeh.transform import factor_cmap
from colour import Color
import utils
class Report():
models = {"Div": Div, "Span": Span, "Range1d": Range1d, "ColumnDataSource": ColumnDataSource}
layouts = {"column": column, "row": row}
figure = figure
Color = Color
def __init__(self, title, file_name = None, run_ids=None):
self.figures = []
self.file_name = file_name
self.doc = curdoc()
self.title = title
self.doc_root_attached = False
self.run_ids = run_ids
def add_figure(self, figure):
self.figures.append(figure)
def render_to_file(self):
if self.doc_root_attached == False:
self.doc.add_root(column(*self.figures))
self.doc_root_attached = True
if self.file_name != None:
raise "No file_name provided 2nd constructor argument"
rid = utils.random_id()
file_id_file = "./calibration-data/combination-report-%s.id" % (rid)
file_short = "./calibration-data/combination-report-%s.html" % (rid)
with open(file_id_file, "w") as fid:
fid.write(self.file_name)
output_file(filename=file_short, title=self.title)
save(self.doc)
return file_short
print ( )
"""