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

MetaStalk.utils.export   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 38
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0
wmc 8

1 Function

Rating   Name   Duplication   Size   Complexity  
B export() 0 26 8
1
"""utils.export
2
---
3
4
Exports the plots as interactive html
5
"""
6 1
import logging
7 1
import os
8
9 1
log = logging.getLogger("MetaStalk")
10
11
12 1
def export(choice: str, output_dir: str, plots: dict):
13
    """export
14
15
    Exports the plots to the chosen format
16
17
    Arguments:
18
        choice {str}: -- The type of export. {html, pdf, svg, png}
19
        output_dir {str} -- Name of the directory to output charts to.
20
        plots {dict} -- The plots to export.
21
    """
22 1
    if not os.path.isdir(output_dir):
23 1
        os.makedirs(output_dir)
24
    else:
25 1
        if len(os.listdir(output_dir)) != 0:
26
            log.warning("The chosen output directory contain files.")
27
28 1
    if choice == "html":
29 1
        for name, chart in plots.items():
30 1
            chart.write_html(f"{output_dir}/{name}.html")
31 1
    elif choice in ["pdf", "svg", "png"]:
32 1
        try:
33 1
            for name, chart in plots.items():
34 1
                chart.write_image(f"{output_dir}/{name}.{choice}")
35 1
        except ValueError:
36 1
            log.error("Dash requires orca to be install to export images.")
37
            raise EnvironmentError("Dash requires orca to be install to export images.")
38