Last active
June 4, 2021 09:19
-
-
Save GenevieveBuckley/20750b92c51a6adfe8ef0994fc5b8624 to your computer and use it in GitHub Desktop.
HighLevelGraph HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from html import escape | |
class HighLevelGraphHTML(): | |
def __init__(self, highlevelgraph): | |
self.highlevelgraph = highlevelgraph | |
pass | |
def _repr_html_(self): | |
highlevelgraph = self.highlevelgraph | |
highlevelgraph_info = escape(highlevelgraph.__str__()) | |
html = f""" | |
<div style=""> | |
<div> | |
<div style=" | |
width: 24px; | |
height: 24px; | |
background-color: #FFF7E5; | |
border: 3px solid #FF6132; | |
border-radius: 5px; | |
position: absolute;"> </div> | |
<div style="margin-left: 48px;"> | |
<h3 style="margin-bottom: 0px;">HighLevelGraph</h3> | |
<p style="color: #9D9D9D; margin-bottom: | |
0px;">{highlevelgraph_info}</p> | |
""" | |
for i, (key, layer) in enumerate(highlevelgraph.layers.items()): | |
key_shortname = key.rsplit('-', 1)[0] # removes token | |
dependencies = highlevelgraph.dependencies[key] | |
info = layer_info_dict(layer, dependencies) | |
layer_info_table = html_from_dict(info) | |
layer_html = f""" | |
<div style=""> | |
<details style="margin-left: 48px;"> | |
<summary style="margin-bottom: 20px; margin-top: 20px;"><h3 style="display: inline;">Layer {i}: {key_shortname}</h3></summary> | |
{key} | |
{layer_info_table} | |
</details> | |
</div> | |
""" | |
html += layer_html | |
self.html = html | |
return html | |
def html_from_dict(info): | |
html = """<table>""" | |
suffix = """</table>""" | |
for key, val in info.items(): | |
table_row = f""" | |
<tr> | |
<th>{key}</th> | |
<td>{val}</td> | |
</tr> | |
""" | |
html += table_row | |
html += suffix | |
return html | |
def layer_info_dict(layer, dependencies): | |
info = { | |
"layer_type": type(layer).__name__, | |
"is_materialized": layer.is_materialized(), | |
"dependencies": dependencies | |
} | |
return info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment