Jelajahi Sumber

优化历史轨迹点,优化人一多卡逻辑.

lixioayao 5 tahun lalu
induk
melakukan
787b684b6d
2 mengubah file dengan 58 tambahan dan 22 penghapusan
  1. 21 5
      bindmorecard.h
  2. 37 17
      his_location.h

+ 21 - 5
bindmorecard.h

@@ -45,6 +45,10 @@ struct Data
 		m_totaldistance = 0;
 		m_flag = false;
 	}
+    bool empty()
+    {
+        return m_index==0;
+    }
 	void increase(const int index)
 	{
 		m_ct[index]++;
@@ -108,8 +112,8 @@ struct TcardInterface
 					skip(1);
 				}
 				grow(tsp);
-				tmp_tsp_min = back(0).m_timestamp;
-				tmp_tsp_max = back(0).m_timestamp + TIME_WIN_MILLISEC;
+				tmp_tsp_min = tsp;
+				tmp_tsp_max = tsp + TIME_WIN_MILLISEC;
 			}
             else
             {
@@ -140,14 +144,26 @@ struct TcardInterface
 	{
 		return m_arr.empty();
 	}
+    bool empty_slop()
+    {
+        return back(0).empty();
+    }
 	int size() 
 	{
 		return m_arr.size();
 	}
 	void  grow(uint64_t ct)
 	{
-		Data d(ct);
-		m_arr.push_back(d);
+        if(size()&&empty_slop())
+        {
+            back(0).reset();
+            back(0).m_timestamp=ct;
+        }
+        else
+        {
+		    Data d(ct);
+		    m_arr.push_back(d);
+        }
 	}
 	Data &back(int index)
 	{
@@ -163,7 +179,7 @@ struct TcardInterface
 	}
 	bool timeout()
 	{
-		return size() == SIZE;
+		return (size()==SIZE) && !empty_slop();
 	}
 	std::string getInfo_1()
 	{

+ 37 - 17
his_location.h

@@ -28,6 +28,7 @@ struct location_card
 	int 		m_mapid;//地图
 	uint64_t	m_timestamp;//入库后的时间
 	point		m_p;//入库后的点
+    int         m_direct_index;
 	struct mini_data
 	{
 		mini_data(const point &p,uint64_t t)
@@ -44,13 +45,15 @@ struct location_card
 		m_mapid=-1;
 		m_timestamp=0;
 		m_p.set(0,0);
-		init_att();
+		std::queue<mini_data> tmp;
+		m_d.swap(tmp);
+        m_direct_index=0;
 	}
-	void init_att()
+	void init_att(const point &pt,uint64_t time)
 	{
-		m_arg=0x12345678;
 		std::queue<mini_data> tmp;
 		m_d.swap(tmp);
+        m_d.emplace(pt,time);
 	}
 	void set_invalid()
 	{
@@ -69,21 +72,34 @@ struct location_card
 	{
 		m_timestamp=time;
 		m_p.set(pt);
+        init_att(pt,time);
 	}
-	bool line_changed(const point &pt)
+	bool line_changed(const point &pt,int &df)
 	{
 		if(!is_valid())
 		  return false;
-		point p=m_d.back().p;
+        point p;
+        if(m_d.empty())p=m_p;  else p=m_d.back().p;
 
 		if(point::eq(p.x,pt.x,0.2) && point::eq(p.y,pt.y,0.2)) return false;
         double dis1=m_p.dist(pt);
         if(dis1<1.5)return false;
         double dis = p.dist(pt);
 		double arg = make_arg(pt,p);
-		log_info("his_location:line_changed:%d,%f,m_arg:%f,%s,%f,%f",m_cardid,arg,m_arg, (arg-m_arg > -1e-10 && arg-m_arg<1e-10)?"same":"not same",m_arg-arg,dis);
-        if(dis<0.5 && fabs(fabs(arg)+fabs(m_arg)-3.141593)< 0.000005)
-          return false;
+        //查看路径方向是否改变
+        bool change_flag=(arg-m_arg > -1e-10 && arg-m_arg<1e-10);
+        //change_flag为true,标识没有发生变化
+        if(change_flag)m_direct_index=0;
+		log_info("his_location:line_changed:%d,%f,m_arg:%f,%s,%f,%f",m_cardid,arg,m_arg, change_flag?"same":"not same",m_arg-arg,dis);
+        //if(dis<0.5 && fabs(fabs(arg)+fabs(m_arg)-3.141593)< 0.000005)
+        //判断5次反向才做下一步动作
+        if(fabs(fabs(arg)+fabs(m_arg)-3.141593)< 0.000005)
+        {
+            if(++m_direct_index<=10)
+            {
+                df=1;return false;
+            }
+        }
 		return !point::eq(arg,m_arg,1e-10);
 	}
 	bool is_speed_changed(const point& pt,uint64_t time)
@@ -138,7 +154,7 @@ struct location_card
 	}
 	void push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid)
 	{
-		if(m_p.empty() || m_timestamp==0||m_areaid<=0||m_mapid<=0)	
+		if(m_p.empty() || m_timestamp==0||m_areaid<0||m_mapid<0)	
 		{
 		  set(p,timestamp);
 		  m_areaid=areaid;m_mapid=mapid;
@@ -151,8 +167,7 @@ struct location_card
             //if(p==m_p)
 		    if(point::eq(p.x,m_p.x,0.2) && point::eq(p.y,m_p.y,0.2))
             {
-		        init_att();set(p,timestamp);
-			    m_d.emplace(p,timestamp);
+		        set(p,timestamp);
 			    return ;
             }
             auto v=find_path(m_p,p);
@@ -162,13 +177,16 @@ struct location_card
             {
                 log_info("his_location:more_abnormal_point....%d,(%.2f,%.2f)---(%.2f,%.2f)",m_cardid,m_p.x,m_p.y,p.x,p.y);
                 handle_path(v,timestamp,true);
+                set_invalid();
                 return;
             }
 		    log_info("his_location:%d arg:%f",m_cardid,m_arg);
 		    insert();
+            return;
 		}
 		bool flag=false;
 		bool iflag=false;
+        //判断是否路径发生了变化
 		flag=handle_message(p,timestamp);
 		//if(time_out(p,timestamp))
 		//	if(!flag)iflag=true;
@@ -202,8 +220,8 @@ struct location_card
 		char nsql[512]={0};
 		const char * sql = "update his_location set last_time='%s',speed=%.2f where obj_id=%d and begin_time='%s' and last_time is null;";
 		double dist = m_p.dist(p);
-		double t	= timestamp - m_timestamp;
-		double avge_speed= dist/t*1000;
+		double t	= (timestamp - m_timestamp)/1000;
+		double avge_speed= dist/t;
 		if(std::isnan(avge_speed)|| std::isinf(avge_speed))avge_speed=0;
 
 		snprintf(nsql,512,sql,tool_time::to_str(timestamp/1000).c_str(),avge_speed,m_objid,tool_time::to_str(m_timestamp/1000).c_str());
@@ -219,7 +237,8 @@ struct location_card
 	bool  handle_message(const point &p,uint64_t timestamp)
     {
 		bool flag = false;
-		if(line_changed(p))
+        int df=0;
+		if(line_changed(p,df))
         {
             flag = true;
             std::vector<point> rc=find_path(m_d.back().p,p);
@@ -235,8 +254,9 @@ struct location_card
                   return true;
             }
             //置m_arg非法
-			init_att();
+            set_invalid();
         }
+        if(df==1)flag=true;
         return flag;
     }
     bool handle_path(std::vector<point> &rc,uint64_t timestamp,bool flag)
@@ -245,9 +265,9 @@ struct location_card
         std::for_each(rc.begin(),rc.end(),[&dis,&_p](point &pt){
                     pt.y=-pt.y;dis+=_p.dist(pt);_p=pt;
                     });
-		uint64_t t=timestamp - m_timestamp;
+		uint64_t t=timestamp/1000 - m_timestamp/1000;
         if(t==0)return true;
-		double avge_speed= dis/t*1000;
+		double avge_speed= dis/t;
 
         for(const point & pp:rc)
         {