Passed
Push — master ( cba5ed...7e35c2 )
by Simon
04:17
created

ProgressBoard.__init__()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
import os
7
import uuid
8
import numpy as np
9
import pandas as pd
10
11
from ..data_tools import DataCollector
12
13
14
class ProgressBoard:
15
    def __init__(self, filter_file=None):
16
        self.filter_file = filter_file
17
18
        self.uuid = uuid.uuid4().hex
19
        self.paths_list = []
20
21
    def _create_filter_file(self, search_id, search_space):
22
        filter_path = "./filter_" + search_id + ".csv"
23
        if os.path.isfile(filter_path):
24
            os.remove(filter_path)
25
26
        indices = list(search_space.keys()) + ["score"]
27
        filter_dict = {
28
            "parameter": indices,
29
            "lower bound": "lower",
30
            "upper bound": "upper",
31
        }
32
33
        df = pd.DataFrame(filter_dict)
34
        df.to_csv(filter_path, index=None)
35
36
    def init_paths(self, search_id, search_space):
37
        progress_data_path = "./progress_data_" + search_id + ".csv~"
38
39
        if os.path.isfile(progress_data_path):
40
            os.remove(progress_data_path)
41
42
        data_c = DataCollector(progress_data_path)
43
44
        self.paths_list.append(search_id)
45
        if self.filter_file:
46
            self._create_filter_file(search_id, search_space)
47
48
        return data_c
49
50
    def open_dashboard(self):
51
        abspath = os.path.abspath(__file__)
52
        dir_ = os.path.dirname(abspath)
53
54
        paths = " ".join(self.paths_list)
55
        open_streamlit = "streamlit run " + dir_ + "/run_streamlit.py " + paths
56
57
        # from: https://stackoverflow.com/questions/7574841/open-a-terminal-from-python
58
        os.system("gnome-terminal -e 'bash -c \" " + open_streamlit + " \"'")
59