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
The uuid of the project.
"""
dl.unlock(path + '/backlogger.db', dataset=path)
conn = sqlite3.connect(path + '/backlogger.db')
db = os.path.join(path, 'backlogger.db')
dl.unlock(db, dataset=path)
conn = sqlite3.connect(db)
c = conn.cursor()
files = []
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)
known_meas = {}
if not os.path.exists(path + "/archive/" + ensemble + "/" + corr):
os.makedirs(path + "/archive/" + ensemble + "/" + corr)
if not os.path.exists(os.path.join(path, '.', 'archive', ensemble, corr)):
os.makedirs(os.path.join(path, '.', 'archive', ensemble, corr))
else:
if os.path.exists(file):
dl.unlock(file, dataset=path)
@ -61,7 +62,7 @@ def write_measurement(path, ensemble, measurement, uuid, code, parameter_file):
for subkey in subkeys:
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]
@ -135,10 +136,12 @@ def preload(path: str, file: 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]
dl.unlock(path + '/backlogger.db', dataset=path)
conn = sqlite3.connect(path + '/backlogger.db')
dl.unlock(db, dataset=path)
conn = sqlite3.connect(db)
c = conn.cursor()
if c.execute("SELECT * FROM backlogs WHERE path = ?", (meas_path, )).fetchone() is not None:
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]
dl.unlock(file, dataset=path)
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
else:
raise ValueError("This measurement does not exist as a file!")