-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_html.py
126 lines (122 loc) · 5.07 KB
/
debug_html.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
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
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
import pandas as pd
def render_debug_html(title, fields, n_templates,
field_tfl_active_unnormalized,
field_tfl_inactive,
field_tfl_active,
children_field_tfl,
parent_field_tfl,
parent_no_other_field_templates,
not_an_item_ancestor,
children_no_other_field_templates,
no_other_field_competitor,
exactly_one_field_competitor,
children_debug_html,
item_tl_active,
children_item_tl,
parent_item_tl,
no_other_item_competitor,
exactly_one_other_item_competitor,
no_other_item_level):
fm = lambda x: "" if x == 0 else ('?' if x == -1 else '{:.0%}'.format(x))
return f"""
<div style="background: rgba(0, 0, 0, 0.04)">
<h2>{title}</h2>
<div style="display: flex">
<div class="datatable">
<h3>TFL active (pre normalization!)</h3>
{"".join([pd.DataFrame(field_tfl_active_unnormalized[ti, ...], index=fields).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
<div class="datatable">
<h3>TFL inactive (pre normalization!)</h3>
{"".join([pd.DataFrame(field_tfl_inactive[ti, ...], index=fields).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
<div class="datatable">
<h3>TFL active (post normalization!)</h3>
{"".join([pd.DataFrame(field_tfl_active[ti, ...], index=fields).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
</div>
<div style="display: flex; color: navy;">
<div class="datatable">
<h3>Children Field TFL</h3>
{"".join([pd.DataFrame(children_field_tfl[ti, ...], index=fields).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
<div class="datatable">
<h3>Parent Field TFL</h3>
{"".join([pd.DataFrame(parent_field_tfl[ti, ...], index=fields).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
<div class="datatable">
<h3>parent_no_other_templates</h3>
{"".join([pd.DataFrame(parent_no_other_field_templates[ti, ...]).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
<div class="datatable">
<h3>no other field competitor</h3>
{"".join([pd.DataFrame(no_other_field_competitor[ti, ...]).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
<div class="datatable">
<h3>exactly one field competitor</h3>
{"".join([pd.DataFrame(exactly_one_field_competitor[ti, ...]).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
<div class="datatable">
<h3>not_an_item_ancestor</h3>
{not_an_item_ancestor}
</div>
<div class="datatable">
<h3>children_no_other_field_templates</h3>
{"".join([pd.DataFrame(children_no_other_field_templates[ti, ...]).to_html(float_format=fm) for ti in range(n_templates)])}
</div>
</div>
<div style="display: flex; color: darkgreen;">
<div class="datatable">
<h3>item_tl_active</h3>
{pd.DataFrame(item_tl_active).to_html(float_format=fm)}
</div>
<div class="datatable">
<h3>children_item_tl</h3>
{pd.DataFrame(children_item_tl).to_html(float_format=fm)}
</div>
<div class="datatable">
<h3>parent_item_tl</h3>
{pd.DataFrame(parent_item_tl).to_html(float_format=fm)}
</div>
<div class="datatable">
<h3>no_other_item_competitor</h3>
{pd.DataFrame(no_other_item_competitor).to_html(float_format=fm)}
</div>
<div class="datatable">
<h3>exactly_one_other_item_competitor</h3>
{pd.DataFrame(exactly_one_other_item_competitor).to_html(float_format=fm)}
</div>
<div class="datatable">
<h3>no_other_item_level</h3>
{no_other_item_level}
</div>
</div>
<div style="margin-left: 2rem">
{children_debug_html}
</div>
</div>
"""
def wrap_debug_html(debug_html):
style = """<style>
body {
font-family: Inter;
}
.datatable {
margin: 0 1rem;
}
.dataframe {
font-family: "IBM Plex Mono";
font-size: 80%;
border: none;
border-collapse: collapse;
}
.dataframe td {
border-style: solid;
width: 2rem;
}
</style>"""
return f"""<html>
<head><title>Induction output</title>{style}</head>
<body>{debug_html}</body>
</html>"""