|
@@ -14,7 +14,7 @@ class dispose
|
|
|
|
|
|
public function computeData($data){
|
|
|
debug_log("InAndOUT","基站:".$data['mac'] .' label :'.$data['label']);
|
|
|
-
|
|
|
+ debug_log("InAndOUT","新数据:".json_encode($data));
|
|
|
$hashKey=$data['mac'].'station';
|
|
|
$key=$data['label'];
|
|
|
$list=[];
|
|
@@ -22,14 +22,15 @@ class dispose
|
|
|
$res= $this->selectHash($hashKey,$key);
|
|
|
|
|
|
if($res==false){
|
|
|
- debug_log("InAndOUT","redis没有数据");
|
|
|
+ debug_log("InAndOUT","redis没有数据,存入新数据");
|
|
|
array_push($list,$data);
|
|
|
- debug_log("InAndOUT","存入数据".$data);
|
|
|
+ debug_log("InAndOUT","当前数据队列",json_encode($list));
|
|
|
+
|
|
|
}else{
|
|
|
- debug_log("InAndOUT","redis初始数据",json_encode($res));
|
|
|
+ debug_log("InAndOUT","redis初始数据 :".json_encode($res));
|
|
|
$list=$res;
|
|
|
debug_log("InAndOUT","上次上报的数据 :".json_encode($list[count($list)-1],true));
|
|
|
- debug_log("InAndOUT","存入数据".$data);
|
|
|
+
|
|
|
if(($data['report_time']-$list[count($list)-1]['report_time'])>=120){
|
|
|
debug_log("InAndOUT","上报次数间隔超过120s,清空redis缓存,从新存入数据");
|
|
|
$list=[];
|
|
@@ -37,19 +38,33 @@ class dispose
|
|
|
}else{
|
|
|
$list=$res;
|
|
|
array_push($list,$data);
|
|
|
- if(count($list)>5){
|
|
|
- debug_log("InAndOUT","数据长度大于5,剔除一条");
|
|
|
- debug_log("InAndOUT","剔除的一条数据为:".json_encode($list[0]));
|
|
|
- array_shift($list);
|
|
|
+ //保留10秒
|
|
|
+ $tem_list=$list;
|
|
|
+
|
|
|
+ foreach($tem_list as $tem_item){
|
|
|
+ debug_log("InAndOUT","测试".($tem_item['report_time']-$data['report_time']));
|
|
|
+ if(($data['report_time']-$tem_item['report_time'])>5){
|
|
|
+ debug_log("InAndOUT","最旧的上报时间超过5s剔除一条");
|
|
|
+ array_shift($list);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // if(count($list)>5){
|
|
|
+ // debug_log("InAndOUT","数据长度大于5,剔除一条");
|
|
|
+ // debug_log("InAndOUT","剔除的一条数据为:".json_encode($list[0]));
|
|
|
+ // array_shift($list);
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//数据
|
|
|
- debug_log("InAndOUT","新数据长度 :".json_encode($list));
|
|
|
- //现在的数据长度
|
|
|
$count=count($list);
|
|
|
+ debug_log("InAndOUT","当前数据队列 :".json_encode($list));
|
|
|
debug_log("InAndOUT","新数据长度 :".$count);
|
|
|
+ //现在的数据长度
|
|
|
+
|
|
|
//获取配置
|
|
|
$config= $this->selectHash("anbang_four_wire",$data['mac']);
|
|
|
|
|
@@ -69,7 +84,7 @@ class dispose
|
|
|
$rssi3=0;
|
|
|
$rssi4=0;
|
|
|
foreach($list as $item){
|
|
|
- if(!empty($config)){
|
|
|
+ if(!empty($config)){
|
|
|
if($config['front']&&$config['front']>$item["rssi1"]){
|
|
|
$rssi1+=$item["rssi1"];
|
|
|
$len01+=1;
|
|
@@ -99,13 +114,16 @@ class dispose
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
$data["rssi1"]=number_format($rssi1/$len01,'2');
|
|
|
$data["rssi2"]=number_format($rssi2/$len02,'2');
|
|
|
$data["rssi3"]=number_format($rssi3/$len03,'2');
|
|
|
$data["rssi4"]=number_format($rssi4/$len04,'2');
|
|
|
debug_log("InAndOUT","计算出的平均数据 :".json_encode($data));
|
|
|
//保存到hash中
|
|
|
+ debug_log("InAndOUT","存入redis缓存的数据 :".json_encode($list));
|
|
|
$this->setHash($hashKey,$key,$list);
|
|
|
+ debug_log("InAndOUT","=======================================");
|
|
|
return $data;
|
|
|
}
|
|
|
//计算结果设计
|
|
@@ -134,8 +152,6 @@ class dispose
|
|
|
$key=$data['label'];
|
|
|
$json_list= $this->selectHash($hashkey,$key);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
if(!$json_list){
|
|
|
|
|
@@ -145,8 +161,7 @@ class dispose
|
|
|
];
|
|
|
debug_log("InAndOUT","数据不存在,直接存储新数据".json_encode($arr));
|
|
|
$this->setHash($hashkey,$key,$arr);
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
return;
|
|
|
}else{
|
|
|
|
|
@@ -166,12 +181,17 @@ class dispose
|
|
|
$status= ['time'=>null,'dirt'=>null];
|
|
|
}
|
|
|
array_push($list,$resArray);
|
|
|
- if(count($list)>5){
|
|
|
- debug_log("InAndOUT","数据超过五条,剔除一条旧数据");
|
|
|
- array_shift($list);
|
|
|
- }
|
|
|
- debug_log("InAndOUT","时间超过两分钟,清空数据,载入当前数据");
|
|
|
- debug_log("InAndOUT","当前队列数据",json_encode($list));
|
|
|
+ // if(count($list)>3){
|
|
|
+ // debug_log("InAndOUT","数据超过3条,剔除一条旧数据");
|
|
|
+ //array_shift($list);
|
|
|
+
|
|
|
+ while(count($list)>5){
|
|
|
+ array_shift($list);
|
|
|
+ debug_log("InAndOUT","数据超过3条,剔除一条旧数据");
|
|
|
+ }
|
|
|
+ //}
|
|
|
+
|
|
|
+ debug_log("InAndOUT","当前队列数据:".json_encode($list));
|
|
|
$front=0;
|
|
|
$back=0;
|
|
|
if(count($list)>2){
|
|
@@ -186,13 +206,14 @@ class dispose
|
|
|
$back+=1;
|
|
|
}
|
|
|
}
|
|
|
- $res=$front>=$back?1:2;
|
|
|
+
|
|
|
+ $res=$front>$back?1:2;
|
|
|
+
|
|
|
if(empty($status['dirt'])){
|
|
|
$status['dirt']= $res;
|
|
|
$status['time']= $resArray['time'];
|
|
|
debug_log("InAndOUT","无初始化状态,则进行初始化");
|
|
|
- debug_log("InAndOUT","初始化数据为:".json_encode($resArray));
|
|
|
- debug_log("InAndOUT","初始化数据为:".json_encode($status));
|
|
|
+ debug_log("InAndOUT","初始化状态为:".json_encode($status));
|
|
|
}else{
|
|
|
//进行保存
|
|
|
if($res!=$status['dirt']){
|
|
@@ -201,13 +222,33 @@ class dispose
|
|
|
'label'=>$data['label'],
|
|
|
"begin_time"=>$status['time'],
|
|
|
"end_time"=>$resArray['time'],
|
|
|
- 'dir'=> $status['dirt']==1?1:2
|
|
|
+ 'dirt'=> $status['dirt']==1?1:2
|
|
|
];
|
|
|
+ $data_array=[];
|
|
|
+ $data_array[]=[
|
|
|
+ "label"=>$data['label'],
|
|
|
+ 'time'=>$resArray['time'],
|
|
|
+ 'dirt'=> $status['dirt']==1?1:2
|
|
|
+ ];
|
|
|
+ $url_data=[
|
|
|
+ "mac"=>$data['mac'],
|
|
|
+ "data"=>$data_array
|
|
|
+
|
|
|
+ ];
|
|
|
+ debug_log("InAndOUT","得出计算结果:".json_encode($arr));
|
|
|
+ debug_log("InAndOUT","发送给远程".json_encode($url_data));
|
|
|
+ $url="http://47.114.185.186:8115/api/accessReport";
|
|
|
+ $url_res= curl_http_post(json_encode($url_data),$url,false);
|
|
|
+ debug_log("InAndOUT","远程返回结果".$url_res);
|
|
|
+
|
|
|
// $dor=new Dormitory();
|
|
|
// $dor->save($arr);
|
|
|
- debug_log("InAndOUT","得出计算结果",json_encode($arr));
|
|
|
+
|
|
|
+
|
|
|
+ debug_log("InAndOUT","得出计算结果:".json_encode($arr));
|
|
|
$status['dirt']= $res;
|
|
|
$status['time']= $resArray['time'];
|
|
|
+
|
|
|
}else{
|
|
|
debug_log("InAndOUT","无计算结果",json_encode($status));
|
|
|
}
|
|
@@ -219,7 +260,7 @@ class dispose
|
|
|
"a"=>$list,
|
|
|
'status'=>$status
|
|
|
);
|
|
|
- debug_log("InAndOUT","存入缓存中",json_encode($arr));
|
|
|
+ debug_log("InAndOUT","存入缓存中:".json_encode($arr));
|
|
|
|
|
|
$this->setHash($hashkey,$key,$arr);
|
|
|
debug_log("InAndOUT",'操作结束');
|