//path_data : row are selected, 2 columns to be cropped ("time,id") //path_minmax : minmax, no crop is needed, leave "" for local MM //path_folder & filename : path to save //Auto Crop Column Name public static void ChangeAnalysis(string path_data_selected, string path_GlobalMM, string path_folder, string filename) { try { path_PE_localMM = path_folder + @"\[MinMax(local)].csv";//in case Local path_PE_vRank = path_folder + @"\" + filename + " F-Rank.csv"; path_PE_normal_extract = path_folder + @"\" + filename + " Extracted-03 Normalized.csv"; DataTable dt_temp = CSVReader.ReadCSVFile(path_data_selected, true); //have 2 unused col DataTable dt_data = TheTool.dataTable_cropCol(dt_temp, 2, 0); //only analyzed column DataTable dt_mm = null; //Datatable of MinMax //--- Prepare MinMax Table Boolean useGlobalMM = true; if (path_GlobalMM == "" || File.Exists(path_GlobalMM) == false) { useGlobalMM = false; } else { try { dt_mm = CSVReader.ReadCSVFile(path_GlobalMM, true); } catch (Exception ex) { TheSys.showError(ex); useGlobalMM = false; } } if (useGlobalMM == false) { //build MM table by local data dt_mm = TheTool.dataTable_getMaxMinTable(dt_data);//generate MM table TheTool.export_dataTable_to_CSV(path_PE_localMM, dt_mm); } try { DataTable dt_normal = TheTool.dataTable_MinMaxNormalization(dt_data, dt_mm); //--- Cal Change ------------------------------------- List <String> data_raw_change = ThePosExtract.process_calChange(dt_data, false, false); List <String> data_normal_change = ThePosExtract.process_calChange(dt_normal, true, true); List <String> data_ChangeAnalysis = new List <String>(); data_ChangeAnalysis.Add("RAW"); data_ChangeAnalysis.AddRange(data_raw_change); data_ChangeAnalysis.Add(""); data_ChangeAnalysis.Add(""); data_ChangeAnalysis.Add("NORMALIZED F-RANKING"); data_ChangeAnalysis.AddRange(data_normal_change); TheTool.exportCSV_orTXT(path_PE_vRank, data_ChangeAnalysis, false); //--- Normalize Table : re-added column before save dt_normal.Columns.Add("time", typeof(string)).SetOrdinal(0); dt_normal.Columns.Add("id", typeof(string)).SetOrdinal(0); int r = 0; foreach (DataRow row in dt_normal.Rows) { row[0] = dt_temp.Rows[r][0].ToString(); row[1] = dt_temp.Rows[r][1].ToString(); r++; } TheTool.export_dataTable_to_CSV(path_PE_normal_extract, dt_normal); } catch (Exception ex) { TheSys.showError("Normalize: " + ex.ToString()); } } catch (Exception ex) { TheSys.showError("Change Analysis: " + ex.ToString()); } }
//recompute = compute even data is already exist public List <int[]> getKeyPose(Boolean recompute, Boolean saveData) { if (Path.GetExtension(path_key) != ThePosExtract.extension_key) { path_key = ""; this.keyPose.Clear(); } if (recompute) { this.keyPose.Clear(); } if (this.keyPose.Count == 0) { if (path_key == "") { path_key = TheTool.getFilePathExcludeExtension_byPath(path) + ThePosExtract.extension_key; path_keyJ = TheTool.getFilePathExcludeExtension_byPath(path) + ".j"; } if (recompute == false) { this.keyPose = TheUKI.loadKeyPose(path_key);// .key is exist this.keyPoseJump = TheUKI.loadKeyJump(path_keyJ); } if (recompute || (this.keyPose.Count == 0 && !TheTool.checkPathExist(path_key))) { if (recompute == false && !TheTool.checkPathExist(path_key)) { TheSys.showError("Not Found: " + path_key); } this.keyPose = ThePosExtract.extractKeyPose(this); this.keyPoseJump = new List <int_double>(); this.keyPoseJump.AddRange(ThePosExtract.list_jump_selected); if (saveData) { TheUKI.exportKey(path_key, keyPose); if (ThePosExtract.capJumping) { TheUKI.exportKeyJ(path_keyJ, keyPoseJump); } } } } return(keyPose); }
public static List <int[]> extractKeyPose(Instance inst) { List <int[]> list_keyPose = new List <int[]>(); if (extractKeyPose_algo_selected == extractKeyPose_algo_sam) { list_keyPose.AddRange(ThePosExtract2.extractKeyPose_SamAlgo(inst)); } else if (extractKeyPose_algo_selected == extractKeyPose_algo_angular) { list_keyPose.AddRange(ThePosExtract2.extractKeyPose_Angular(inst)); } else { //My Algo list_keyPose.AddRange(ThePosExtract.extractKeyPose_MyAlgo(inst.getDataMove())); UKI_DataMovement_markGT(inst); } return(list_keyPose); }
int ang_techq = TheUKI.angTechq_SC_HC; //center to SC-HC public void exportFile(string fileName, string folderPrefix, Boolean posture_extraction, Boolean useGlobalMinMax, Boolean showDialog) { try { if (data_raw.Count() > 0) { List <string> temp; string folderPath = TheURL.url_saveFolder + folderPrefix + fileName; string folderPath_oth = folderPath + @"\oth"; string path_raw = folderPath + @"\" + fileName + ".csv"; string path_center_suffix = " (center" + TheUKI.getCenterTechqName(center_techq) + ")"; string path_raw_centered = folderPath + @"\" + fileName + path_center_suffix + ".csv"; string path_bp = folderPath + @"\" + fileName + " Atomic.csv"; string path_log = folderPath_oth + @"\" + fileName + " Log.csv"; string path_plus = folderPath_oth + @"\" + fileName + " Plus.csv"; string path_movement = folderPath_oth + @"\" + fileName + " Movement.csv"; string path_GlobalMM = TheURL.url_saveFolder + "[MinMax].csv";//in case Global if (useGlobalMinMax == false) { path_GlobalMM = ""; } TheTool.Folder_CreateIfMissing(folderPath); TheTool.Folder_CreateIfMissing(folderPath_oth); //--- RAW ------------------------------------------- TheUKI.saveData_Raw(path_raw, data_raw); //--- RAW center to HipC ---------------------------- List <UKI_DataRaw> data_raw_centered = TheUKI.raw_centerBodyJoint(data_raw, center_techq); TheUKI.saveData_Raw_centered(path_raw_centered, data_raw_centered, center_techq); //--- Basic Posture --------------------------------- List <string> data_bp_final = new List <string>(); data_bp_final.Add(TheUKI.data_bp_header()); data_bp_final.AddRange(TheUKI.getBasicPostureData(data_bp)); TheTool.exportCSV_orTXT(path_bp, data_bp_final, false); //--- Log : Additional Data (Non-Analysis) ---------- List <string> data_log_final = new List <string>(); data_log_final.Add(TheUKI.data_log_header); data_log_final.AddRange(data_log); TheTool.exportCSV_orTXT(path_log, data_log_final, false); //----- Movement Data --------------------------- List <UKI_DataMovement> data_movement_adjusted = TheUKI.adjustMovementData(data_movement); if (!posture_extraction) { TheUKI.exportData_Movement(data_movement_adjusted, path_movement, false); } //--- Additional Data For Analysis ----------------------- List <string> data_addition_full = TheUKI.createData_Additional(data_raw, data_raw_centered, data_add_01, center_techq); temp = new List <string>();//data_addition_full with header temp.Add(TheUKI.data_addition_full_header); temp.AddRange(data_addition_full); TheTool.exportCSV_orTXT(path_plus, temp, false); //=================================================================== if (posture_extraction) { string folderPath_PE = folderPath + @"\PosExtract"; string folderPath_Sparse = folderPath + @"\Sparse"; string folderPath_Entropy = folderPath + @"\Entropy"; // string path_note = folderPath + @"\note.txt"; string path_plus_normal = folderPath_oth + @"\" + fileName + " Plus Normal.csv"; string path_plus_discrete = folderPath_oth + @"\" + fileName + " Plus Descrete.csv"; string path_ang = folderPath_oth + @"\" + fileName + " ANG(" + TheUKI.getAngTechqName(ang_techq) + ").csv"; // string path_PE_raw_centered_extract = folderPath_PE + @"\" + fileName + " Extracted-01" + path_center_suffix + ".csv"; string path_PE_addition_extract = folderPath_PE + @"\" + fileName + " Extracted-02 Plus.csv"; // string path_raw_en = folderPath_Entropy + @"\" + fileName + " Entropy-01 RAW.csv"; string path_raw_centered_en = folderPath_Entropy + @"\" + fileName + " Entropy-02 RAW" + path_center_suffix + ".csv"; string path_plus_normal_en = folderPath_Entropy + @"\" + fileName + " Entropy-03 Plus Normal.csv"; string path_plus_discrete_en = folderPath_Entropy + @"\" + fileName + " Entropy-04 Plus Discrete.csv"; string path_ang_en = folderPath_Entropy + @"\" + fileName + " Entropy-11 ANG.csv"; string path_dist_en = folderPath_Entropy + @"\" + fileName + " Entropy-12 Dist.csv"; // TheTool.Folder_CreateIfMissing(folderPath_PE); TheTool.Folder_CreateIfMissing(folderPath_Sparse); TheTool.Folder_CreateIfMissing(folderPath_Entropy); //--- Normalize & Discretize ------------------------- DataTable data_addition_normalized = ThePosExtract.getNormalizedTable(path_plus, path_GlobalMM, true); TheTool.export_dataTable_to_CSV(path_plus_normal, data_addition_normalized); DataTable data_discritized = TheTool.dataTable_discritize10Partition(data_addition_normalized); TheTool.export_dataTable_to_CSV(path_plus_discrete, data_discritized); //----- Angle Data ---------------------------------------- List <UKI_DataAngular> data_ang = TheUKI.calAngle_fromRaw(data_raw, ang_techq); TheUKI.saveData_Ang(path_ang, data_ang);//save original //----- (Prepare Key List) ---------------------- List <int[]> list_keyPose_Range = new List <int[]>(); list_keyPose_Range.AddRange(ThePosExtract.extractKeyPose_MyAlgo(data_movement_adjusted)); List <int> list_keyPose_ID = new List <int>(); list_keyPose_ID.AddRange(ThePosExtract.getKeyPose_ID_StartEnd(list_keyPose_Range)); //----- Movement Data --------------------------- TheUKI.exportData_Movement(data_movement_adjusted, path_movement, true);//must be after "calMinimaMaxima" //----- Basic Posture Analysis ------------------ List <UKI_Data_BasicPose> data_bp_selected = TheTool.list_SelectRow(data_bp, list_keyPose_ID); ThePosExtract.BasicPostureAnalysis(data_bp_selected, true); TheTool.exportFile(ThePosExtract.log_BasicPostureAnalysis, path_note, false); TheSys.showError(ThePosExtract.log_BasicPostureAnalysis); //----- Raw Extracted Data ---------------------------- List <UKI_DataRaw> data_raw_selected = TheTool.list_SelectRow(data_raw_centered, list_keyPose_ID); TheUKI.saveData_Raw_centered(path_PE_raw_centered_extract, data_raw_selected, center_techq); //----- Addition Extracted Data ---------------------------- List <String> data_addition_selected = TheTool.list_SelectRow(data_addition_full, list_keyPose_ID); temp = new List <string>();//data_addition_full with header temp.Add(TheUKI.data_addition_full_header); temp.AddRange(data_addition_selected); TheTool.exportCSV_orTXT(path_PE_addition_extract, temp, false); //======= Feature Selecting Using Delta Analysis ========================== ThePosExtract.ChangeAnalysis(path_PE_addition_extract, path_GlobalMM, folderPath_PE, fileName); //======= Feature Selecting Using MI ====================================== //======= Entropy ========================================================= ThePosExtract.UKI_CalEntropy_Angle(path_ang_en, path_ang, list_keyPose_Range); ThePosExtract.UKI_CalEntropy_Eu(path_dist_en, path_raw, list_keyPose_Range); ThePosExtract.UKI_CalEntropy_1By1(path_raw_en, path_raw, list_keyPose_Range); ThePosExtract.UKI_CalEntropy_1By1(path_raw_centered_en, path_raw_centered, list_keyPose_Range); ThePosExtract.UKI_CalEntropy_1By1(path_plus_normal_en, path_plus_normal, list_keyPose_Range); ThePosExtract.UKI_CalEntropy_1By1(path_plus_discrete_en, path_plus_discrete, list_keyPose_Range); //======= Oth ========================================================= //---- Paper : Sparse --------------------- CalSparse_XYZ.calSparse(data_raw_selected, folderPath_Sparse + @"\", fileName);//cal & export } if (showDialog) { System.Windows.MessageBox.Show(@"Save to '" + folderPath + "'", "Export Data"); } } } catch (Exception ex) { TheSys.showError("Export: " + ex); } }
private void butUKIconvert_Click(object sender, RoutedEventArgs e) { String fileName; String path_raw; String path_raw_centered; String path_ang; String path_ang_en; String path_raw_en; String path_dist_en; int ang_techq = comboAngTech.SelectedIndex; //center of angle int center_techq = comboRawCenter.SelectedIndex; //center of body position foreach (DataRow r in dataTable.Rows) { path_raw = r[col_path].ToString(); fileName = TheTool.getFileName_byPath(path_raw); TheTool.Folder_CreateIfMissing(path_folder_convert + fileName); String path_sub_folder = path_folder_convert + fileName + @"\"; path_raw_centered = path_sub_folder + fileName + " (center" + TheUKI.getCenterTechqName(center_techq) + ").csv"; path_ang = path_sub_folder + fileName + " ANG(" + TheUKI.getAngTechqName(ang_techq) + ").csv"; path_ang_en = path_sub_folder + fileName + " ANG_Entropy.csv"; path_raw_en = path_sub_folder + fileName + " RAW_Entropy.csv"; path_dist_en = path_sub_folder + fileName + " Dist_Entropy.csv"; if (center_techq > 0) { path_raw_en = path_sub_folder + fileName + " (center" + TheUKI.getCenterTechqName(center_techq) + ") RAW_Entropy.csv"; } //----- Raw ----- List <UKI_DataRaw> list_raw = TheUKI.csv_loadFileTo_DataRaw(path_raw, 0); //----- Angle --------- List <UKI_DataAngular> list_ang = TheUKI.calAngle_fromRaw(list_raw, ang_techq); if (checkUKI_Angle.IsChecked.Value || checkUKI_E_Angle.IsChecked.Value) { TheUKI.saveData_Ang(path_ang, list_ang); } //--------------------- //List<int> keyPostureId = UKI_getKeyPostureId(); List <int[]> keyPostureRange = ThePosExtract.getKetPose_Range_from1String(txtUKI_keyID.Text); //----- Angle Entropy --------- if (checkUKI_E_Angle.IsChecked.Value) { ThePosExtract.UKI_CalEntropy_Angle(path_ang_en, path_ang, keyPostureRange); } //----- Dist --------- if (checkUKI_E_Dist.IsChecked.Value) { ThePosExtract.UKI_CalEntropy_Eu(path_dist_en, path_raw, keyPostureRange); } //----- XYZ Entropy --------- if (checkUKI_E_XYZ.IsChecked.Value) { if (center_techq > 0) { List <UKI_DataRaw> list_raw_centered = TheUKI.raw_centerBodyJoint(list_raw, center_techq); TheUKI.saveData_Raw_centered(path_raw_centered, list_raw_centered, center_techq); ThePosExtract.UKI_CalEntropy_1By1(path_raw_en, path_raw_centered, keyPostureRange); } else { ThePosExtract.UKI_CalEntropy_1By1(path_raw_en, path_raw, keyPostureRange); } } } System.Windows.MessageBox.Show(@"Save to file\[Convert]"); }