93 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			93 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import os
 | ||
| 
 | ||
| from global_var import global_var_init
 | ||
| cycle, fs, record_name, data_path = global_var_init()
 | ||
| 
 | ||
| from processing import processing
 | ||
| (signal_dwt , waves_dwt , rpeaks , ecg_signal,
 | ||
|  signal, signal.v, signal.fs, rows_to_extract, t_ecg, t_ppg,
 | ||
|  on_column_list, on_column_list_toArea, on_values, on_values_toArea,
 | ||
|  sp_column_list, sp_values, dn_column_list, dn_values, dp_column_list,
 | ||
|  dp_values, u_column_list, u_column_list_toArea, u_values, u_values_toArea,
 | ||
|  v_column_list, v_values, w_column_list, w_values, a_column_list, a_column_list_toArea,
 | ||
|  a_values, a_values_toArea, b_column_list, b_values, c_column_list, c_values,
 | ||
|  e_column_list, e_values, f_column_list, f_values,
 | ||
|  signal.ppg, signal.vpg, signal.apg, signal.jpg) = processing()
 | ||
| 
 | ||
| from ecg_clean_nan import ecg_clean_nan 
 | ||
| (waves_dwt['ECG_P_Onsets'],waves_dwt['ECG_P_Offsets'],waves_dwt['ECG_T_Onsets'],
 | ||
|  waves_dwt['ECG_T_Offsets'],waves_dwt['ECG_P_Peaks'] ,waves_dwt['ECG_Q_Peaks'],
 | ||
|  rpeaks['ECG_R_Peaks'],waves_dwt['ECG_S_Peaks'],waves_dwt['ECG_T_Peaks']) = ecg_clean_nan()
 | ||
| 
 | ||
| # 将它们放到字典中
 | ||
| data_dict_ecg = {
 | ||
| 
 | ||
|     'ECG_P_Onsets': waves_dwt['ECG_P_Onsets'][:cycle],
 | ||
|     'ECG_P_Offsets': waves_dwt['ECG_P_Offsets'][:cycle],
 | ||
|     'ECG_T_Onsets': waves_dwt['ECG_T_Onsets'][:cycle],
 | ||
|     'ECG_T_Offsets': waves_dwt['ECG_T_Offsets'][:cycle],
 | ||
|     'ECG_P_Peaks': waves_dwt['ECG_P_Peaks'][:cycle],
 | ||
|     'ECG_Q_Peaks': waves_dwt['ECG_Q_Peaks'][:cycle],
 | ||
|     'ECG_R_Peaks': rpeaks['ECG_R_Peaks'][:cycle],
 | ||
|     'ECG_S_Peaks': waves_dwt['ECG_S_Peaks'][:cycle],
 | ||
|     'ECG_T_Peaks': waves_dwt['ECG_T_Peaks'][:cycle],
 | ||
| 
 | ||
| }
 | ||
| 
 | ||
| data_dict_ppg ={
 | ||
| 
 | ||
|     'on_column_list': on_column_list[:cycle],
 | ||
|     'on_column_list_toArea': on_column_list_toArea[:cycle+1],
 | ||
|     'sp_column_list': sp_column_list[:cycle],
 | ||
|     'dn_column_list': dn_column_list[:cycle],
 | ||
|     'dp_column_list': dp_column_list[:cycle]
 | ||
| 
 | ||
| }
 | ||
| 
 | ||
| data_dict_vpg ={
 | ||
| 
 | ||
|     'u_column_list': u_column_list[:cycle],
 | ||
|     'u_column_list_toArea': u_column_list_toArea[:cycle+1],
 | ||
|     'v_column_list': v_column_list[:cycle],
 | ||
|     'w_column_list': w_column_list[:cycle]
 | ||
| }
 | ||
| 
 | ||
| data_dict_apg ={
 | ||
| 
 | ||
|     'a_column_list': a_column_list[:cycle],
 | ||
|     'a_column_list_toArea': a_column_list_toArea[:cycle+1],
 | ||
|     'b_column_list': b_column_list[:cycle],
 | ||
|     'c_column_list': c_column_list[:cycle],
 | ||
|     'e_column_list': e_column_list[:cycle],
 | ||
|     'f_column_list': f_column_list[:cycle]
 | ||
| }
 | ||
| 
 | ||
| #--------------------------------------------------------------------------------------------------------
 | ||
| #--------------------------------------------------------------------------------------------------------
 | ||
| #--------------------------------------------------------------------------------------------------------
 | ||
| #--------------------------------------------------------------------------------------------------------
 | ||
| #--------------------------------         将坐标保存为文本        ----------------------------------------
 | ||
| #--------------------------------------------------------------------------------------------------------
 | ||
| #--------------------------------------------------------------------------------------------------------
 | ||
| #--------------------------------------------------------------------------------------------------------
 | ||
| #--------------------------------------------------------------------------------------------------------
 | ||
| 
 | ||
| def save_to_file(data_dict, directory):
 | ||
|     os.makedirs(directory, exist_ok=True)
 | ||
|     for key, value in data_dict.items():
 | ||
|         file_path = os.path.join(directory, f"{key}.txt")
 | ||
|         with open(file_path, "w") as f:
 | ||
|             f.write(",".join(map(str, value)))
 | ||
|         print(f"保存到文件: {file_path}")
 | ||
| 
 | ||
| 
 | ||
| if __name__ == '__main__':
 | ||
| 
 | ||
|     save_to_file(data_dict_ecg, f"D://python_study//big_boss//doc//points_coordinates_update//{record_name}//ECG")
 | ||
|     save_to_file(data_dict_ppg, f"D://python_study//big_boss//doc//points_coordinates_update//{record_name}//PPG")
 | ||
|     save_to_file(data_dict_vpg, f"D://python_study//big_boss//doc//points_coordinates_update//{record_name}//VPG")
 | ||
|     save_to_file(data_dict_apg, f"D://python_study//big_boss//doc//points_coordinates_update//{record_name}//APG")
 | ||
|     print("所有txt文件中已生成完毕!")
 | ||
|     
 | ||
| 
 |