Skip to content

Commit

Permalink
Read experiment "Info" from the info.json file.
Browse files Browse the repository at this point in the history
  • Loading branch information
chovanecm committed Jun 6, 2017
1 parent d442878 commit c8f3c88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 18 additions & 6 deletions sacredboard/app/data/filestorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,36 @@

from sacredboard.app.data.datastorage import Cursor, DataStorage

config_json = "config.json"
run_json = "run.json"
CONFIG_JSON = "config.json"
RUN_JSON = "run.json"
INFO_JSON = "info.json"


def _path_to_file(basepath, run_id, file_name):
return os.path.join(basepath, str(run_id), file_name)


def _path_to_config(basepath, run_id):
return os.path.join(basepath, str(run_id), config_json)
return _path_to_file(basepath, str(run_id), CONFIG_JSON)


def _path_to_info(basepath, run_id):
return _path_to_file(basepath, str(run_id), INFO_JSON)


def _path_to_run(basepath, run_id):
return os.path.join(basepath, str(run_id), run_json)
return os.path.join(basepath, str(run_id), RUN_JSON)


def _read_json(path_to_json):
with open(path_to_json) as f:
return json.load(f)


def _create_run(runjson, configjson):
def _create_run(run_id, runjson, configjson, infojson):
runjson["_id"] = run_id
runjson["config"] = configjson
runjson["info"] = infojson

# TODO probably want a smarter way of detecting
# which values have type "time."
Expand Down Expand Up @@ -52,7 +63,8 @@ def __init__(self, path_to_dir):
def get_run(self, run_id):
config = _read_json(_path_to_config(self.path_to_dir, run_id))
run = _read_json(_path_to_run(self.path_to_dir, run_id))
return _create_run(run, config)
info = _read_json(_path_to_info(self.path_to_dir, run_id))
return _create_run(run_id, run, config, info)

def get_runs(self, sort_by=None, sort_direction=None,
start=0, limit=None, query={"type": "and", "filters": []}):
Expand Down
4 changes: 4 additions & 0 deletions sacredboard/tests/data/test_filestorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def create_tmp_datastore():
"stop_time": "2017-06-02T07:14:02.455460",
"heartbeat": "2017-06-02T07:14:02.452597",
"captured_out": "Output: \n"}
info = {"info": "present"}

experiment_dir = tempfile.mkdtemp()
experiment42 = os.path.join(experiment_dir, "42") # experiment number 42
Expand All @@ -55,6 +56,9 @@ def create_tmp_datastore():
with open(os.path.join(experiment42, "run.json"), 'w') as run_file:
json.dump(run, run_file)

with open(os.path.join(experiment42, "info.json"), 'w') as info_file:
json.dump(info, info_file)

return experiment_dir

@pytest.fixture
Expand Down

0 comments on commit c8f3c88

Please sign in to comment.