implement write to db prperly

This commit is contained in:
Justus Kuhlmann 2024-08-13 15:14:34 +00:00
parent 4c81410798
commit 391fa556ef
2 changed files with 53 additions and 32 deletions

View file

@ -1,5 +1,15 @@
import pyerrors as pe
import datalad.api as dl
import json
corr_types = {
'f_A': 'bi',
'f_P': 'bi',
'g_A': 'bi',
'g_P': 'bi',
'f_1': 'bb',
'k_1': 'bb',
}
def read_param(path, project, file_in_project):
@ -105,7 +115,7 @@ def _map_params(params, spec_list):
Map the extracted parameters to the extracted data.
"""
# quarks/offset/wf/wf2
new_specs = {}
# quarks
quarks = spec_list[0].split(" ")
@ -133,6 +143,17 @@ def _map_params(params, spec_list):
return new_specs
def get_specs(key, parameters, sep='/'):
key_parts = key.split(sep)
if corr_types[key_parts[0]] == 'bi':
param = _map_params(parameters, key_parts[1:-1])
else:
param = _map_params(parameters, key_parts[1:])
print(param)
s = json.dumps(param)
return s
def read_data(path, project, dir_in_project, prefix, param, version='1.0c', cfg_seperator='n', sep='/', **kwargs):
"""
Extract the data from the sfcf file.
@ -144,14 +165,7 @@ def read_data(path, project, dir_in_project, prefix, param, version='1.0c', cfg_
"""
names = kwargs.get('names', None)
corr_types = {
'f_A': 'bi',
'f_P': 'bi',
'g_A': 'bi',
'g_P': 'bi',
'f_1': 'bb',
'k_1': 'bb',
}
directory = path + "/projects/" + project + '/' + dir_in_project
dl.get(directory, dataset=path)
corr_type_list = []
@ -185,11 +199,7 @@ def read_data(path, project, dir_in_project, prefix, param, version='1.0c', cfg_
for key in data.keys():
key_parts = key.split(sep)
corr = key_parts[0]
if corr_types[corr] == 'bi':
specs = _map_params(param, key_parts[1:-1])
else:
specs = _map_params(param, key_parts[1:])
if corr not in sorted_data:
sorted_data[corr] = {}
sorted_data[corr][sep.join(key_parts[1:])] = data[key]
return sorted_data, specs
return sorted_data