$csv_in = @fopen(CSV_FILE_IN, "r"); $csv_out = @fopen(CSV_FILE_OUT, "w"); $array_temp = array("A" => array("X" => array(), "Y" => array()), "B" => array("X" => array(), "Y" => array())); $array_out = array(); $i = 0; while ($row_in = fgetcsv($csv_in)) { $index_value = array_search("TRUE", $row_in); $x_y = $index_value % 2 == 0 ? "Y" : "X"; $a_b = $index_value < 3 ? "A" : "B"; $code = $row_in[0]; echo "I" . $i++ . " | X/Y: {$x_y} | A/B : {$a_b} | CODE : {$code}\n"; fill_column($array_temp[$a_b][$x_y], $code, "array_our[{$a_b}][{$x_y}]"); $i++; } foreach ($array_temp as $A_B => $values) { $array_A_B = flip_array($values); foreach ($array_A_B as $item) { $item[] = $A_B; $array_out[] = $item; } } usort($array_out, "cmp_min"); foreach ($array_out as $row) { fputcsv($csv_out, $row); } function fill_column(&$array, $value, $log = "") { echo " Add {$value} to {$log}\n"; $array[] = $value; } function flip_array($array)
function perform_calculate_sensor_data() { //write_to_log(__FILE__,__LINE__,__FUNCTION__,'$_GET[countofcall]',$_GET['countofcall']); if ($_GET['countofcall'] == 0) { //write_to_log(__FILE__,__LINE__,__FUNCTION__,'$_GET[countofcall]',$_GET['countofcall']); // $data=read_sensor_data_old($_POST['consequent_id_1']); $data = read_sensor_data($_POST['consequent_id_1']); // print_r($_SESSION['$jt']); // $jt=$_SESSION['$jt']; $nodeId = $_GET['node']; $jt2 = gettree(); $jN = $jt2->getNode($nodeId); $jChildren = $jN->getChildren(); $row_count = 0; $child_data_row = array(); $t = 0; $child_data_ass = array(); foreach ($jChildren as $value) { // write_to_log(__FILE__,__LINE__,__FUNCTION__,'$value',$value); // write_to_log(__FILE__,__LINE__,__FUNCTION__,'$_SESSION['.$value.']["sensor_data_result_non_normalize_1"]',$_SESSION[$value]["sensor_data_result_non_normalize_1"]); if (isset($_SESSION[$value]["sensor_data_result_non_normalize_1"])) { $child_data_row[$t] = $_SESSION[$value]["sensor_data_result_non_normalize_1"]; $child_data_ass[$value] = $child_data_row[$t]; // echo'$child_data_ass<br>'; // print_r($child_data_ass); $t++; } } write_to_log(__FILE__, __LINE__, __FUNCTION__, '$child_data_ass', $child_data_ass); write_to_log(__FILE__, __LINE__, __FUNCTION__, '$child_data_row', $child_data_row); if (count($child_data_row) > 0) { $child_data = flip_array($child_data_row); write_to_log(__FILE__, __LINE__, __FUNCTION__, 'flipped $child_data_row', $child_data_row); if (!is_array($data)) { if ($data == 'FNF') { $data = $child_data; } } else { // $data = merge_array($data,$child_data); $data = merge_array_ass($data, $child_data_ass); $data = flip_array($data); } } else { $tmp = array(); foreach ($data as $x => $x_value) { $tmp[] = $x_value; } $data = $tmp; $data = flip_array($data); } write_to_log(__FILE__, __LINE__, __FUNCTION__, 'count($data)', count($data)); write_to_log(__FILE__, __LINE__, __FUNCTION__, '$data', $data); $rows = count($data); $cols = count($data[0]); // assumes non empty matrix // for($i=0;$i<$rows;$i++){ // for($j=0;$j<$cols;$j++){ // write_to_log(__FILE__,__LINE__,__FUNCTION__,'$data['.$i.']['.($j).']',$data[$i][($j)]); // } // } $_SESSION[$_GET['node']]['horizontalAxisLabel'] = array(); // write_to_log(__FILE__,__LINE__,__FUNCTION__,'$_SESSION['.$_GET['node'].'][horizontalAxisLabel]',$_SESSION[$_GET['node']]['horizontalAxisLabel']); for ($j = 1; $j <= $_POST['number_of_child']; $j++) { $_SESSION[$_GET['node']]['horizontalAxisLabel'][$j - 1] = $_POST['antecedent_id_' . $j]; $_SESSION[$_GET['node']]["sensor_data_result_" . $j] = array_fill(0, count($data), 0); $_SESSION[$_GET['node']]["sensor_graph_label_" . $j] = array_fill(0, count($data), 0); } write_to_log(__FILE__, __LINE__, __FUNCTION__, '$_SESSION[' . $_GET['node'] . '][horizontalAxisLabel]', $_SESSION[$_GET['node']]['horizontalAxisLabel']); for ($i = 0; $i < count($data); $i++) { for ($j = 1; $j <= $_POST['number_of_child']; $j++) { if (isset($_POST['antecedent_checked_input_' . $j]) && !empty($_POST['antecedent_checked_input_' . $j])) { write_to_log(__FILE__, __LINE__, __FUNCTION__, '$data[' . $i . '][' . ($j - 1) . ']', $data[$i][$j - 1]); $_POST['antecedent_input_' . $j] = $data[$i][$j - 1]; write_to_log(__FILE__, __LINE__, __FUNCTION__, '$_POST[antecedent_input_' . $j . ']', $_POST['antecedent_input_' . $j]); } } compute_rule_base($_POST['consequent_id_1'], $_POST['consequent_number_of_ref_val']); $input_Transformation = execute_Input_Transformation(); write_to_log(__FILE__, __LINE__, __FUNCTION__, '$input_Transformation', $input_Transformation); $resul1 = execute_Activation_Weight_Computation(); write_to_log(__FILE__, __LINE__, __FUNCTION__, 'execute_Activation_Weight_Computation : $resul1', $resul1); perform_update(); $resul1 = perform_aggregation(); write_to_log(__FILE__, __LINE__, __FUNCTION__, 'perform_aggregation $resul1', $resul1); for ($k = 1; $k <= $_POST['number_of_child']; $k++) { // write_to_log(__FILE__,__LINE__,__FUNCTION__,'after $_SESSION['.$_GET['node'].'][crisp_value]',$_SESSION[$_GET['node']]['crisp_value']); // $_SESSION[$_GET['node']]["sensor_data_result_".$k][$i]=convert_to_crisp(explode("-",$resul1)); $_SESSION[$_GET['node']]["sensor_data_result_" . $k][$i] = $_SESSION[$_GET['node']]['crisp_value']; $_SESSION[$_GET['node']]["sensor_data_result_non_normalize_" . $k][$i] = $_SESSION[$_GET['node']]['crisp_value']; if (isset($_POST['antecedent_checked_input_' . $k]) && !empty($_POST['antecedent_checked_input_' . $k])) { $_SESSION[$_GET['node']]["sensor_graph_label_" . $k][$i] = $data[$i][$k - 1]; } else { $_SESSION[$_GET['node']]["sensor_graph_label_" . $k][$i] = $_POST['antecedent_input_' . $k]; } // $_SESSION[$_GET['node']]['horizontalAxisLabel_'.$j]=$_POST['antecedent_id_'.$j]; } } // write_to_log(__FILE__,__LINE__,__FUNCTION__,'before normalize $_SESSION['.$_GET['node'].'][sensor_data_result_'.$k.']',$_SESSION[$_GET['node']]["sensor_data_result_".$k]); for ($k = 1; $k <= $_POST['number_of_child']; $k++) { write_to_log(__FILE__, __LINE__, __FUNCTION__, 'before normalize $_SESSION[' . $_GET['node'] . '][sensor_data_result_' . $k . ']', $_SESSION[$_GET['node']]["sensor_data_result_" . $k]); $_SESSION[$_GET['node']]["sensor_data_result_" . $k] = data_normalization($_SESSION[$_GET['node']]["sensor_data_result_" . $k]); $_SESSION[$_GET['node']]["sensor_data_result_" . $k][$i] = 'end'; // $_SESSION[$_GET['node']]["sensor_graph_label_".$k]=data_normalization($_SESSION[$_GET['node']]["sensor_graph_label_".$k]); $_SESSION[$_GET['node']]["sensor_graph_label_" . $k] = $_SESSION[$_GET['node']]["sensor_graph_label_" . $k]; write_to_log(__FILE__, __LINE__, __FUNCTION__, 'after normalize $_SESSION[' . $_GET['node'] . '][sensor_data_result_' . $k . ']', $_SESSION[$_GET['node']]["sensor_data_result_" . $k]); } } $dataTObeNormalize = array(); for ($k = 1; $k <= $_POST['number_of_child']; $k++) { write_to_log(__FILE__, __LINE__, __FUNCTION__, '$_SESSION[' . $_GET['node'] . '][sensor_data_result_' . $k . ']', $_SESSION[$_GET['node']]["sensor_data_result_" . $k]); write_to_log(__FILE__, __LINE__, __FUNCTION__, '$_SESSION[' . $_GET['node'] . '][sensor_graph_label_' . $k . ']', $_SESSION[$_GET['node']]["sensor_graph_label_" . $k]); $dataTObeNormalize[] = $_SESSION[$_GET['node']]["sensor_graph_label_" . $k]; } // print_r($dataTObeNormalize); // echo('max<br>'); // print_r(m_max($dataTObeNormalize)); // echo('min<br>'); // print_r(m_min($dataTObeNormalize)); return 'done'; }