$values = array(5, 6, 8, 9); /** * Calculate the mean of a series of numbers. */ function mean($values) { assert('is_numeric_array($values)'); return array_sum($values) / count($values); } function variance($values) { $mean = mean($values); $num = count($values); $x = 0; foreach ($values as $value) { $diff = $value - $mean; $x += $diff * $diff; } $variance = $x / $num; return $variance; } function stddev($values) { return sqrt(variance($values)); } header('Content-type: text/plain'); var_dump(join(', ', $values)); var_dump(mean($values)); var_dump(variance($values)); var_dump(stddev($values));
if ($torecord == 'cc') { $score = dispscore(max($scorerec[$qn])); } else { $score = dispscore(min($scorerec[$qn])); } if (isset($_GET['details'])) { $score .= ' ; ' . count($scorerec[$qn]) . ' ; '; } else { $score .= '(' . count($scorerec[$qn]) . ')'; $score .= '<br/>'; } $score .= dispscore($scorerec[$qn][count($scorerec[$qn]) - 1]); if (isset($_GET['details'])) { $score .= ' ; ' . dispscore(round(array_sum($scorerec[$qn]) / count($scorerec[$qn]), 1)); if (count($scorerec[$qn]) > 1) { $score .= ' ; ' . round(stddev($scorerec[$qn]), 1); } else { $score .= ' ; 0'; } } } else { $score = 'N/A'; } $rowdata[] = $score; } $studata[] = $rowdata; } $placeinhead = '<script type="text/javascript">function highlightrow(el) { el.setAttribute("lastclass",el.className); el.className = "highlight";}'; $placeinhead .= 'function unhighlightrow(el) { el.className = el.getAttribute("lastclass");}</script>'; $placeinhead .= "<script type=\"text/javascript\" src=\"{$imasroot}/javascript/tablesorter.js?v=012811\"></script>\n"; require "../header.php";
public function index($id = NULL) { //pr($this->request->data); if ($this->request->data) { //echo "if"; //pr($_REQUEST); //pr($this->request->data);exit; $certificateno = $this->request->data['step1']['certificateno']; $readingtype_id = $this->request->data['step1']['readingtype_id']; $channel_id = $this->request->data['step1']['channel_id']; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //pr($this->request->data['step1']); function myfunction($num) { if (is_float($num)) { return abs($num); } else { return $num; } } $a = $b = array(); $a = $this->request->data['step1']; //pr($a); $b = array_map("myfunction", $a); $this->request->data['step1'] = $b; //$temp1= $this->request->data['step1']['temp1']; $find_cert = $this->Tempcertificatedata->find('first', array('conditions' => array('Tempcertificatedata.certificate_no' => $certificateno, 'Tempcertificatedata.temp_readingtype_id' => $readingtype_id, 'Tempcertificatedata.temp_channel_id' => $channel_id))); //pr($find_cert);exit; if ($find_cert) { if (isset($this->request->data['step1']['uncertainty1_val'])) { $uncertainty1_val1 = $this->request->data['step1']['uncertainty1_val']; $uncertainty1_val = implode(',', $uncertainty1_val1); } if (isset($uncertainty1_val)) { $this->request->data['step1']['uncertainty1_val'] = $uncertainty1_val; } if (isset($this->request->data['step1']['uncertainty2_val'])) { $uncertainty2_val1 = $this->request->data['step1']['uncertainty2_val']; $uncertainty2_val = implode(',', $uncertainty2_val1); } if (isset($uncertainty2_val)) { $this->request->data['step1']['uncertainty2_val'] = $uncertainty2_val; } if (isset($this->request->data['step1']['uncertainty3_val'])) { $uncertainty3_val1 = $this->request->data['step1']['uncertainty3_val']; $uncertainty3_val = implode(',', $uncertainty3_val1); } if (isset($uncertainty3_val)) { $this->request->data['step1']['uncertainty3_val'] = $uncertainty3_val; } if (isset($this->request->data['step1']['uncertainty4_val'])) { $uncertainty4_val1 = $this->request->data['step1']['uncertainty4_val']; $uncertainty4_val = implode(',', $uncertainty4_val1); } if (isset($uncertainty4_val)) { $this->request->data['step1']['uncertainty4_val'] = $uncertainty4_val; } //pr($this->request->data);exit; if (isset($this->request->data['step1']['uncertainty5_val'])) { $uncertainty5_val1 = $this->request->data['step1']['uncertainty5_val']; $uncertainty5_val = implode(',', $uncertainty5_val1); } if (isset($uncertainty5_val)) { $this->request->data['step1']['uncertainty5_val'] = $uncertainty5_val; } function stddev($array) { //Don Knuth is the $deity of algorithms //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#III._On-line_algorithm $n = 0; $mean = 0; $M2 = 0; foreach ($array as $x) { $n++; $delta = $x - $mean; $mean = $mean + $delta / $n; $M2 = $M2 + $delta * ($x - $mean); } $variance = $M2 / ($n - 1); return sqrt($variance); } function stddev1($array) { //Don Knuth is the $deity of algorithms //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#III._On-line_algorithm $n = 0; $mean = 0; $M2 = 0; foreach ($array as $x) { $n++; $delta = $x - $mean; $mean = $mean + $delta / $n; $M2 = $M2 + $delta * ($x - $mean); } $variance = $M2 / ($n - 1); return sqrt($variance); } function stddev2($array) { //Don Knuth is the $deity of algorithms //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#III._On-line_algorithm $n = 0; $mean = 0; $M2 = 0; foreach ($array as $x) { $n++; $delta = $x - $mean; $mean = $mean + $delta / $n; $M2 = $M2 + $delta * ($x - $mean); } $variance = $M2 / ($n - 1); return sqrt($variance); } function t1($val, $min, $max) { return $val >= $min && $val <= $max; } function powfn($para) { return $para * $para; } function powfn4($para) { return $para * $para * $para * $para; } if (isset($this->request->data['step1']['no_runs'])) { //$aaaaaa = array(); // Twin FOR for ($j = 1; $j <= 15; $j++) { $arr1 = array(); //array_unique $summed_val_m = 0; $array_sd_m = array(); $sd_m = 0; $mean_m = 0; // Data Pack //$uncert_data_pack = datapack($this->request->data['step1']['temp'.$j],$this->request->data['step1']['uncertainty'.$j.'_val']); for ($i = 1; $i <= 15; $i++) { if (isset($this->request->data['step1']['m' . $j . '_' . $i . ''])) { $summed_val_m = $summed_val_m + $this->request->data['step1']['m' . $j . '_' . $i . '']; $array_sd_m[] = $this->request->data['step1']['m' . $j . '_' . $i . '']; } } //pr($array_sd_m); exit; $this->request->data['step1']['m' . $j . '_12'] = $sd_m = stddev($array_sd_m); $this->request->data['step1']['m' . $j . '_13'] = $sd_m / sqrt($this->request->data['step1']['no_runs']); $this->request->data['step1']['m' . $j . '_11'] = $mean_m = $summed_val_m / $this->request->data['step1']['no_runs']; $summed_val_b = 0; $array_sd_b = array(); $sd_b = 0; $mean_b = 0; for ($i = 1; $i <= 15; $i++) { if (isset($this->request->data['step1']['b' . $j . '_' . $i . ''])) { $summed_val_b = $summed_val_b + $this->request->data['step1']['b' . $j . '_' . $i . '']; $array_sd_b[] = $this->request->data['step1']['b' . $j . '_' . $i . '']; } } $this->request->data['step1']['b' . $j . '_12'] = $sd_b = stddev1($array_sd_b); $this->request->data['step1']['b' . $j . '_13'] = $sd_b / sqrt($this->request->data['step1']['no_runs']); $this->request->data['step1']['b' . $j . '_11'] = $mean_b = $summed_val_b / $this->request->data['step1']['no_runs']; //pr($sd_b); if (isset($this->request->data['total']['is_afteradjust'])) { $summed_val_a = 0; $array_sd_a = array(); $sd_a = 0; $mean_a = 0; for ($i = 1; $i <= 15; $i++) { if (isset($this->request->data['step1']['a' . $j . '_' . $i . ''])) { $summed_val_a = $summed_val_a + $this->request->data['step1']['a' . $j . '_' . $i . '']; $array_sd_a[] = $this->request->data['step1']['a' . $j . '_' . $i . '']; } } $this->request->data['step1']['a' . $j . '_12'] = $sd_a = stddev2($array_sd_a); $this->request->data['step1']['a' . $j . '_13'] = $sd_a / sqrt($this->request->data['step1']['no_runs']); //pr($sd_a); $this->request->data['step1']['a' . $j . '_11'] = $mean_a = $summed_val_a / $this->request->data['step1']['no_runs']; } $uncer_va = array(); $arr1 = array(); static $aaaaaa = array(); if (isset($this->request->data['step1']['uncertainty' . $j . '_val'])) { $uncer_va = explode(',', $this->request->data['step1']['uncertainty' . $j . '_val']); } //pr($uncer_va); foreach ($uncer_va as $u) { $tempuncertaintydata1 = $this->Tempuncertaintydata->find('all', array('conditions' => array('Tempuncertaintydata.temp_uncertainty_id' => $u))); //pr($tempuncertaintydata1); foreach ($tempuncertaintydata1 as $tempuncertaintydata2) { $rangeid = $tempuncertaintydata2['Tempuncertaintydata']['range_id']; $range_dat = $this->Temprange->find('first', array('conditions' => array('Temprange.id' => $rangeid), 'recursive' => '2')); //pr($range_dat); $temp_val = $this->request->data['step1']['temp' . $j]; //pr($temp_val); if ($range_dat) { if ($range_dat['Temprange']['fromrange'] != '' || $range_dat['Temprange']['torange'] != '') { // pr($range_dat['Temprange']['fromrange']);pr($range_dat['Temprange']['torange']); $yesorno = t1($temp_val, $range_dat['Temprange']['fromrange'], $range_dat['Temprange']['torange']); } else { $yesorno = false; } //pr($yesorno); if ($yesorno == true) { $aaaaaa[] = $arr1[] = $tempuncertaintydata2['Tempuncertaintydata']['id']; } } } } //pr($arr1); // if($this->request->data['step1']['temp'.$j]!= NULL) // { // //$arra2 = // $aaaaaa = implode(',',array($aaaaaa); // // } // pr($arr1); // if($j == 15) // { //$comparable_uncert = array('22','23','22'); // if(count($arr1)!=1) // { // $comparable_uncert = array_unique($arr1); // } // else // { $comparable_uncert = $arr1; //} //pr($comparable_uncert);exit; //$uncertainty[] = array(); //pr($comparable_uncert);exit; //$count_al = $this->request->data['step1']['count'.$j]; $vc = array(); foreach ($comparable_uncert as $comcert) { //pr($comcert); $step1infor = $this->Tempuncertaintydata->find('first', array('conditions' => array('Tempuncertaintydata.id' => $comcert))); // pr($step1infor); $uref1 = $step1infor['Tempuncertaintydata']['uref1_data1']; $uref2 = $step1infor['Tempuncertaintydata']['uref2_data1']; $uref3 = $step1infor['Tempuncertaintydata']['uref3_data1']; $urefdivisor = $step1infor['Tempuncertaintydata']['urefdivisor']; $uacc1 = $step1infor['Tempuncertaintydata']['uacc1_data1']; $uacc2 = $step1infor['Tempuncertaintydata']['uacc2_data1']; $uacc3 = $step1infor['Tempuncertaintydata']['uacc3_data1']; $divisor = $step1infor['Tempuncertaintydata']['divisor']; $uresdivisoranalog = $step1infor['Tempuncertaintydata']['uresdivisoranalog']; //pr($uresdivisoranalog); $uresdivisordigital = $step1infor['Tempuncertaintydata']['uresdivisordigital']; //pr($uresdivisordigital); $urepdivisor = $step1infor['Tempuncertaintydata']['urepdivisor']; ///// Others $u1_data2 = $step1infor['Tempuncertaintydata']['u1_data2']; $u2_data2 = $step1infor['Tempuncertaintydata']['u2_data2']; $u3_data2 = $step1infor['Tempuncertaintydata']['u3_data2']; $u4_data2 = $step1infor['Tempuncertaintydata']['u4_data2']; $u5_data2 = $step1infor['Tempuncertaintydata']['u5_data2']; $u6_data2 = $step1infor['Tempuncertaintydata']['u6_data2']; $u7_data2 = $step1infor['Tempuncertaintydata']['u7_data2']; $u8_data2 = $step1infor['Tempuncertaintydata']['u8_data2']; $u9_data2 = $step1infor['Tempuncertaintydata']['u9_data2']; $u10_data2 = $step1infor['Tempuncertaintydata']['u10_data2']; $u11_data2 = $step1infor['Tempuncertaintydata']['u11_data2']; $u12_data2 = $step1infor['Tempuncertaintydata']['u12_data2']; $u13_data2 = $step1infor['Tempuncertaintydata']['u13_data2']; $u14_data2 = $step1infor['Tempuncertaintydata']['u14_data2']; $u15_data2 = $step1infor['Tempuncertaintydata']['u15_data2']; $u16_data2 = $step1infor['Tempuncertaintydata']['u16_data2']; $u17_data2 = $step1infor['Tempuncertaintydata']['u17_data2']; $u18_data2 = $step1infor['Tempuncertaintydata']['u18_data2']; $u19_data2 = $step1infor['Tempuncertaintydata']['u19_data2']; $u20_data2 = $step1infor['Tempuncertaintydata']['u20_data2']; $res = $this->request->data['step1']['res' . $j]; //$first = powfn($uref1/$urefdivisor); $vc_uref = 0; if ($urefdivisor != 0) { $vc_uref = powfn($uref1 / $urefdivisor) + powfn($uref2 / $urefdivisor) + powfn($uref3 / $urefdivisor); } pr("uref = " . $vc_uref); //pr($vc_uref); $vc_urep1 = 0; $vc_urep2 = 0; $vc_urep3 = 0; if ($urepdivisor != 0) { $vc_urep1 = powfn($this->request->data['step1']['m' . $j . '_13'] / $urepdivisor); $vc_urep2 = powfn($this->request->data['step1']['b' . $j . '_13'] / $urepdivisor); if (isset($this->request->data['total']['is_afteradjust'])) { $vc_urep3 = powfn($this->request->data['step1']['a' . $j . '_13'] / $urepdivisor); } } pr("urep = " . ($vc_urep1 + $vc_urep2)); $vc_digital = array(); pr("uresdivisordigital" . $uresdivisordigital); pr("res" . $res); if ($uresdivisordigital != 0 && $res != 0) { $vc_digital[] = powfn($res / $uresdivisordigital); } //pr("ures = ".$vc_digital); $vc_div = 0; $vc_acc = 0; if ($divisor != 0) { //powfn($this->request->data['step1']['acc'.$j]/$divisor) + powfn($this->request->data['step1']['count'.$j]/$divisor) + $vc_acc = powfn($uacc1 / $divisor) + powfn($uacc2 / $divisor) + powfn($uacc3 / $divisor); $vc_div = powfn($u1_data2 / $divisor) + powfn($u2_data2 / $divisor) + powfn($u3_data2 / $divisor) + powfn($u4_data2 / $divisor) + powfn($u5_data2 / $divisor) + powfn($u6_data2 / $divisor) + powfn($u7_data2 / $divisor) + powfn($u8_data2 / $divisor) + powfn($u9_data2 / $divisor) + powfn($u10_data2 / $divisor) + powfn($u11_data2 / $divisor) + powfn($u12_data2 / $divisor) + powfn($u13_data2 / $divisor) + powfn($u14_data2 / $divisor) + powfn($u15_data2 / $divisor) + powfn($u16_data2 / $divisor) + powfn($u17_data2 / $divisor) + powfn($u18_data2 / $divisor) + powfn($u19_data2 / $divisor) + powfn($u20_data2 / $divisor); } pr("uacc = " . $vc_acc); pr("uothers = " . $vc_div); $vc[] = $vc_uref + $vc_div + $vc_urep1 + $vc_urep2 + $vc_urep3 + $vc_acc; //pr($vc); } //pr($vc); $vc2 = 0; foreach ($vc as $vc1) { $vc2 = $vc2 + $vc1; } //pr($vc_digital); //$vc_digital = 0.020833333; if ($vc_digital) { pr("combined uncert = " . ($vc2 + $vc_digital[0])); $vc_final = sqrt($vc2 + $vc_digital[0]); } else { pr("combined uncert = " . $vc2); $vc_final = sqrt($vc2); } //pr("vc_final = ".$vc_final); $kfactor = 2; $urep = $this->request->data['step1']['m' . $j . '_13']; //pr($urep); $po_val = powfn4($urep) / ($this->request->data['step1']['no_runs'] - 1); //pr($po_val); if ($po_val) { $dof = powfn4($vc_final) / $po_val; //pr("dof = ".$dof); } $uncertainty = $kfactor * $vc_final; //pr("uncert = ".$uncertainty); // //pr($dof); // // // //exit; // //exit; // if(count($comparable_uncert) != 0) // { // $uncer_sum = array_sum($uncertainty); // $uncertainty = array(); if ($this->request->data['step1']['m' . $j . '_1'] != NULL && $this->request->data['step1']['temp' . $j] != NULL) { $this->request->data['step1']['uncert' . $j] = $uncertainty; } else { $this->request->data['step1']['uncert' . $j] = ''; } if ($po_val) { $this->request->data['step1']['dof' . $j] = $dof; } $this->request->data['step1']['uc' . $j] = $vc_final; $this->request->data['step1']['kfac' . $j] = $kfactor; // // } // //} } //pr($uncertainty); //exit; //$unique = array(); //$unique[] = ; //$this->request->data['step1']['uc_data_arr'] = '1,2,7,8,10'; $this->request->data['step1']['uc_data_arr'] = implode(',', array_unique($aaaaaa)); // exit; } //pr($aaaaaa); $this->request->data['Tempcertificatedata'] = $this->request->data['step1']; $this->request->data['Tempcertificatedata']['certificate_no'] = $certificateno; $this->request->data['Tempcertificatedata']['temp_readingtype_id'] = $readingtype_id; $this->request->data['Tempcertificatedata']['temp_channel_id'] = $channel_id; //$this->request->data['Tempcertificatedata']['temp1'] = $temp1; //pr($this->request->data);exit; $this->request->data['Tempcertificatedata']['id'] = $find_cert['Tempcertificatedata']['id']; $this->Tempcertificatedata->save($this->request->data['Tempcertificatedata']); $get_cert_for_id = $this->Tempcertificate->find('first', array('conditions' => array('Tempcertificate.certificate_no' => $this->request->data['certificateno']), 'recursive' => '2')); if ($this->request->data['Tempformdata']['cal_status'] == 1) { echo "calstatus = rejected"; $get_desc = $this->Tempcertificate->find('first', array('conditions' => array('Tempcertificate.certificate_no' => $this->request->data['certificateno']), 'recursive' => '2')); $desc_id = $get_desc['Tempcertificate']['description_id']; //$data = $this->Description->find('first',array('conditions'=>array('Description.id'=>$desc_id))); $this->Description->updateAll(array('Description.engineer' => 0), array('Description.id' => $desc_id)); } if ($this->request->data['Tempformdata']['cal_status'] == 2) { echo "calstatus = approved"; $get_desc = $this->Tempcertificate->find('first', array('conditions' => array('Tempcertificate.certificate_no' => $this->request->data['certificateno']), 'recursive' => '2')); $desc_id = $get_desc['Tempcertificate']['description_id']; //$data = $this->Description->find('first',array('conditions'=>array('Description.id'=>$desc_id))); $this->Description->updateAll(array('Description.supervisor' => 1), array('Description.id' => $desc_id)); } if ($this->request->data['Tempformdata']['approved_status'] == 1) { echo "appstatus = rejected"; $get_desc = $this->Tempcertificate->find('first', array('conditions' => array('Tempcertificate.certificate_no' => $this->request->data['certificateno']), 'recursive' => '2')); $desc_id = $get_desc['Tempcertificate']['description_id']; //$data = $this->Description->find('first',array('conditions'=>array('Description.id'=>$desc_id))); $this->Description->updateAll(array('Description.supervisor' => 0), array('Description.id' => $desc_id)); } if ($this->request->data['Tempformdata']['approved_status'] == 2) { echo "appstatus = approved"; $get_desc = $this->Tempcertificate->find('first', array('conditions' => array('Tempcertificate.certificate_no' => $this->request->data['certificateno']), 'recursive' => '2')); $desc_id = $get_desc['Tempcertificate']['description_id']; //$data = $this->Description->find('first',array('conditions'=>array('Description.id'=>$desc_id))); $this->Description->updateAll(array('Description.manager' => 1), array('Description.id' => $desc_id)); } $this->request->data['Tempcertificate'] = $this->request->data['Tempformdata']; $this->request->data['Tempcertificate']['id'] = $get_cert_for_id['Tempcertificate']['id']; $this->Tempcertificate->save($this->request->data['Tempcertificate']); } else { //pr($_REQUEST); //pr($this->request->data);exit; if (isset($this->request->data['step1']['uncertainty1_val'])) { $uncertainty1_val1 = $this->request->data['step1']['uncertainty1_val']; $uncertainty1_val = implode(',', $uncertainty1_val1); $this->request->data['Tempcertificatedata']['uncertainty1_val'] = $uncertainty1_val; } $this->request->data['Tempcertificatedata']['uncertainty1_val'] = $uncertainty1_val; function stddev($array) { //Don Knuth is the $deity of algorithms //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#III._On-line_algorithm $n = 0; $mean = 0; $M2 = 0; foreach ($array as $x) { $n++; $delta = $x - $mean; $mean = $mean + $delta / $n; $M2 = $M2 + $delta * ($x - $mean); } $variance = $M2 / ($n - 1); return sqrt($variance); } function stddev1($array) { //Don Knuth is the $deity of algorithms //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#III._On-line_algorithm $n = 0; $mean = 0; $M2 = 0; foreach ($array as $x) { $n++; $delta = $x - $mean; $mean = $mean + $delta / $n; $M2 = $M2 + $delta * ($x - $mean); } $variance = $M2 / ($n - 1); return sqrt($variance); } function stddev2($array) { //Don Knuth is the $deity of algorithms //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#III._On-line_algorithm $n = 0; $mean = 0; $M2 = 0; foreach ($array as $x) { $n++; $delta = $x - $mean; $mean = $mean + $delta / $n; $M2 = $M2 + $delta * ($x - $mean); } $variance = $M2 / ($n - 1); return sqrt($variance); } if (isset($this->request->data['step1']['no_runs'])) { // Twin FOR for ($j = 1; $j <= 15; $j++) { $summed_val_m = 0; $array_sd_m = array(); $sd_m = 0; $mean_m = 0; for ($i = 1; $i <= 15; $i++) { if (isset($this->request->data['step1']['m' . $j . '_' . $i . ''])) { $summed_val_m = $summed_val_m + $this->request->data['step1']['m' . $j . '_' . $i . '']; $array_sd_m[] = $this->request->data['step1']['m' . $j . '_' . $i . '']; } } //pr($array_sd_m); exit; $this->request->data['step1']['m' . $j . '_12'] = $sd_m = stddev($array_sd_m); $this->request->data['step1']['m' . $j . '_13'] = $sd_m / sqrt($this->request->data['step1']['no_runs']); $this->request->data['step1']['m' . $j . '_11'] = $mean_m = $summed_val_m / $this->request->data['step1']['no_runs']; $summed_val_b = 0; $array_sd_b = array(); $sd_b = 0; $mean_b = 0; for ($i = 1; $i <= 15; $i++) { if (isset($this->request->data['step1']['b' . $j . '_' . $i . ''])) { $summed_val_b = $summed_val_b + $this->request->data['step1']['b' . $j . '_' . $i . '']; $array_sd_b[] = $this->request->data['step1']['b' . $j . '_' . $i . '']; } } $this->request->data['step1']['b' . $j . '_12'] = $sd_b = stddev1($array_sd_b); $this->request->data['step1']['b' . $j . '_13'] = $sd_b / sqrt($this->request->data['step1']['no_runs']); $this->request->data['step1']['b' . $j . '_11'] = $mean_b = $summed_val_b / $this->request->data['step1']['no_runs']; //pr($sd_b); if (isset($this->request->data['total']['is_afteradjust'])) { $summed_val_a = 0; $array_sd_a = array(); $sd_a = 0; $mean_a = 0; for ($i = 1; $i <= 15; $i++) { if (isset($this->request->data['step1']['a' . $j . '_' . $i . ''])) { $summed_val_a = $summed_val_a + $this->request->data['step1']['a' . $j . '_' . $i . '']; $array_sd_a[] = $this->request->data['step1']['a' . $j . '_' . $i . '']; } } $this->request->data['step1']['a' . $j . '_12'] = $sd_a = stddev2($array_sd_a); $this->request->data['step1']['a' . $j . '_13'] = $sd_a / sqrt($this->request->data['step1']['no_runs']); //pr($sd_a); $this->request->data['step1']['a' . $j . '_11'] = $mean_a = $summed_val_a / $this->request->data['step1']['no_runs']; } } } $this->request->data['Tempcertificatedata'] = $this->request->data['step1']; $this->request->data['Tempcertificatedata']['certificate_no'] = $certificateno; $this->request->data['Tempcertificatedata']['temp_readingtype_id'] = $readingtype_id; $this->request->data['Tempcertificatedata']['temp_channel_id'] = $channel_id; //$this->request->data['Tempcertificatedata']['temp1'] = $temp1; $this->Tempcertificatedata->create(); $this->Tempcertificatedata->save($this->request->data['Tempcertificatedata']); } $unit_list = $this->Tempunit->find('list', array('conditions' => array('Tempunit.status' => 1), 'fields' => array('Tempunit.id', 'unitname'))); $this->set('unit_list', $unit_list); $uncertainty = $this->Tempuncertainty->find('all'); $this->set('uncertainty', $uncertainty); $find_cert = $this->Tempcertificatedata->find('first', array('conditions' => array('Tempcertificatedata.certificate_no' => $certificateno, 'Tempcertificatedata.temp_readingtype_id' => $readingtype_id, 'Tempcertificatedata.temp_channel_id' => $channel_id))); $this->set('cert', $find_cert); $find_cert_uc_data_arr = $this->Tempcertificatedata->find('first', array('conditions' => array('Tempcertificatedata.certificate_no' => $certificateno, 'Tempcertificatedata.temp_readingtype_id' => $readingtype_id, 'Tempcertificatedata.temp_channel_id' => $channel_id))); $res = $find_cert_uc_data_arr['Tempcertificatedata']['uc_data_arr']; if (isset($res)) { $explo = explode(',', $res); $uncertaintyda[] = $this->Tempuncertaintydata->find('all', array('conditions' => array('Tempuncertaintydata.id' => $explo))); $this->set('uncertaintyda', $uncertaintyda); } //pr($uncertaintyda);exit; $find_cert_main_data = $this->Description->find('first', array('conditions' => array('Description.certificateno' => $certificateno), 'recursive' => '2')); $this->set('get_cert_main', $find_cert_main_data); $get_cert_sales = $this->Tempcertificate->find('first', array('conditions' => array('Tempcertificate.certificate_no' => $certificateno), 'recursive' => '2')); $this->set('get_cert_sales', $get_cert_sales); //// -----------------------Static Details $get_cert_certno = $this->Tempcertificate->find('list', array('fields' => array('certificate_no', 'certificate_no')), array('recursive' => '2')); $this->set('get_cert_certno', $get_cert_certno); $uncertainty = $this->Tempuncertainty->find('all'); $this->set('uncertainty', $uncertainty); $readingtype_data = $this->Tempreadingtype->find('list', array('fields' => array('Tempreadingtype.id', 'Tempreadingtype.readingtypename'), 'conditions' => array('Tempreadingtype.is_deleted' => 0, 'Tempreadingtype.status' => 1)), array('order' => 'Tempreadingtype.id Desc', 'recursive' => '2')); $this->set('readingtype_data', $readingtype_data); $channel_data = $this->Tempchannel->find('list', array('fields' => array('Tempchannel.id', 'Tempchannel.channelname'), 'conditions' => array('Tempchannel.is_deleted' => 0, 'Tempchannel.status' => 1)), array('order' => 'Tempchannel.id Desc', 'recursive' => '2')); $this->set('channel_data', $channel_data); $tempform_data = $this->Tempformdata->find('first'); $this->set('formdata', $tempform_data); $instrument_cal_status = array('1' => 'Faulty', '2' => 'Calibration', '3' => 'No Capability', '4' => 'Return without cal', '5' => 'Out of tolerance'); $this->set('instrument_cal_status', $instrument_cal_status); } else { //pr('else'); //exit; $ids = array(); $ids = explode("\$", $id); $instrument_id = $ids[0]; $range_id = $ids[3]; $model_no = $ids[2]; $brand_id = $ids[1]; $salesorder_id = $ids[4]; $description_id = $ids[5]; $find_cert_main_data = $this->Description->find('first', array('conditions' => array('Description.id' => $description_id), 'recursive' => '2')); //pr($find_cert_main_data);exit; $this->set('get_cert_main', $find_cert_main_data); $get_cert_sales = $this->Tempcertificate->find('first', array('conditions' => array('Tempcertificate.description_id' => $description_id), 'recursive' => '2')); $this->set('get_cert_sales', $get_cert_sales); // $tempcert = $this->Tempcertificate->find('first',array('conditions'=>array('Tempcertificate.certificate_no'=>$certificateno),'recursive'=>'2')); // $tempcertdata = $this->Tempcertificatedata->find('first',array('conditions'=>array('Tempcertificatedata.certificate_no'=>$certificateno,'Tempcertificatedata.temp_readingtype_id'=>$readingtype_id,'Tempcertificatedata.temp_channel_id'=>$channel_id))); // // $temptemplate = $this->Temptemplate->find('first', array('conditions' => array('Temptemplate.temp_instruments_id' =>$instrument_id, // 'Temptemplate.model' =>$model_no,'Temptemplate.brand_id' =>$brand_id, // 'Temptemplate.range_id' =>$range_id))); // $this->set('tempdata',$temptemplate['Temptemplatedata']); // //pr($temptemplate['Temptemplatedata']);exit; // $temptemplatedata = $this->Temptemplatedata->find('all', array('conditions' => array('Temptemplatedata.temp_templates_id' =>$tempcert['Tempcertificate']['template_id']))); // //// -----------------------Static Details $get_cert_certno = $this->Tempcertificate->find('list', array('fields' => array('certificate_no', 'certificate_no')), array('recursive' => '2')); $this->set('get_cert_certno', $get_cert_certno); $uncertainty = $this->Tempuncertainty->find('all'); $this->set('uncertainty', $uncertainty); $readingtype_data = $this->Tempreadingtype->find('list', array('fields' => array('Tempreadingtype.id', 'Tempreadingtype.readingtypename'), 'conditions' => array('Tempreadingtype.is_deleted' => 0, 'Tempreadingtype.status' => 1)), array('order' => 'Tempreadingtype.id Desc', 'recursive' => '2')); $this->set('readingtype_data', $readingtype_data); $channel_data = $this->Tempchannel->find('list', array('fields' => array('Tempchannel.id', 'Tempchannel.channelname'), 'conditions' => array('Tempchannel.is_deleted' => 0, 'Tempchannel.status' => 1)), array('order' => 'Tempchannel.id Desc', 'recursive' => '2')); $this->set('channel_data', $channel_data); $tempform_data = $this->Tempformdata->find('first'); $this->set('formdata', $tempform_data); $instrument_cal_status = array('1' => 'Faulty', '2' => 'Calibration', '3' => 'No Capability', '4' => 'Return without cal', '5' => 'Out of tolerance'); $this->set('instrument_cal_status', $instrument_cal_status); } //exit; }
/** * Standard deviation */ function stdev(array $values, $is_sample = false) { return stddev($values, $is_sample); }
function _stats($hits, $treshold = 10.0) { sort($hits); reset($hits); $n = count($hits); $max = 0; $min = 9999999999999; $sum = 0; foreach ($hits as $h) { $sum += $h; $max = max($h, $max); $min = min($h, $min); } $median_i = (int) $n / 2; if (!($n / 2)) { $median = $hits[$median_i]; } else { $median = $hits[$median_i]; } $treshold = 10; $mintreshold = $max * $treshold / 100.0; // lower than 10% of the hits reset($hits); $nmin = $hits[0] < $mintreshold ? 1 : 0; while (next($hits) < $mintreshold) { $nmin++; } $maxtreshold = $max - $mintreshold; // more than 90% of the hits end($hits); $nmax = 1; while (prev($hits) > $maxtreshold) { $nmax++; } return array('n' => $n, 'sum' => $sum, 'min' => $min, 'max' => $max, 'mean' => $sum / $n, 'median' => $median, 'stddev' => stddev($hits, $sum), 'treshold' => $treshold, 'nmin' => $nmin, 'mintreshold' => $mintreshold, 'nmax' => $nmax, 'maxtreshold' => $maxtreshold); }