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

MetaStalk.utils.export.export()   B

Complexity

Conditions 8

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 8.0189

Importance

Changes 0
Metric Value
cc 8
eloc 15
nop 3
dl 0
loc 26
ccs 14
cts 15
cp 0.9333
crap 8.0189
rs 7.3333
c 0
b 0
f 0
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