likang 2 years ago
parent
commit
72b6963ea4
1 changed files with 32 additions and 20 deletions
  1. 32 20
      catch/api/service/dispose.php

+ 32 - 20
catch/api/service/dispose.php

@@ -125,6 +125,8 @@ class dispose
         debug_log("InAndOUT",'接收新数据'.json_encode($data));   
         debug_log("InAndOUT","=======================================");    
        $res=0;
+       //进出
+    
 
        $hashkey='res'.$data['mac'];
        $key=$data['label'];
@@ -132,18 +134,18 @@ class dispose
        $json_list= $this->selectHash($hashkey,$key);
        //最新时间
        $time=$data['report_time'];
+       //进出结果
+       $inAndOut=0;
        //是否参与计算
        $calculate=true;
        
        if($data['rssi1']==$data['rssi2']){
-
-            debug_log("InAndOUT","前后信号相等则进行过滤掉");
             $calculate=false;
        }
        $t1s= $data['rssi1']-$data['rssi2'];
        if(abs($t1s)<3){
           debug_log("InAndOUT","差值小于3不做计算");
-            $calculate=false;
+          $calculate=false;
        }
 
        if($calculate==false){
@@ -151,11 +153,11 @@ class dispose
                 $arr=[
                     "a"=>[],
                     'status'=> ['time'=>null,'dirt'=>null],
-                    "time"=>$time //最新时间
+                    "time"=>$time, //最新时间 
+                    "in_and_out"=>0   //进出结果
                 ];   
             }else{
                 $json_list['time']=$time;
-               
             }
             $this->setHash($hashkey,$key,$json_list);
             return;
@@ -174,18 +176,23 @@ class dispose
             $arr=[
                 "a"=>[['time'=>$time,'dirt'=>$res]],
                 'status'=> ['time'=>null,'dirt'=>null],
-                "time"=>$time //最新时间
+                "time"=>$time, //最新时间
+                "in_and_out"=>0
             ];
             debug_log("InAndOUT","数据不存在,直接存储新数据".json_encode($arr));
             $this->setHash($hashkey,$key,$arr);
             return;
        }else{
+
+
          $resArray=['time'=>$data['report_time'],'dirt'=>$res];
          debug_log("InAndOUT","缓存的数据".json_encode($json_list));
          $s=$json_list;
          //数据列表
          $list=$s['a'];
-         //状态
+        //进出结果
+         $inAndOut=$s["in_and_out"];
+        //状态
          $status=$s['status'];
          array_push($list,$resArray);
         while(count($list)>5){
@@ -209,12 +216,9 @@ class dispose
                 }
                  $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{
 
@@ -225,7 +229,7 @@ class dispose
                $res=$reverse[0]['dirt'];
                foreach($reverse as $aitem){
                    if($aitem['dirt']!=$res){
-                     $IS_OK=false;
+                      $IS_OK=false;
                    } 
                }
             //    if(($reverse[0]['dirt']==$reverse[1]['dirt'])&&($reverse[1]['dirt']==$reverse[2]['dirt'])){
@@ -246,6 +250,7 @@ class dispose
                                 'time'=>$resArray['time'],
                                 'dirt'=> $status['dirt']==1?1:2 //1是进 2是出
                             ];
+                            $inAndOut=$status['dirt']==1?1:2;
                             $url_data=[
                                 "mac"=>$data['mac'],
                                 "data"=>$data_array
@@ -253,13 +258,7 @@ class dispose
                             $this->getRemoteData($url_data);
                             //清除缓存数据
                             $this->get_label_history(3,$data['mac'],$data['label']);
-                            // 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);
-                        
-
-                           $this->temporary_label($this->redis,$data['label'],2);
+                            $this->temporary_label($this->redis,$data['label'],2);
                           $status['dirt']=$res;
                           $status['time']=$time;
 
@@ -274,7 +273,8 @@ class dispose
             $arr=array(
                 "a"=>$list,
                 'status'=>$status,
-                "time"=>$time
+                "time"=>$time,
+                "in_and_out"=>$inAndOut
             );
             debug_log("InAndOUT","存入缓存中:".json_encode($arr));
             $this->setHash($hashkey,$key,$arr);
@@ -366,13 +366,25 @@ public function set_label_history($data){
     $tail=$data["label"]."_tail";
     //保存头部
     $head_data= $this->selectHash($key,$head);
+    $tail_data=$this->selectHash($key,$tail);
+    debug_log("InAndOUT","最旧信号间隔".($data["report_time"]-$tail_data[count($tail_data)-1]["report_time"]));
+    if(!empty($tail_data)){
+        if(($data["report_time"]-$tail_data[count($tail_data)-1]["report_time"])>6){
+          $head_data=[];
+          $tail_data=[];
+        }
+     }
+
     if(empty($head_data)||count($head_data)<3){
+       
         $head_data=empty($head_data)?[]: $head_data;
+        
         array_push($head_data,$data);
         $this->setHash($key,$head,$head_data);
     }
     //保存尾部标签数据
-    $tail_data=$this->selectHash($key,$tail);
+    
+   
     $tail_data=empty($tail_data)?[]: $tail_data;
     array_push($tail_data,$data);
     while(count($tail_data)>3){