NoSQL のデータベース MongoDB
<?php $arr1da = array(); $arr1 = array(); $arr2da = array(); $arr2 = array(); $result1 = array(); $result2 = array(); $mongo = new Mongo(); $today = date("Y-m-d"); $today1 = $today." 00:00:00"; #print $today1; $yester = date("Y-m-d",strtotime("-1 day")); $yester1 = $yester. " 00:00:00"; #print $yester1; #exit(); $db = $mongo->selectDB("pcless"); $col = $db->selectCollection("tyo"); #$start = new MongoDate(strtotime('2014-09-01 00:00:00')); $start = new MongoDate(strtotime($yester1)); #$end = new MongoDate(strtotime('2014-11-10 00:00:00')); $end = new MongoDate(strtotime($today1)); $cursor = $col->find(array('time' => array ('$gt'=>$start, '$lte'=>$end))); # $start1 = new MongoDate(strtotime('2014-11-01 00:00:00')); # $end1 = new MongoDate(strtotime('2014-11-02 00:00:00')); #$cursor2 = $col->find(array('time' => array ('$gt'=>$start1, '$lte'=>$end1))); foreach($cursor as $jokes) { #print_r("AbsPress".$jokes['AbsPress']); #print ("Date,".$jokes['Date']); #print (",InsideTemp,".$jokes['InsideTemp']); #print (",OutTemp,".$jokes['OutTemp']); #print ("\n"); $InsideTemp = $jokes['InsideTemp']; $OutTemp = $jokes['OutTemp']; #print (",Inside,".$InsideTemp); #print (",Out,".$OutTemp); if (($InsideTemp != "") AND ($OutTemp != "")) { #print_r("AbsPress".$jokes['AbsPress']); #print ("Date,".$jokes['Date']); #print (",InsideTemp,".$InsideTemp); #print (",OutTemp,".$OutTemp); #print ("\n"); $arr1[]=$InsideTemp; $arr2[]=$OutTemp; $arr1da[]=$jokes['Date']; } #var_dump($jokes); } $cnt0=sizeof($arr1); $cnt=floor($cnt0/2); print $cnt; print ("\n"); #print corrcoef($arr1,$arr2); $corr_result= corrcoef($arr1,$arr2); $subject="昨日の相関結果"; print $corr_result; $body = "Start: $yester\r" . "End: $today\r" . "室外と室内温度の相関:$corr_result\r"; $body = "\"". $body."\""; #$body = "室外と室内温度の相関\n" . #"相関:".$corr_result; print $body; $email="chibacy@kki.biglobe.ne.jp"; #exex("/usr/lib/zabbix/alertscripts/sendmessage-smtp-php/sendmessage_smtp_php.sh $email $cnt $corr_result"); $cmd= '/usr/lib/zabbix/alertscripts/sendmessage-smtp-php/sendmessage_smtp_php.sh'. ' '.$email . ' '.$subject.' '. "$body"; print $cmd; exec($cmd); $mongo->setProfilingLevel(0); $collection->drop(); function corrcoef($var_x, $var_y) { if (!count($var_x) || !is_array($var_x)) die('配列じゃない・・・'); if (!count($var_y) || !is_array($var_y)) die('配列じゃない・・・'); $c = (count($var_x) > count($var_y)) ? count($var_x) : count($var_y); $c = 0; while (true) { if (is_null($var_x[$c]) || is_null($var_y[$c])) break; $_var_x[] = $var_x[$c]; $_var_y[] = $var_y[$c]; $c++; } $mean_x = (float) $_var_x[$c]; $mean_y = (float) $_var_y[$c]; $n = 0; while ($n < $c) { if (is_null($_var_x[$n]) || is_null($_var_y[$n])) break; $n = (float) $n; $sweep = $n / ($n + 1.0); $float_x = (float) $_var_x[$n]; $float_y = (float) $_var_y[$n]; $delta_x = $float_x - $mean_x; $delta_y = $float_y - $mean_y; $sum_sq_x += $delta_x * $delta_x * $sweep; $sum_sq_y += $delta_y * $delta_y * $sweep; $sum_coproduct += $delta_x * $delta_y * $sweep; $mean_x += $delta_x / ($n + 1.0); $mean_y += $delta_y / ($n + 1.0); $n += 1; } $n = (float) $n; $pop_sd_x = sqrt($sum_sq_x / $n); $pop_sd_y = sqrt($sum_sq_y / $n); $cov_x_y = $sum_coproduct / $n; $result = $cov_x_y / ($pop_sd_x * $pop_sd_y); return $result; } ?>