Skip to content

Commit

Permalink
WIP: update transform model to send history
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed May 2, 2024
1 parent 26de401 commit b36ee43
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion chem_spectra/controller/transform_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def zip_jcamp_n_img():
tf_jcamp, tf_img, tf_csv, tf_nmrium = cmpsr.tf_jcamp(), cmpsr.tf_img(), cmpsr.tf_csv(), cmpsr.generate_nmrium()
spc_type = cmpsr.core.ncl if cmpsr.core.typ == 'NMR' else cmpsr.core.typ
if (tf_csv is not None and tf_csv != False):
memory = to_zip_response([tf_jcamp, tf_img, tf_csv])
if (cmpsr.core.is_cyclic_volta):
history_logs = cmpsr.generate_changed_history()
memory = to_zip_response([tf_jcamp, tf_img, tf_csv, history_logs])
else:
memory = to_zip_response([tf_jcamp, tf_img, tf_csv])
elif (tf_nmrium is not None):
memory = to_zip_response([tf_jcamp, tf_img, tf_nmrium])
else:
Expand Down
9 changes: 7 additions & 2 deletions chem_spectra/lib/composer/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,16 @@ def generate_changed_history(self):
if self.core.is_cyclic_volta == False:
return None

cyclicvolta = self.core.params.get('cyclicvolta', None)
params = self.core.params
cyclicvolta = params.get('cyclicvolta', None)

history_data = {}
if cyclicvolta is not None:
history_data = {}
jcamp_idx = params.get('jcamp_idx', 0)
spectra_list = cyclicvolta.get('spectraList', [])
if len(spectra_list) > 0:
current_history = spectra_list[jcamp_idx]
history_data = current_history

json_data = json.dumps(history_data)
tf_history_log = tempfile.NamedTemporaryFile(suffix='.json')
Expand Down
17 changes: 16 additions & 1 deletion tests/test_cyclic_volta.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def jcamp_file_cv():
def jcamp_file_1H():
return source_nmr

@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,}

def test_cv_base_converter(jcamp_file_cv):
jbcv = JcampBaseConverter(jcamp_file_cv)
assert jbcv.is_cyclic_volta == True
Expand Down Expand Up @@ -62,4 +66,15 @@ def test_ni_composer_generate_changed_history_cv_no_history(jcamp_file_cv):

with open(history_file.name) as log_file:
history = json.load(log_file)
assert history == {}
assert history == {}

def test_ni_composer_generate_changed_history_cv_has_history(jcamp_file_cv, cv_params):
base_converter = JcampBaseConverter(jcamp_file_cv)
base_converter.params = cv_params
ni_converter = JcampNIConverter(base=base_converter)
ni_composer = NIComposer(core=ni_converter)
history_file = ni_composer.generate_changed_history()

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,'isWorkMaxPeak':True,'jcampIdx':1,'shift':{'ref':None,'val':0,'prevValue':0},'hasRefPeak':False}

0 comments on commit b36ee43

Please sign in to comment.