1
|
|
|
"""Uses dash to create a webpage that contain all the graphs/"""
|
2
|
1 |
|
import timeit
|
3
|
1 |
|
import logging
|
4
|
1 |
|
import webbrowser
|
5
|
1 |
|
from datetime import datetime
|
6
|
1 |
|
import dash
|
7
|
1 |
|
import dash_html_components as html
|
8
|
1 |
|
import dash_core_components as dcc
|
9
|
|
|
|
10
|
|
|
|
11
|
1 |
|
log = logging.getLogger("MetaStalk")
|
12
|
|
|
|
13
|
|
|
|
14
|
1 |
|
def graph(plots: dict, t_start: float, test: bool, no_open: bool):
|
15
|
|
|
"""Graph
|
16
|
|
|
|
17
|
|
|
Displays all the plots that are passed to it.
|
18
|
|
|
|
19
|
|
|
Arguments:
|
20
|
|
|
plots {dict} -- All the plot that get displayed
|
21
|
|
|
t_start {float} -- The start time of MetaStalk
|
22
|
|
|
test {bool} -- Whether or not to start web server (default: {False})
|
23
|
|
|
no_open {bool} -- Whether or now to open with the browser (default: {False})
|
24
|
|
|
"""
|
25
|
1 |
|
graphs = []
|
26
|
1 |
|
for name, chart in plots.items():
|
27
|
1 |
|
graphs.append(dcc.Graph(id="graph-{}".format(name), figure=chart))
|
28
|
1 |
|
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
|
29
|
1 |
|
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
|
30
|
1 |
|
app.logger.disabled = True
|
31
|
1 |
|
app.title = "MetaStalk"
|
32
|
1 |
|
t_stop = timeit.default_timer()
|
33
|
1 |
|
app.layout = html.Div(
|
34
|
|
|
[
|
35
|
|
|
html.H1("MetaStalk", style={"textAlign": "center"}),
|
36
|
|
|
html.H6(
|
37
|
|
|
html.A("Cyber Jake", href="https://twitter.com/Cyb3r_Jak3"),
|
38
|
|
|
style={"textAlign": "center"},
|
39
|
|
|
),
|
40
|
|
|
html.Div(children=graphs),
|
41
|
|
|
html.Footer(
|
42
|
|
|
"Time Taken = {0:.2f} seconds".format(t_stop - t_start),
|
43
|
|
|
style={"textAlign": "right"},
|
44
|
|
|
),
|
45
|
|
|
html.Footer(f"Run Time: {datetime.now().strftime('%m/%d/%Y, %H:%M:%S')}"),
|
46
|
|
|
]
|
47
|
|
|
)
|
48
|
1 |
|
if not test:
|
49
|
|
|
if not no_open: # pragma: no cover
|
50
|
|
|
webbrowser.open("http://localhost:8052", new=2) # pragma: no cover
|
51
|
|
|
app.run_server(port=8052) # pragma: no cover
|
52
|
|
|
else:
|
53
|
1 |
|
log.info("Test flag was set. No webpage will be shown.")
|
54
|
|
|
log.info("Time Taken = {0:.2f} seconds".format(t_stop - t_start))
|
55
|
|
|
|