|
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, verbosity=True, warnings=True): |
|
11
|
|
|
self.path = "./" |
|
12
|
|
|
self.verbosity = verbosity |
|
13
|
|
|
self.warnings = warnings |
|
14
|
|
|
|
|
15
|
|
|
def get_filter_file_path(self, search_id): |
|
16
|
|
|
return self.path + "/filter_" + search_id + ".csv" |
|
17
|
|
|
|
|
18
|
|
|
def get_progress_data_path(self, search_id): |
|
19
|
|
|
return self.path + "/progress_data_" + search_id + ".csv~" |
|
20
|
|
|
|
|
21
|
|
|
def get_lock_file_path(self, search_id): |
|
22
|
|
|
return self.path + "/progress_data_" + search_id + ".csv~.lock~" |
|
23
|
|
|
|
|
24
|
|
|
def load_filter(self, search_id): |
|
25
|
|
|
path = self.get_filter_file_path(search_id) |
|
26
|
|
|
if os.path.isfile(path): |
|
27
|
|
|
if self.verbosity: |
|
28
|
|
|
print("Load filter file from path:", path) |
|
29
|
|
|
return pd.read_csv(path) |
|
30
|
|
|
else: |
|
31
|
|
|
if self.warnings: |
|
32
|
|
|
print("Warning: Filter file not found in:", path) |
|
33
|
|
|
return None |
|
34
|
|
|
|
|
35
|
|
|
def load_progress(self, search_id): |
|
36
|
|
|
path = self.get_progress_data_path(search_id) |
|
37
|
|
|
if os.path.isfile(path): |
|
38
|
|
|
if self.verbosity: |
|
39
|
|
|
print("Load progress data file from path:", path) |
|
40
|
|
|
return pd.read_csv(path) |
|
41
|
|
|
else: |
|
42
|
|
|
if self.warnings: |
|
43
|
|
|
print("Warning: Progress data not found in:", path) |
|
44
|
|
|
return None |
|
45
|
|
|
|
|
46
|
|
|
def remove_filter(self, search_id): |
|
47
|
|
|
path = self.get_filter_file_path(search_id) |
|
48
|
|
|
if os.path.isfile(path): |
|
49
|
|
|
os.remove(path) |
|
50
|
|
|
if self.verbosity: |
|
51
|
|
|
print("Remove filter file from path:", path) |
|
52
|
|
|
|
|
53
|
|
|
def remove_progress(self, search_id): |
|
54
|
|
|
path = self.get_progress_data_path(search_id) |
|
55
|
|
|
if os.path.isfile(path): |
|
56
|
|
|
os.remove(path) |
|
57
|
|
|
if self.verbosity: |
|
58
|
|
|
print("Remove progress data file from path:", path) |
|
59
|
|
|
|
|
60
|
|
|
def remove_lock(self, search_id): |
|
61
|
|
|
path = self.get_lock_file_path(search_id) |
|
62
|
|
|
if os.path.isfile(path): |
|
63
|
|
|
os.remove(path) |
|
64
|
|
|
if self.verbosity: |
|
65
|
|
|
print("Remove lock file from path:", path) |
|
66
|
|
|
|
|
67
|
|
|
def create_filter(self, search_id, search_space): |
|
68
|
|
|
path = self.get_filter_file_path(search_id) |
|
69
|
|
|
self.remove_filter(search_id) |
|
70
|
|
|
|
|
71
|
|
|
indices = list(search_space.keys()) + ["score"] |
|
72
|
|
|
filter_dict = { |
|
73
|
|
|
"parameter": indices, |
|
74
|
|
|
"lower bound": "---", |
|
75
|
|
|
"upper bound": "---", |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
df = pd.DataFrame(filter_dict) |
|
79
|
|
|
df.to_csv(path, index=None) |