|
@@ -6,192 +6,193 @@ use catchAdmin\tag_history\model\Dormitory;
|
|
|
class dispose
|
|
|
{
|
|
|
private $redis;
|
|
|
+ private $stations="stations";
|
|
|
public function __construct($redis){
|
|
|
|
|
|
$this->redis=$redis;
|
|
|
|
|
|
}
|
|
|
|
|
|
- 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=[];
|
|
|
- $length=0;
|
|
|
- $res= $this->selectHash($hashKey,$key);
|
|
|
+ // 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=[];
|
|
|
+ // $length=0;
|
|
|
+ // $res= $this->selectHash($hashKey,$key);
|
|
|
|
|
|
- if($res==false){
|
|
|
- debug_log("InAndOUT","redis没有数据,存入新数据");
|
|
|
- array_push($list,$data);
|
|
|
- debug_log("InAndOUT","当前数据队列",json_encode($list));
|
|
|
+ // if($res==false){
|
|
|
+ // debug_log("InAndOUT","redis没有数据,存入新数据");
|
|
|
+ // array_push($list,$data);
|
|
|
+ // debug_log("InAndOUT","当前数据队列",json_encode($list));
|
|
|
|
|
|
- }else{
|
|
|
- debug_log("InAndOUT","redis初始数据 :".json_encode($res));
|
|
|
- $list=$res;
|
|
|
- debug_log("InAndOUT","上次上报的数据 :".json_encode($list[count($list)-1],true));
|
|
|
+ // }else{
|
|
|
+ // debug_log("InAndOUT","redis初始数据 :".json_encode($res));
|
|
|
+ // $list=$res;
|
|
|
+ // debug_log("InAndOUT","上次上报的数据 :".json_encode($list[count($list)-1],true));
|
|
|
|
|
|
- if(($data['report_time']-$list[count($list)-1]['report_time'])>=120){
|
|
|
- debug_log("InAndOUT","上报次数间隔超过120s,清空redis缓存,从新存入数据");
|
|
|
- $list=[];
|
|
|
- array_push($list,$data);
|
|
|
- }else{
|
|
|
- $list=$res;
|
|
|
- array_push($list,$data);
|
|
|
- //保留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(($data['report_time']-$list[count($list)-1]['report_time'])>=120){
|
|
|
+ // // debug_log("InAndOUT","上报次数间隔超过120s,清空redis缓存,从新存入数据");
|
|
|
+ // // $list=[];
|
|
|
+ // // array_push($list,$data);
|
|
|
+ // // }else{
|
|
|
+ // $list=$res;
|
|
|
+ // array_push($list,$data);
|
|
|
+
|
|
|
+ // //按照个数
|
|
|
+ // while(count($list)>5){
|
|
|
+ // array_shift($list);
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ // // }
|
|
|
+
|
|
|
+ // }
|
|
|
+ // //数据
|
|
|
+ // $count=count($list);
|
|
|
+ // debug_log("InAndOUT","当前数据队列 :".json_encode($list));
|
|
|
+ // debug_log("InAndOUT","新数据长度 :".$count);
|
|
|
+ // //现在的数据长度
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // if(count($list)>5){
|
|
|
- // debug_log("InAndOUT","数据长度大于5,剔除一条");
|
|
|
- // debug_log("InAndOUT","剔除的一条数据为:".json_encode($list[0]));
|
|
|
- // array_shift($list);
|
|
|
- // }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- //数据
|
|
|
- $count=count($list);
|
|
|
- debug_log("InAndOUT","当前数据队列 :".json_encode($list));
|
|
|
- debug_log("InAndOUT","新数据长度 :".$count);
|
|
|
- //现在的数据长度
|
|
|
|
|
|
- //获取配置
|
|
|
- $config= $this->selectHash("anbang_four_wire",$data['mac']);
|
|
|
+ // //获取配置
|
|
|
+ // $config= $this->selectHash("anbang_four_wire",$data['mac']);
|
|
|
|
|
|
|
|
|
- if(empty($config)){
|
|
|
- debug_log("InAndOUT","没有配置");
|
|
|
- }else{
|
|
|
- debug_log("InAndOUT","配置参数为:".json_encode($config));
|
|
|
+ // if(empty($config)){
|
|
|
+ // debug_log("InAndOUT","没有配置");
|
|
|
+ // }else{
|
|
|
+ // debug_log("InAndOUT","配置参数为:".json_encode($config));
|
|
|
|
|
|
+ // }
|
|
|
+ // $sortlist= $this->sortlist($list);
|
|
|
+
|
|
|
+
|
|
|
+ // $data["rssi1"]=$sortlist[0];
|
|
|
+ // $data["rssi2"]=$sortlist[1];
|
|
|
+ // $data["rssi3"]=$sortlist[2];
|
|
|
+ // $data["rssi4"]=$sortlist[3];
|
|
|
+ // debug_log("InAndOUT","计算出的平均数据 :".json_encode($data));
|
|
|
+ // //保存到hash中
|
|
|
+ // debug_log("InAndOUT","存入redis缓存的数据 :".json_encode($list));
|
|
|
+ // $this->setHash($hashKey,$key,$list);
|
|
|
+ // debug_log("InAndOUT","=======================================");
|
|
|
+ // return $data;
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ public function check_data($data){
|
|
|
+ $this->setStations($data['mac']);
|
|
|
+ $res='';
|
|
|
+ $hashKey=$data['mac'].'station';
|
|
|
+ $key=$data['label'];
|
|
|
+ $old_data=$this->selectHash($hashKey,$key);
|
|
|
+ if($data["rssi1"]==90&&!empty($old_data)){
|
|
|
+ if($old_data["rssi1"]<90){
|
|
|
+ $data["rssi1"]=$old_data["rssi1"]+8;
|
|
|
+ $data["rssi1"]= $data["rssi1"]>90 ? 90:$data["rssi1"];
|
|
|
+ $res=$res."rssi1 ";
|
|
|
+ }
|
|
|
}
|
|
|
- $len01=0;
|
|
|
- $len02=0;
|
|
|
- $len03=0;
|
|
|
- $len04=0;
|
|
|
- $rssi1=0;
|
|
|
- $rssi2=0;
|
|
|
- $rssi3=0;
|
|
|
- $rssi4=0;
|
|
|
- foreach($list as $item){
|
|
|
- if(!empty($config)){
|
|
|
- if($config['front']&&$config['front']>$item["rssi1"]){
|
|
|
- $rssi1+=$item["rssi1"];
|
|
|
- $len01+=1;
|
|
|
- }
|
|
|
- if($config['behind']&&$config['behind']>$item["rssi2"]){
|
|
|
- $rssi2+=$item["rssi2"];
|
|
|
- $len02+=1;
|
|
|
- }
|
|
|
- if($config['left']&&$config['left']>$item["rssi3"]){
|
|
|
- $rssi3+=$item["rssi3"];
|
|
|
- $len03+=1;
|
|
|
- }
|
|
|
- if($config['right']&&$config['right']>$item["rssi4"]){
|
|
|
- $rssi4+=$item["rssi4"];
|
|
|
- $len04+=1;
|
|
|
- }
|
|
|
-
|
|
|
- }else{
|
|
|
- $rssi1=$rssi1+$item["rssi1"];
|
|
|
- $rssi2=$rssi2+$item["rssi2"];
|
|
|
- $rssi3=$rssi3+$item["rssi3"];
|
|
|
- $rssi4=$rssi4+$item["rssi4"];
|
|
|
- $len01+=1;
|
|
|
- $len02+=1;
|
|
|
- $len03+=1;
|
|
|
- $len04+=1;
|
|
|
+ if($data["rssi2"]==90&&!empty($old_data)){
|
|
|
+ if($old_data["rssi2"]<90){
|
|
|
+ $data["rssi2"]=$old_data["rssi2"]+8;
|
|
|
+ $data["rssi2"]= $data["rssi2"]>90 ? 90:$data["rssi2"];
|
|
|
+ $res=$res."rssi2";
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- $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","=======================================");
|
|
|
+ $this->setHash($hashKey,$key,$data);
|
|
|
return $data;
|
|
|
}
|
|
|
- //计算结果设计
|
|
|
- public function computeResout($data){
|
|
|
- //前后左右$arr=[$data['resi1'],$data['resi2'],$data['resi3'],$data['resi4']];
|
|
|
- //前后
|
|
|
|
|
|
- // $redis=$this->redis;
|
|
|
- // $arr=[$data['resi1'],$data['resi2']];
|
|
|
- // sort($arr);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //计算结果设计
|
|
|
+ public function computeResout($data){
|
|
|
+
|
|
|
+ debug_log("InAndOUT","=======================================");
|
|
|
+ debug_log("InAndOUT",'接收新数据'.json_encode($data));
|
|
|
+ debug_log("InAndOUT","=======================================");
|
|
|
$res=0;
|
|
|
+
|
|
|
+ $hashkey='res'.$data['mac'];
|
|
|
+ $key=$data['label'];
|
|
|
+ //存入redis的数据
|
|
|
+ $json_list= $this->selectHash($hashkey,$key);
|
|
|
+ //最新时间
|
|
|
+ $time=$data['report_time'];
|
|
|
+ //是否参与计算
|
|
|
+ $calculate=true;
|
|
|
+
|
|
|
if($data['rssi1']==$data['rssi2']){
|
|
|
|
|
|
- debug_log("InAndOUT","前后信号相等则进行过滤掉");
|
|
|
+ debug_log("InAndOUT","前后信号相等则进行过滤掉");
|
|
|
+ $calculate=false;
|
|
|
+ }
|
|
|
+ $t1s= $data['rssi1']-$data['rssi2'];
|
|
|
+ if(abs($t1s)<3){
|
|
|
+ debug_log("InAndOUT","差值小于3不做计算");
|
|
|
+ $calculate=false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($calculate==false){
|
|
|
+ if(!$json_list){
|
|
|
+ $arr=[
|
|
|
+ "a"=>[],
|
|
|
+ 'status'=> ['time'=>null,'dirt'=>null],
|
|
|
+ "time"=>$time //最新时间
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $json_list['time']=$time;
|
|
|
+
|
|
|
+ }
|
|
|
+ $this->setHash($hashkey,$key,$json_list);
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
if($data['rssi1']<$data['rssi2']){
|
|
|
$res=1;
|
|
|
}
|
|
|
if($data['rssi1']>$data['rssi2']){
|
|
|
$res=2;
|
|
|
}
|
|
|
- debug_log("InAndOUT","信号强度 :".$res);
|
|
|
- $hashkey='res'.$data['mac'];
|
|
|
- $key=$data['label'];
|
|
|
- $json_list= $this->selectHash($hashkey,$key);
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
if(!$json_list){
|
|
|
|
|
|
$arr=[
|
|
|
- "a"=>[['time'=>$data['report_time'],'dirt'=>$res]],
|
|
|
- 'status'=> ['time'=>null,'dirt'=>null]
|
|
|
+ "a"=>[['time'=>$time,'dirt'=>$res]],
|
|
|
+ 'status'=> ['time'=>null,'dirt'=>null],
|
|
|
+ "time"=>$time //最新时间
|
|
|
];
|
|
|
debug_log("InAndOUT","数据不存在,直接存储新数据".json_encode($arr));
|
|
|
- $this->setHash($hashkey,$key,$arr);
|
|
|
-
|
|
|
+ $this->setHash($hashkey,$key,$arr);
|
|
|
return;
|
|
|
}else{
|
|
|
-
|
|
|
$resArray=['time'=>$data['report_time'],'dirt'=>$res];
|
|
|
- debug_log("InAndOUT","当前的新数据".json_encode($resArray));
|
|
|
debug_log("InAndOUT","缓存的数据".json_encode($json_list));
|
|
|
$s=$json_list;
|
|
|
//数据列表
|
|
|
$list=$s['a'];
|
|
|
//状态
|
|
|
$status=$s['status'];
|
|
|
- //判断时间间隔超过2分钟,则从新计算
|
|
|
- if(($resArray['time']-$list[count($list)-1]['time'])>120){
|
|
|
- //时间超过两分钟,进行重置
|
|
|
- debug_log("InAndOUT","时间超过两分钟,清空数据,载入当前数据");
|
|
|
- $list=[];
|
|
|
- $status= ['time'=>null,'dirt'=>null];
|
|
|
- }
|
|
|
array_push($list,$resArray);
|
|
|
- // if(count($list)>3){
|
|
|
- // debug_log("InAndOUT","数据超过3条,剔除一条旧数据");
|
|
|
- //array_shift($list);
|
|
|
-
|
|
|
- while(count($list)>5){
|
|
|
+ while(count($list)>5){
|
|
|
array_shift($list);
|
|
|
- debug_log("InAndOUT","数据超过3条,剔除一条旧数据");
|
|
|
- }
|
|
|
- //}
|
|
|
-
|
|
|
- debug_log("InAndOUT","当前队列数据:".json_encode($list));
|
|
|
+ debug_log("InAndOUT","数据超过5条,剔除一条旧数据");
|
|
|
+ }
|
|
|
+ debug_log("InAndOUT","当前队列数据:".json_encode($list));
|
|
|
$front=0;
|
|
|
$back=0;
|
|
|
if(count($list)>2){
|
|
@@ -206,50 +207,62 @@ class dispose
|
|
|
$back+=1;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
$res=$front>$back?1:2;
|
|
|
|
|
|
+
|
|
|
if(empty($status['dirt'])){
|
|
|
$status['dirt']= $res;
|
|
|
$status['time']= $resArray['time'];
|
|
|
+
|
|
|
debug_log("InAndOUT","无初始化状态,则进行初始化");
|
|
|
debug_log("InAndOUT","初始化状态为:".json_encode($status));
|
|
|
}else{
|
|
|
+
|
|
|
+ //判断是否连贯
|
|
|
+ $IS_OK=true;
|
|
|
+ $res=0;
|
|
|
+ $reverse=array_reverse($list);
|
|
|
+ $res=$reverse[0]['dirt'];
|
|
|
+ foreach($reverse as $aitem){
|
|
|
+ if($aitem['dirt']!=$res){
|
|
|
+ $IS_OK=false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // if(($reverse[0]['dirt']==$reverse[1]['dirt'])&&($reverse[1]['dirt']==$reverse[2]['dirt'])){
|
|
|
+ // $res=$reverse[0]['dirt'];
|
|
|
+ // $IS_OK=true;
|
|
|
+ // }
|
|
|
+
|
|
|
//进行保存
|
|
|
- if($res!=$status['dirt']){
|
|
|
- $arr=[
|
|
|
- 'mac'=> $data['mac'],
|
|
|
- 'label'=>$data['label'],
|
|
|
- "begin_time"=>$status['time'],
|
|
|
- "end_time"=>$resArray['time'],
|
|
|
- '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));
|
|
|
- $status['dirt']= $res;
|
|
|
- $status['time']= $resArray['time'];
|
|
|
+ if($res!=$status['dirt']&&$IS_OK){
|
|
|
+
|
|
|
+ // if(!empty($status['status']['dirt'])){
|
|
|
+
|
|
|
+ // if($resArray['time']-$status['status']['time']>5){
|
|
|
+
|
|
|
+ $data_array=[];
|
|
|
+ $data_array[]=[
|
|
|
+ "label"=>$data['label'],
|
|
|
+ 'time'=>$resArray['time'],
|
|
|
+ 'dirt'=> $status['dirt']==1?1:2 //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);
|
|
|
+ debug_log("result","正常计算返回的结果".json_encode($url_data));
|
|
|
+
|
|
|
+ $this->temporary_label($this->redis,$data['label'],2);
|
|
|
+ $status['dirt']=$res;
|
|
|
+ $status['time']=$time;
|
|
|
|
|
|
}else{
|
|
|
+
|
|
|
debug_log("InAndOUT","无计算结果",json_encode($status));
|
|
|
}
|
|
|
|
|
@@ -258,16 +271,76 @@ class dispose
|
|
|
}
|
|
|
$arr=array(
|
|
|
"a"=>$list,
|
|
|
- 'status'=>$status
|
|
|
+ 'status'=>$status,
|
|
|
+ "time"=>$time
|
|
|
);
|
|
|
debug_log("InAndOUT","存入缓存中:".json_encode($arr));
|
|
|
-
|
|
|
$this->setHash($hashkey,$key,$arr);
|
|
|
debug_log("InAndOUT",'操作结束');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ //获取所有基站
|
|
|
+ public function getStations(){
|
|
|
+ $key=$this->stations;
|
|
|
+ $list= $this->redis->hKeys($key);
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+ //存入基站号
|
|
|
+ public function setStations($Stations){
|
|
|
+ $key=$this->stations;
|
|
|
+ if(!$this->redis->hExists($key,$Stations)){
|
|
|
+ $this->redis->hSet($key,$Stations,0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //排序
|
|
|
+ public function sortlist($list){
|
|
|
+ $list01=[];
|
|
|
+ $list02=[];
|
|
|
+ $list03=[];
|
|
|
+ $list04=[];
|
|
|
+ debug_log("InAndOUT","排序的数据:".json_encode($list));
|
|
|
+ foreach($list as $item){
|
|
|
+ array_push($list01,$item['rssi1']);
|
|
|
+ array_push($list02,$item['rssi2']);
|
|
|
+ array_push($list03,$item['rssi3']);
|
|
|
+ array_push($list04,$item['rssi4']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(count($list)>=3){
|
|
|
+ sort($list01);
|
|
|
+ sort($list02);
|
|
|
+ sort($list03);
|
|
|
+ sort($list04);
|
|
|
+ array_pop($list01);
|
|
|
+ array_pop($list02);
|
|
|
+ array_pop($list03);
|
|
|
+ array_pop($list04);
|
|
|
+ array_shift($list01);
|
|
|
+ array_shift($list02);
|
|
|
+ array_shift($list03);
|
|
|
+ array_shift($list04);
|
|
|
+ }
|
|
|
+ debug_log("InAndOUT","排序后的队列:".json_encode($list01));
|
|
|
+ debug_log("InAndOUT","排序后的队列:".json_encode($list02));
|
|
|
+ debug_log("InAndOUT","排序后的队列:".json_encode($list03));
|
|
|
+ debug_log("InAndOUT","排序后的队列:".json_encode($list04));
|
|
|
+ $rssi1= array_sum($list01)/count($list01);
|
|
|
+ $rssi2= array_sum($list02)/count($list02);
|
|
|
+ $rssi3= array_sum($list03)/count($list03);
|
|
|
+ $rssi4= array_sum($list04)/count($list04);
|
|
|
+ $res=[$rssi1,$rssi2,$rssi3,$rssi4];
|
|
|
+ debug_log("InAndOUT","结算后的结果:".json_encode($res));
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//查询key hash
|
|
|
public function selectHash($hashKey,$key){
|
|
|
$res= $this->redis->hGet($hashKey,$key);
|
|
@@ -277,12 +350,24 @@ class dispose
|
|
|
return json_decode($res,true);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public function setHash($hashKey,$key,$data){
|
|
|
$this->redis->hSet($hashKey,$key,json_encode($data));
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public function temporary_label($redis,$label,$type){
|
|
|
+ $key="temporary_label";
|
|
|
+ if($type==1){
|
|
|
+ $res= $redis->hGet($key,$label);
|
|
|
+ if($res==false){
|
|
|
+ $redis->hSet($key,$label,1);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $redis->hSet($key,$label,2);
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|