Total Complexity | 12 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Changes | 0 |
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) |