Skip to content

Commit

Permalink
feat: only store history and origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed May 7, 2024
1 parent 533a1e7 commit 0a97925
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 9 additions & 4 deletions chem_spectra/lib/composer/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,14 @@ def __generate_nmrim_ranges(self):

return dic_ranges

def __cleaning_history(self, history_data):
keywords_to_be_kept = ['origin', 'history']
cleaned_data = dict()
history_data_keys = history_data.keys()
for keyword in keywords_to_be_kept:
cleaned_data[keyword] = history_data[keyword] if keyword in history_data_keys else None
return cleaned_data

def generate_changed_history(self):
if self.core.is_cyclic_volta == False:
return None
Expand All @@ -837,10 +845,7 @@ def generate_changed_history(self):
spectra_list = cyclicvolta.get('spectraList', [])
if len(spectra_list) > 0:
current_history = spectra_list[jcamp_idx]
history_data = current_history
del history_data['isWorkMaxPeak']
del history_data['hasRefPeak']
del history_data['shift']
history_data = self.__cleaning_history(current_history)

json_data = json.dumps(history_data)
tf_history_log = tempfile.NamedTemporaryFile(suffix='.json')
Expand Down
8 changes: 6 additions & 2 deletions tests/test_cyclic_volta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def jcamp_file_1H():

