|
@@ -13,7 +13,10 @@ class dispose
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 校验数据 如果相同标签的上一条相同位置的信号有值(不是100),而当前数据为100(实际上是信号可能没收到)则标签信号
|
|
|
+ * 在上一条标签信号基础上+8
|
|
|
+ */
|
|
|
|
|
|
public function check_data($data){
|
|
|
|
|
@@ -21,16 +24,16 @@ class dispose
|
|
|
$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){
|
|
|
+ if($data["rssi1"]==100&&!empty($old_data)){
|
|
|
+ if($old_data["rssi1"]<100){
|
|
|
$data["rssi1"]=$old_data["rssi1"]+8;
|
|
|
- $data["rssi1"]= $data["rssi1"]>90 ? 90:$data["rssi1"];
|
|
|
+ $data["rssi1"]= $data["rssi1"]>100 ? 100:$data["rssi1"];
|
|
|
}
|
|
|
}
|
|
|
- if($data["rssi2"]==90&&!empty($old_data)){
|
|
|
- if($old_data["rssi2"]<90){
|
|
|
+ if($data["rssi2"]==100&&!empty($old_data)){
|
|
|
+ if($old_data["rssi2"]<100){
|
|
|
$data["rssi2"]=$old_data["rssi2"]+8;
|
|
|
- $data["rssi2"]= $data["rssi2"]>90 ? 90:$data["rssi2"];
|
|
|
+ $data["rssi2"]= $data["rssi2"]>100 ? 100:$data["rssi2"];
|
|
|
}
|
|
|
}
|
|
|
$this->setHash($hashKey,$key,$data);
|
|
@@ -58,18 +61,20 @@ class dispose
|
|
|
$inAndOut=0;
|
|
|
//是否参与计算
|
|
|
$calculate=true;
|
|
|
-
|
|
|
+ //前后信号如果一致 不参与计算
|
|
|
if($data['rssi1']==$data['rssi2']){
|
|
|
$calculate=false;
|
|
|
}
|
|
|
+ //前后信号差值小于3不参与计算,但是时间依旧保留
|
|
|
$t1s= $data['rssi1']-$data['rssi2'];
|
|
|
if(abs($t1s)<3){
|
|
|
debug_log("InAndOUT","差值小于3不做计算");
|
|
|
$calculate=false;
|
|
|
}
|
|
|
-
|
|
|
+ //如果redis没有缓存该标签的信号则创建,如果存在则更新最新时间
|
|
|
if($calculate==false){
|
|
|
if(!$json_list){
|
|
|
+
|
|
|
$arr=[
|
|
|
"a"=>[],
|
|
|
'status'=> ['time'=>null,'dirt'=>null],
|
|
@@ -83,14 +88,14 @@ class dispose
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //rssi1强 则前面强,否则后面强
|
|
|
if($data['rssi1']<$data['rssi2']){
|
|
|
$res=1;
|
|
|
}
|
|
|
if($data['rssi1']>$data['rssi2']){
|
|
|
$res=2;
|
|
|
}
|
|
|
-
|
|
|
+ //没有缓存的标签的数据则创建
|
|
|
if(!$json_list){
|
|
|
|
|
|
$arr=[
|
|
@@ -114,7 +119,9 @@ class dispose
|
|
|
$inAndOut=$s["in_and_out"];
|
|
|
//状态
|
|
|
$status=$s['status'];
|
|
|
+ //添加数据
|
|
|
array_push($list,$resArray);
|
|
|
+ //如果缓存的数据大于5条则剔除最前面的一条
|
|
|
while(count($list)>5){
|
|
|
array_shift($list);
|
|
|
debug_log("InAndOUT","数据超过5条,剔除一条旧数据");
|
|
@@ -122,10 +129,11 @@ class dispose
|
|
|
debug_log("InAndOUT","当前队列数据:".json_encode($list));
|
|
|
$front=0;
|
|
|
$back=0;
|
|
|
+ //缓存的信号数量超过两条则参数判定方向,在里面还是在外面
|
|
|
if(count($list)>2){
|
|
|
//
|
|
|
debug_log("InAndOUT","当前队列超过两条可以计算前后:".count($list));
|
|
|
- //校验权柄
|
|
|
+ //
|
|
|
foreach($list as $item){
|
|
|
if($item['dirt']==1){
|
|
|
$front+=1;
|
|
@@ -135,25 +143,29 @@ class dispose
|
|
|
}
|
|
|
}
|
|
|
$res=$front>$back?1:2;
|
|
|
-
|
|
|
+ //判断有没有方向,没有方向则确定方向 1 为外 ,2为内
|
|
|
if(empty($status['dirt'])){
|
|
|
$status['dirt']= $res;
|
|
|
$status['time']= $resArray['time'];
|
|
|
debug_log("InAndOUT","初始化状态为:".json_encode($status));
|
|
|
|
|
|
}else{
|
|
|
+ //如果形成初始方向,且上一次连续时间上报的数据也没有形成考勤,则判断上次最后的方向,和这次初始方向是否一致,
|
|
|
+ //例子 如果上次最后的方向是里面强,而这次的初始方向是外面强,则给上次没有形成考勤的数据补充一个"出"这个结果
|
|
|
$this->no_check_data($data['mac'],$data['label'],$status['dirt'],$time,2);
|
|
|
//判断是否连贯
|
|
|
$IS_OK=true;
|
|
|
$res=0;
|
|
|
$reverse=array_reverse($list);
|
|
|
$res=$reverse[0]['dirt'];
|
|
|
+ //判断所有的信号方向是是一个朝向强
|
|
|
foreach($reverse as $aitem){
|
|
|
if($aitem['dirt']!=$res){
|
|
|
$IS_OK=false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ //判断这个方向是否和初始确定的方向是否不一致
|
|
|
+ //如果存储的初始方向 是1 (外面强) ,$res的方向是2 ,说明形成进去这个考勤结果
|
|
|
//进行保存
|
|
|
if($res!=$status['dirt']&&$IS_OK){
|
|
|
|
|
@@ -177,7 +189,7 @@ class dispose
|
|
|
"a"=>$list,
|
|
|
'status'=>$status,
|
|
|
"time"=>$time,
|
|
|
- "in_and_out"=>$inAndOut
|
|
|
+ "in_and_out"=>$inAndOut //如果有形成考勤,则in_and_out 记录存储形成考勤的方向 1是进,2是出
|
|
|
);
|
|
|
debug_log("InAndOUT","存入缓存中:".json_encode($arr));
|
|
|
$this->setHash($hashkey,$key,$arr);
|
|
@@ -329,7 +341,7 @@ public function set_label_history($data){
|
|
|
$tail_data=[];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ //保存头部的标签数据
|
|
|
if(empty($head_data)||count($head_data)<3){
|
|
|
|
|
|
$head_data=empty($head_data)?[]: $head_data;
|
|
@@ -409,6 +421,7 @@ public function get_label_history($type,$mac,$label){
|
|
|
debug_log("clear_label","二次生成发送给远程".json_encode($url_data));
|
|
|
//远程推送时间
|
|
|
$this->set_time_results($mac,$label,$time,$dir);
|
|
|
+ //清空记录
|
|
|
$this->no_check_data($mac,$label,null,null,3);
|
|
|
//远程推送
|
|
|
$this->getRemoteData($url_data);
|
|
@@ -440,9 +453,10 @@ public function second_create_direction($mac,$label){
|
|
|
$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)){
|
|
@@ -456,6 +470,7 @@ public function second_create_direction($mac,$label){
|
|
|
if(count($head_data)<3){
|
|
|
return false;
|
|
|
}
|
|
|
+ //判断前几条数据的初始朝向
|
|
|
foreach($head_data as $item){
|
|
|
if($item["rssi1"]<$item["rssi2"]){
|
|
|
$front+=1;
|
|
@@ -467,7 +482,7 @@ public function second_create_direction($mac,$label){
|
|
|
$head_dir=$front>$behind?1:2;
|
|
|
$front=0;
|
|
|
$behind=0;
|
|
|
-
|
|
|
+//判断后几条数据的初始朝向
|
|
|
foreach($tail_data as $item){
|
|
|
if($item["rssi1"]<$item["rssi2"]){
|
|
|
$front+=1;
|
|
@@ -480,6 +495,7 @@ public function second_create_direction($mac,$label){
|
|
|
if($tail_dir== $head_dir){
|
|
|
return false;
|
|
|
}
|
|
|
+ //判断能否生成考勤 1 进 2 出
|
|
|
if($head_dir==1){
|
|
|
$res=1;
|
|
|
}else{
|
|
@@ -488,6 +504,7 @@ public function second_create_direction($mac,$label){
|
|
|
|
|
|
$frontMax= $this->get_label_history(4,$mac,$label);
|
|
|
debug_log("second_dirt","标签.$label.的最朝外的最大值".$frontMax);
|
|
|
+ //如果朝外的信号强度最强信号高于65 则不进行计算,不生成考勤
|
|
|
if($frontMax>65){
|
|
|
debug_log("second_dirt","标签.$label.的最朝外的最小值大于65不参与计算");
|
|
|
return false;
|
|
@@ -504,10 +521,12 @@ public function second_create_direction($mac,$label){
|
|
|
debug_log("second_dirt","当天早上7点之前进寝室,不做二次计算");
|
|
|
return false;
|
|
|
}
|
|
|
+ //获取该标签上次的考勤时间和考勤结果
|
|
|
$befor_res= $this->get_time_results($mac,$label,2);
|
|
|
|
|
|
if(!empty($befor_res)){
|
|
|
debug_log("second_dirt","间隔时间".json_encode($befor_res));
|
|
|
+ //如果上次考勤结果和这次考勤结果方向一致,并且间隔时间小于1小时,则不生成考勤
|
|
|
if($befor_res['dir']==$res){
|
|
|
$interval_time=$time-$befor_res["time"];
|
|
|
debug_log("second_dirt","间隔时间".$interval_time);
|