-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.py
119 lines (104 loc) · 4.37 KB
/
Storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from DiskStorage import DiskStorage
from ConfigReader import ConfigReader
class Storage:
database_type_key = 'database-type'
session_id_key = 'session-id'
db_type_fs = 'filesystem'
# expects pandas data frame and identifier, optionally a session id
# stores pandas data frame in storage system
@staticmethod
def store_pd_frame(data_frame, identifier, session_id=None):
db_type = ConfigReader.get_db_type()
if session_id is None:
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
DiskStorage.store_pd_frame(data_frame, identifier, session_id)
# expects identifier, optionally a session id
# returns corresponding pandas data frame
@staticmethod
def load_pd_frame(identifier, session_id=None):
db_type = ConfigReader.get_db_type()
if session_id is None:
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
return DiskStorage.load_pd_frame(identifier, session_id)
# expects identifier, optionally a session id
# deletes corresponding pandas data frame from storage system
@staticmethod
def delete_pd_frame(identifier, session_id=None):
db_type = ConfigReader.get_db_type()
if session_id is None:
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
DiskStorage.delete_pd_frame(identifier, session_id)
# expects model and identifier
# stores model in storage system
@staticmethod
def store_model(model, identifier):
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
DiskStorage.store_model(model, identifier, session_id)
# expects identifier
# returns corresponding model
@staticmethod
def load_model(identifier):
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
return DiskStorage.load_model(identifier, session_id)
# expects identifier
# deletes corresponding model from storage system
@staticmethod
def delete_model(identifier):
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
DiskStorage.delete_model(identifier, session_id)
# expects model and identifier
# stores model in storage system
@staticmethod
def store_h5_model(model, identifier):
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
DiskStorage.store_h5_model(model, identifier, session_id)
# expects identifier
# returns corresponding model
@staticmethod
def load_h5_model(identifier):
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
return DiskStorage.load_h5_model(identifier, session_id)
# expects identifier
# deletes corresponding model from storage system
@staticmethod
def delete_h5_model(identifier):
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
DiskStorage.delete_h5_model(identifier, session_id)
# deletes all data from session
@staticmethod
def delete_session_data():
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
DiskStorage.delete_session_data(session_id)
# expects location within the session location (i.e. a directory)
# deletes location from session
@staticmethod
def delete_location(location):
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
DiskStorage.delete_location(location, session_id)
# expects location within the session location (i.e. a directory)
# returns a list of all identifiers from the location
@staticmethod
def list_ids(location):
db_type = ConfigReader.get_db_type()
session_id = ConfigReader.get_session_id()
if db_type == Storage.db_type_fs:
return DiskStorage.list_ids(location, session_id)