Commit dfc963ec authored by Martin Drechsler's avatar Martin Drechsler

comments added to storage

parent 1dc78886
...@@ -22,13 +22,19 @@ class Storage(object): ...@@ -22,13 +22,19 @@ class Storage(object):
Class to handle data saving. Class to handle data saving.
""" """
def __init__(self): def __init__(self):
"""
self.directory = '.' By default, directory is set to the current directory.
"""
self.directory = os.getcwd()
def set_directory(self, directory): def set_directory(self, directory):
self.directory = directory self.directory = directory
def create_data_file(self, *args): def create_data_file(self, *args):
"""
Creates a file to store data. Name is set automatically.
*args should be strings, with the column titles of the data to be saved.
"""
saving_directory = "/".join([self.directory, self.get_date_string()]) saving_directory = "/".join([self.directory, self.get_date_string()])
if not os.path.exists(saving_directory): if not os.path.exists(saving_directory):
os.makedirs(saving_directory) os.makedirs(saving_directory)
...@@ -51,12 +57,20 @@ class Storage(object): ...@@ -51,12 +57,20 @@ class Storage(object):
def append_data_to_current_file(self, row): def append_data_to_current_file(self, row):
"""
This will append a row to the last data file created.
row should be a list with the values to append.
"""
with open(self.get_current_data_filename(), 'ab') as f: with open(self.get_current_data_filename(), 'ab') as f:
#data = np.column_stack(args) #data = np.column_stack(args)
np.savetxt(f, [row]) np.savetxt(f, [row])
f.flush() f.flush()
def append_metadata_to_current_file(self, *args): def append_metadata_to_current_file(self, *args):
"""
This appends metadata to the last metadata file created.
*args should be dictionaries, each of them will be stored.
"""
for arg in args: for arg in args:
for key, value in arg.items(): for key, value in arg.items():
with open(self.get_current_metadata_filename(), 'a') as f: with open(self.get_current_metadata_filename(), 'a') as f:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment