Passed
Push — master ( 7e35c2...37974c )
by Simon
03:12
created

hyperactive.dashboards.progress_board.progress_io   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A ProgressIO.remove_progress() 0 4 2
A ProgressIO.remove_filter() 0 4 2
A ProgressIO.create_filter() 0 13 1
A ProgressIO.__init__() 0 2 1
A ProgressIO.load_filter() 0 7 2
A ProgressIO.get_filter_file_path() 0 2 1
A ProgressIO.get_progress_data_path() 0 2 1
A ProgressIO.load_progress() 0 7 2
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import os
6
import pandas as pd
7
8
9
class ProgressIO:
10
    def __init__(self, path):
11
        self.path = path
12
13
    def get_filter_file_path(self, search_id):
14
        return self.path + "/filter_" + search_id + ".csv"
15
16
    def get_progress_data_path(self, search_id):
17
        return self.path + "/progress_data_" + search_id + ".csv"
18
19
    def load_filter(self, search_id):
20
        path = self.get_filter_file_path(search_id)
21
        if os.path.isfile(path):
22
            return pd.read_csv(path)
23
        else:
24
            print("\n Warning: Filter file not found in:", path)
25
            return None
26
27
    def load_progress(self, search_id):
28
        path = self.get_progress_data_path(search_id)
29
        if os.path.isfile(path):
30
            return pd.read_csv(path)
31
        else:
32
            print("\n Warning: Progress data not found in:", path)
33
            return None
34
35
    def remove_filter(self, search_id):
36
        path = self.get_filter_file_path(search_id)
37
        if os.path.isfile(path):
38
            os.remove(path)
39
40
    def remove_progress(self, search_id):
41
        path = self.get_progress_data_path(search_id)
42
        if os.path.isfile(path):
43
            os.remove(path)
44
45
    def create_filter(self, search_id, search_space):
46
        path = self.get_filter_file_path(search_id)
47
        self.remove_filter(search_id)
48
49
        indices = list(search_space.keys()) + ["score"]
50
        filter_dict = {
51
            "parameter": indices,
52
            "lower bound": "lower",
53
            "upper bound": "upper",
54
        }
55
56
        df = pd.DataFrame(filter_dict)
57
        df.to_csv(path, index=None)