@pytest.fixture
def cv_params():
return {'select_x':'','ref_name':'- - -','ref_value':'0','peaks_str':'-0.4890399999999999,-0.000033747399999999995#1.9294829999999998,0.00023741','delta':0.0,'mass':58.078250319999995,'scan':0,'thres':100.0,'clear':False,'integration':{'stack':[],'refArea':1,'refFactor':1,'shift':0},'multiplicity':{'stack':[],'smExtext':False,'shift':0},'ext':'jdx','fname':'File053_BagIt.2_bagit','waveLength':{'name':'CuKalpha','value':0.15406,'label':'Cu Kα','unit':'nm'},'list_max_min_peaks':[{'min':{'x':1.8095560000000002,'y':2.2759699999999998e-05},'max':{'x':1.919489,'y':0.00023641},'isRef':False,'e12':1.8645225,'pecker':None}],'cyclicvolta':{'spectraList':[{'list':[{'min':None,'max':None,'isRef':False,'e12':None}],'origin':[{'min':None,'max':None,'isRef':False,'e12':None}],'selectedIdx':0,'isWorkMaxPeak':True,'jcampIdx':-1,'shift':{'ref':None,'val':0,'prevValue':0},'hasRefPeak':False},{'list':[{'min':{'x':1.8095560000000002,'y':2.2759699999999998e-05},'max':{'x':1.919489,'y':0.00023641},'isRef':False,'e12':1.8645225,'pecker':None}],'origin':[{'min':{'x':1.8095560000000002,'y':2.2759699999999998e-05},'max':{'x':1.919489,'y':0.00023641},'isRef':False,'e12':1.8645225,'pecker':None}],'selectedIdx':0,'isWorkMaxPeak':True,'jcampIdx':1,'shift':{'ref':None,'val':0,'prevValue':0},'hasRefPeak':False},{'list':[{'min':None,'max':None,'isRef':False,'e12':None}],'origin':[{'min':None,'max':None,'isRef':False,'e12':None}],'selectedIdx':0,'isWorkMaxPeak':True,'jcampIdx':-1,'shift':{'ref':None,'val':0,'prevValue':0},'hasRefPeak':False}]},'jcamp_idx':1,'axesUnits':None,}
return {'select_x':'','ref_name':'- - -','ref_value':'0','peaks_str':'-2.3535625,-0.000033747399999999995#0.06496049999999998,0.00023741','delta':0.0,'mass':427.04192006100004,'scan':0,'thres':100.0,'clear':False,'integration':{'stack':[],'refArea':1,'refFactor':1,'shift':0},'multiplicity':{'stack':[],'smExtext':False,'shift':0},'ext':'jdx','fname':'File053_BagIt.2_bagit','waveLength':{'name':'CuKalpha','value':0.15406,'label':'Cu Kα','unit':'nm'},'list_max_min_peaks':[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084983575,'updatedAt':1715084983576,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}},{'max':{'x':0.3048175000000001,'y':0.000124783},'e12':0.41474750000000005,'updatedAt':1715084983576,'min':{'x':0.5246775,'y':6.0219799999999996e-05},'pecker':{'x':0.7245575000000001,'y':8.428259999999999e-05},'isRef':False}],'cyclicvolta':{'spectraList':[{'list':[{'min':None,'max':None,'isRef':False,'e12':None,'createdAt':1715084983575}],'origin':[{'min':None,'max':None,'isRef':False,'e12':None,'createdAt':1715084983575}],'selectedIdx':0,'isWorkMaxPeak':True,'jcampIdx':-1,'shift':{'ref':None,'val':0,'prevValue':0},'hasRefPeak':False,'history':[[{'min':{'x':-0.0699574999999999,'y':2.09159e-05},'max':{'x':0.0699575,'y':0.00023741},'isRef':True,'e12':5.551115123125783e-17,'createdAt':1715084679465,'updatedAt':1715084679466,'pecker':{'x':0.7295545000000001,'y':8.428259999999999e-05}}],[{'min':{'x':0.799562,'y':2.1740999999999997e-05},'max':{'x':0.929483,'y':0.00023741},'isRef':True,'e12':0.8645225,'createdAt':1715084770812,'updatedAt':1715084779867,'pecker':{'x':1.69901,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084770812,'updatedAt':1715084781429,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084846965,'updatedAt':1715084846965,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084983575,'updatedAt':1715084983576,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}},{'max':{'x':0.3048175000000001,'y':0.000124783},'e12':0.41474750000000005,'updatedAt':1715084983576,'min':{'x':0.5246775,'y':6.0219799999999996e-05},'pecker':{'x':0.7245575000000001,'y':8.428259999999999e-05},'isRef':False}]]},{'list':[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084983575,'updatedAt':1715084983576,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}},{'max':{'x':0.3048175000000001,'y':0.000124783},'e12':0.41474750000000005,'updatedAt':1715084983576,'min':{'x':0.5246775,'y':6.0219799999999996e-05},'pecker':{'x':0.7245575000000001,'y':8.428259999999999e-05},'isRef':False}],'origin':[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084983575,'updatedAt':1715084983576,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}},{'max':{'x':0.3048175000000001,'y':0.000124783},'e12':0.41474750000000005,'updatedAt':1715084983576,'min':{'x':0.5246775,'y':6.0219799999999996e-05},'pecker':{'x':0.7245575000000001,'y':8.428259999999999e-05},'isRef':False}],'selectedIdx':0,'isWorkMaxPeak':True,'jcampIdx':1,'shift':{'ref':None,'val':0,'prevValue':0},'hasRefPeak':True,'history':[[{'min':{'x':-0.0699574999999999,'y':2.09159e-05},'max':{'x':0.0699575,'y':0.00023741},'isRef':True,'e12':5.551115123125783e-17,'createdAt':1715084679465,'updatedAt':1715084679466,'pecker':{'x':0.7295545000000001,'y':8.428259999999999e-05}}],[{'min':{'x':0.799562,'y':2.1740999999999997e-05},'max':{'x':0.929483,'y':0.00023741},'isRef':True,'e12':0.8645225,'createdAt':1715084770812,'updatedAt':1715084779867,'pecker':{'x':1.69901,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084770812,'updatedAt':1715084781429,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084846965,'updatedAt':1715084846965,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084983575,'updatedAt':1715084983576,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}},{'max':{'x':0.3048175000000001,'y':0.000124783},'e12':0.41474750000000005,'updatedAt':1715084983576,'min':{'x':0.5246775,'y':6.0219799999999996e-05},'pecker':{'x':0.7245575000000001,'y':8.428259999999999e-05},'isRef':False}]]},{'list':[{'min':None,'max':None,'isRef':False,'e12':None,'createdAt':1715084983576}],'origin':[{'min':None,'max':None,'isRef':False,'e12':None,'createdAt':1715084983576}],'selectedIdx':0,'isWorkMaxPeak':True,'jcampIdx':-1,'shift':{'ref':None,'val':0,'prevValue':0},'hasRefPeak':False,'history':[[{'min':{'x':-0.0699574999999999,'y':2.09159e-05},'max':{'x':0.0699575,'y':0.00023741},'isRef':True,'e12':5.551115123125783e-17,'createdAt':1715084679465,'updatedAt':1715084679466,'pecker':{'x':0.7295545000000001,'y':8.428259999999999e-05}}],[{'min':{'x':0.799562,'y':2.1740999999999997e-05},'max':{'x':0.929483,'y':0.00023741},'isRef':True,'e12':0.8645225,'createdAt':1715084770812,'updatedAt':1715084779867,'pecker':{'x':1.69901,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084770812,'updatedAt':1715084781429,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084846965,'updatedAt':1715084846965,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}}],[{'min':{'x':-0.06496049999999998,'y':2.1740999999999997e-05},'max':{'x':0.06496049999999998,'y':0.00023741},'isRef':True,'e12':0,'createdAt':1715084983575,'updatedAt':1715084983576,'pecker':{'x':0.8344874999999999,'y':7.92825e-05}},{'max':{'x':0.3048175000000001,'y':0.000124783},'e12':0.41474750000000005,'updatedAt':1715084983576,'min':{'x':0.5246775,'y':6.0219799999999996e-05},'pecker':{'x':0.7245575000000001,'y':8.428259999999999e-05},'isRef':False}]]}]},'jcamp_idx':1,}

