diff --git a/chem_spectra/controller/transform_api.py b/chem_spectra/controller/transform_api.py index 8bdb823..ac13ea9 100644 --- a/chem_spectra/controller/transform_api.py +++ b/chem_spectra/controller/transform_api.py @@ -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: diff --git a/chem_spectra/lib/composer/ni.py b/chem_spectra/lib/composer/ni.py index 9dba734..127bc7c 100644 --- a/chem_spectra/lib/composer/ni.py +++ b/chem_spectra/lib/composer/ni.py @@ -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') diff --git a/tests/test_cyclic_volta.py b/tests/test_cyclic_volta.py index 96b6cc7..8d95b09 100644 --- a/tests/test_cyclic_volta.py +++ b/tests/test_cyclic_volta.py @@ -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 @@ -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 == {} \ No newline at end of file + 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} \ No newline at end of file