correct paths when writing a measurement

This commit is contained in:
Justus Kuhlmann 2025-04-16 08:45:24 +00:00
parent 5fa80077aa
commit bb47bdb81f

View file

@ -25,17 +25,18 @@ def write_measurement(path, ensemble, measurement, uuid, code, parameter_file):
uuid: str uuid: str
The uuid of the project. The uuid of the project.
""" """
db = os.path.join(path, 'backlogger.db')
dl.unlock(path + '/backlogger.db', dataset=path) dl.unlock(db, dataset=path)
conn = sqlite3.connect(path + '/backlogger.db') conn = sqlite3.connect(db)
c = conn.cursor() c = conn.cursor()
files = [] files = []
for corr in measurement.keys(): for corr in measurement.keys():
file = path + "/archive/" + ensemble + "/" + corr + '/' + uuid + '.json.gz' file_in_archive = os.path.join('.', 'archive', ensemble, corr, uuid + '.json.gz')
file = os.path.join(path, file_in_archive)
files.append(file) files.append(file)
known_meas = {} known_meas = {}
if not os.path.exists(path + "/archive/" + ensemble + "/" + corr): if not os.path.exists(os.path.join(path, '.', 'archive', ensemble, corr)):
os.makedirs(path + "/archive/" + ensemble + "/" + corr) os.makedirs(os.path.join(path, '.', 'archive', ensemble, corr))
else: else:
if os.path.exists(file): if os.path.exists(file):
dl.unlock(file, dataset=path) dl.unlock(file, dataset=path)
@ -61,7 +62,7 @@ def write_measurement(path, ensemble, measurement, uuid, code, parameter_file):
for subkey in subkeys: for subkey in subkeys:
parHash = sha256(str(pars[subkey]).encode('UTF-8')).hexdigest() parHash = sha256(str(pars[subkey]).encode('UTF-8')).hexdigest()
meas_path = file + "::" + parHash meas_path = file_in_archive + "::" + parHash
known_meas[parHash] = measurement[corr][subkey] known_meas[parHash] = measurement[corr][subkey]
@ -135,10 +136,12 @@ def preload(path: str, file: str):
def drop_record(path: str, meas_path: str): def drop_record(path: str, meas_path: str):
file = meas_path.split("::")[0] file_in_archive = meas_path.split("::")[0]
file = os.path.join(path, file_in_archive)
db = os.path.join(path, 'backlogger.db')
sub_key = meas_path.split("::")[1] sub_key = meas_path.split("::")[1]
dl.unlock(path + '/backlogger.db', dataset=path) dl.unlock(db, dataset=path)
conn = sqlite3.connect(path + '/backlogger.db') conn = sqlite3.connect(db)
c = conn.cursor() c = conn.cursor()
if c.execute("SELECT * FROM backlogs WHERE path = ?", (meas_path, )).fetchone() is not None: if c.execute("SELECT * FROM backlogs WHERE path = ?", (meas_path, )).fetchone() is not None:
c.execute("DELETE FROM backlogs WHERE path = ?", (meas_path, )) c.execute("DELETE FROM backlogs WHERE path = ?", (meas_path, ))
@ -151,7 +154,7 @@ def drop_record(path: str, meas_path: str):
del known_meas[sub_key] del known_meas[sub_key]
dl.unlock(file, dataset=path) dl.unlock(file, dataset=path)
pj.dump_dict_to_json(known_meas, file) pj.dump_dict_to_json(known_meas, file)
dl.save([path + '/backlogger.db', file], message="Drop measurements to database", dataset=path) dl.save([db, file], message="Drop measurements to database", dataset=path)
return return
else: else:
raise ValueError("This measurement does not exist as a file!") raise ValueError("This measurement does not exist as a file!")