def test_cv_base_converter(jcamp_file_cv):
jbcv = JcampBaseConverter(jcamp_file_cv)
Expand Down Expand Up @@ -77,4 +77,8 @@ def test_ni_composer_generate_changed_history_cv_has_history(jcamp_file_cv, cv_p

with open(history_file.name) as log_file:
history = json.load(log_file)
assert history == {'list':[{'min':{'x':1.8095560000000002,'y':2.2759699999999998e-05},'max':{'x':1.919489,'y':0.00023641},'isRef':False,'e12':1.8645225,'pecker':None}],'origin':[{'min':{'x':1.8095560000000002,'y':2.2759699999999998e-05},'max':{'x':1.919489,'y':0.00023641},'isRef':False,'e12':1.8645225,'pecker':None}],'selectedIdx':0,'jcampIdx':1}
# assert history == {'list':[{'min':{'x':1.8095560000000002,'y':2.2759699999999998e-05},'max':{'x':1.919489,'y':0.00023641},'isRef':False,'e12':1.8645225,'pecker':None}],'origin':[{'min':{'x':1.8095560000000002,'y':2.2759699999999998e-05},'max':{'x':1.919489,'y':0.00023641},'isRef':False,'e12':1.8645225,'pecker':None}]}
assert history == {
'origin': [{'min': {'x': -0.06496049999999998, 'y': 2.1740999999999997e-05}, 'max': {'x': 0.06496049999999998, 'y': 0.00023741}, 'isRef': True, 'e12': 0, 'createdAt': 1715084983575, 'updatedAt': 1715084983576, 'pecker': {'x': 0.8344874999999999, 'y': 7.92825e-05}}, {'max': {'x': 0.3048175000000001, 'y': 0.000124783}, 'e12': 0.41474750000000005, 'updatedAt': 1715084983576, 'min': {'x': 0.5246775, 'y': 6.0219799999999996e-05}, 'pecker': {'x': 0.7245575000000001, 'y': 8.428259999999999e-05}, 'isRef': False}],
'history': [[{'min': {'x': -0.0699574999999999, 'y': 2.09159e-05}, 'max': {'x': 0.0699575, 'y': 0.00023741}, 'isRef': True, 'e12': 5.551115123125783e-17, 'createdAt': 1715084679465, 'updatedAt': 1715084679466, 'pecker': {'x': 0.7295545000000001, 'y': 8.428259999999999e-05}}], [{'min': {'x': 0.799562, 'y': 2.1740999999999997e-05}, 'max': {'x': 0.929483, 'y': 0.00023741}, 'isRef': True, 'e12': 0.8645225, 'createdAt': 1715084770812, 'updatedAt': 1715084779867, 'pecker': {'x': 1.69901, 'y': 7.92825e-05}}], [{'min': {'x': -0.06496049999999998, 'y': 2.1740999999999997e-05}, 'max': {'x': 0.06496049999999998, 'y': 0.00023741}, 'isRef': True, 'e12': 0, 'createdAt': 1715084770812, 'updatedAt': 1715084781429, 'pecker': {'x': 0.8344874999999999, 'y': 7.92825e-05}}], [{'min': {'x': -0.06496049999999998, 'y': 2.1740999999999997e-05}, 'max': {'x': 0.06496049999999998, 'y': 0.00023741}, 'isRef': True, 'e12': 0, 'createdAt': 1715084846965, 'updatedAt': 1715084846965, 'pecker': {'x': 0.8344874999999999, 'y': 7.92825e-05}}], [{'min': {'x': -0.06496049999999998, 'y': 2.1740999999999997e-05}, 'max': {'x': 0.06496049999999998, 'y': 0.00023741}, 'isRef': True, 'e12': 0, 'createdAt': 1715084983575, 'updatedAt': 1715084983576, 'pecker': {'x': 0.8344874999999999, 'y': 7.92825e-05}}, {'max': {'x': 0.3048175000000001, 'y': 0.000124783}, 'e12': 0.41474750000000005, 'updatedAt': 1715084983576, 'min': {'x': 0.5246775, 'y': 6.0219799999999996e-05}, 'pecker': {'x': 0.7245575000000001, 'y': 8.428259999999999e-05}, 'isRef': False}]]
}

0 comments on commit 0a97925

Please sign in to comment.