Passed
Push — master ( f4e57c...929827 )
by Cyb3r
01:59 queued 11s
created

MetaStalk.utils.web   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 86.96%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 50
ccs 20
cts 23
cp 0.8696
rs 10
c 0
b 0
f 0
wmc 4

1 Function

Rating   Name   Duplication   Size   Complexity  
A graph() 0 36 4
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
23
    Keyword Arguments:
24
        test {bool} -- Whether or not to start web server (default: {False})
25
        no_open {bool} -- Whether or now to open with the browser (default: {False})
26
    """
27 1
    graphs = []
28 1
    for name, chart in plots.items():
29 1
        graphs.append(dcc.Graph(id="graph-{}".format(name), figure=chart))
30 1
    external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
31 1
    app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
32 1
    app.title = "MetaStalk"
33 1
    t_stop = timeit.default_timer()
34 1
    app.layout = html.Div([
35
        html.H1("MetaStalk", style={"textAlign": "center"}),
36
        html.H6(html.A("By Cyber Jake", href="https://twitter.com/Cyb3r_Jak3"),
37
                style={"textAlign": "center"}),
38
        html.Div(children=graphs),
39
        html.Footer("Time Taken = {0:.2f} seconds".format(t_stop - t_start),
40
                    style={"textAlign": "right"}),
41
        html.Footer(f"Run Time: {datetime.now().strftime('%m/%d/%Y, %H:%M:%S')}")
42
    ])
43 1
    if not test:
44
        if not no_open:
45
            webbrowser.open("http://localhost:8052", new=2)
46
        app.run_server(port=8052)
47
    else:
48 1
        log.info("Test flag was set. No webpage will be shown.")
49
        log.info("Time Taken = {0:.2f} seconds".format(t_stop - t_start))
50