likang hace 2 años
padre
commit
906efc35b3
Se han modificado 2 ficheros con 192 adiciones y 44 borrados
  1. 63 38
      catch/api/controller/Api.php
  2. 129 6
      catch/api/service/dispose.php

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 63 - 38
catch/api/controller/Api.php


+ 129 - 6
catch/api/service/dispose.php

@@ -251,6 +251,8 @@ class dispose
                                 "data"=>$data_array
                             ];
                             $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";
@@ -277,7 +279,6 @@ class dispose
             debug_log("InAndOUT","存入缓存中:".json_encode($arr));
             $this->setHash($hashkey,$key,$arr);
             debug_log("InAndOUT",'操作结束');
-
        }
 
     }
@@ -353,6 +354,130 @@ public function getRemoteData($data){
     $redis->Rpush($key,json_encode($data));
     
 }
+/**
+ * 历史标签信号
+ *
+ * @return void
+ */
+public function set_label_history($data){
+    $MAC=$data["mac"];
+    $key=$MAC."_label_history";
+    $head=$data['label']."_head";
+    $tail=$data["label"]."_tail";
+    //保存头部
+    $head_data= $this->selectHash($key,$head);
+    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){
+        array_shift($tail_data);
+    }
+    $this->setHash($key,$tail,$tail_data);
+}
+/**
+ * 获取基站
+ *
+ * @param [type] $type  1 头部  2 尾部 3清空
+ * @param [type] $mac  
+ * @param [type] $label 
+ * @return void
+ */
+public function get_label_history($type,$mac,$label){
+ 
+    $key=$mac."_label_history";
+    $head=$label."_head";
+    $tail=$label."_tail";
+    if($type==1){
+        $head_data= $this->selectHash($key,$head);
+        return $head_data;
+    }
+    if($type==2){
+        $tail_data= $this->selectHash($key,$tail);
+        return $tail_data;
+    }
+    if($type==3){
+        debug_log("InAndOUT","清空头部和尾部历史:".$mac." ".$label);
+        $tail_data= $this->delHash($key,$head);
+        $tail_data= $this->delHash($key,$tail);
+    }
+}
+/**
+ * 二次生成进出
+ *
+ * @return void
+ */
+public function second_create_direction($mac,$label){
+    debug_log("second_dirt","==============mac:".$mac."=======label".$label."================================");
+    $key=$mac."_label_history";
+    $head=$label."_head";
+    $tail=$label."_tail";
+    $head_dir=0;
+    $tail_dir=0;
+    $front=0;
+    $behind=0;
+    $res=0;
+    $time=0;
+
+   $head_data= $this->get_label_history(1,$mac,$label);
+   $tail_data= $this->get_label_history(2,$mac,$label);
+   debug_log("second_dirt","头部标签数据".json_encode($head_data));
+   debug_log("second_dirt","尾部标签数据".json_encode($tail_data));
+   if(empty($head_data)){
+       return false; 
+   }
+   
+   if(empty($tail_data)){
+        return false; 
+    }
+
+   if(count($head_data)<3){
+        return false;
+   }
+   foreach($head_data as $item){
+        if($item["rssi1"]<$item["rssi2"]){
+            $front+=1;
+        }
+        if($item["rssi1"]<$item["rssi2"]){
+            $behind+=1;
+        }
+   }
+   
+    $head_dir=$front>$behind?1:2;
+    $front=0;
+    $behind=0;
+
+    foreach($tail_data as $item){
+        if($item["rssi1"]<$item["rssi2"]){
+            $front+=1;
+        }
+        if($item["rssi1"]<$item["rssi2"]){
+            $behind+=1;
+        }
+        $time=$item['report_time'];
+   }
+   $tail_dir=$front>$behind?1:2;
+   if($tail_dir== $head_dir){
+        return false;
+   }
+   if($head_dir==1){
+        $res=2;
+   }else{
+        $res=1;
+   }
+   
+   debug_log("second_dirt","最终结果".json_encode(["dir"=>$res,"time"=>$time]));
+    return ["dir"=>$res,"time"=>$time];
+
+}
+
+
+
 
 
 
@@ -370,6 +495,9 @@ public function getRemoteData($data){
     public function setHash($hashKey,$key,$data){
        $this->redis->hSet($hashKey,$key,json_encode($data));
       
+    } 
+    public function delHash($hashKey,$key){
+        $this->redis->Hdel($hashKey,$key);
     }
 
     public function temporary_label($redis,$label,$type){
@@ -426,11 +554,6 @@ public function getRemoteData($data){
         }
         debug_log("in_label","标签总数".count($array));
           
-       
-
-
-
-
 
 
     }