Passed
Push — master ( cb8661...b33fcc )
by Cyb3r
07:37 queued 11s
created

MetaStalk.utils.web   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A graph() 0 33 3
1
"""Uses dash to create a webpage that contain all the graphs"""
2
import timeit
3
import logging
4
import webbrowser
5
import dash
6
import dash_html_components as html
7
import dash_core_components as dcc
8
9
10
log = logging.getLogger("MetaStalk")
11
12
13
def graph(plots: dict, t_start: float, test=False):
14
    """graph
15
16
    Displays all the plots that are passed to it.
17
18
    Arguments:
19
        plots {dict} -- All the plot that get displayed
20
        t_start {float} -- The start time of MetaStalk
21
22
    Keyword Arguments:
23
        test {bool} -- Whether or not to show the web page (default: {False})
24
    """
25
    external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
26
    app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
27
    app.title = "MetaStalk"
28
    graphs = []
29
    for name, chart in plots.items():
30
        graphs.append(dcc.Graph(id="graph-{}".format(name), figure=chart))
31
    t_stop = timeit.default_timer()
32
    app.layout = html.Div([
33
        html.H1("MetaStalk", style={"textAlign": "center"}),
34
        html.H6(html.A('Cyber Jake', href="https://twitter.com/Cyb3r_Jak3"),
35
                style={"textAlign": "center"}),
36
        html.Div(children=graphs),
37
        html.P("Time Taken = {0:.2f} seconds".format(t_stop - t_start),
38
               style={"textAlign": "center"})
39
    ])
40
    if not test:
41
        webbrowser.open("http://localhost:8052", new=2)
42
        app.run_server(port=8052)
43
    else:
44
        log.info("Test flag was set. No webpage will be shown.")
45
        log.info("Time Taken = {0:.2f} seconds".format(t_stop - t_start))
46