Browse Source

增加历史轨迹点补卡坐标功能

lixioayao 5 years ago
parent
commit
06ff956bab
9 changed files with 95 additions and 42 deletions
  1. 1 0
      ant.cpp
  2. 1 0
      card.cpp
  3. 2 2
      card.h
  4. 1 1
      card_base.cpp
  5. 1 1
      card_car.cpp
  6. 1 1
      card_person.cpp
  7. 74 14
      his_location.h
  8. 12 13
      main.cpp
  9. 2 10
      module_service/area_business_work_rate.cpp

+ 1 - 0
ant.cpp

@@ -374,6 +374,7 @@ void sit_list::read_ant_path(int id)
 
 	test_find_path(card_path::inst(),point(4727,-8.06),point(2200,-75));
 	test_find_path(card_path::inst(),point(4727,-8.06),point(2600,-100));
+	test_find_path(card_path::inst(),point(2768.50,-75.00),point(2768.50,-161.58));
 	test_find_path(card_path::inst(),point(4727,-8.06),point(5427.04,-304.02));
 	test_find_path(card_path::inst(),point(4714.70,-8.06),point(5427.04,-304.02));
 }

+ 1 - 0
card.cpp

@@ -18,6 +18,7 @@
 #include "mine_business.h"
 
 extern config_file config;
+const int three_rates_flag=config.get("service.three_rates_flag",0);
 void card_list::init_staffer(const std::string & lszId64)
 {
     std::string strategy = config.get("person.strategy","PS_1");

+ 2 - 2
card.h

@@ -5,7 +5,7 @@
 
 #include "card_base.h"
 #include "write-copy.h"
-
+extern const int three_rates_flag;
 struct card_list_visit:visitor<std::shared_ptr<card_location_base>>
 {
 	bool visit(std::shared_ptr<card_location_base> c);
@@ -28,4 +28,4 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
     std::shared_ptr<card_location_base> get_card_by_cid(int cid);
     ~card_list(){}
 };
-#endif
+#endif

+ 1 - 1
card_base.cpp

@@ -20,11 +20,11 @@
 #include "area.h"
 #include "cardMgr.h"
 extern config_file config;
-const static int three_rates_flag=config.get("service.three_rates_flag",0);
 card_location_base::card_location_base(const std::string&type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid)
 	:card(id,dis,t,deptid,level_id,cid)
 {
     select_tool_manage::instance()->create_tool(type,m_sel_tool,m_smo_tool);
+	m_his_location_card.reset(new location_card(m_id,m_type,cid));
 }
 
 void card_location_base::do_status(int st)

+ 1 - 1
card_car.cpp

@@ -18,7 +18,7 @@ car::car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,i
 	 ,m_vehicle_type_id(type_id)
 {
 	m_message_handle.reset(new card_message_handle(this));
-	m_his_location_card.reset(new location_vehicle(m_id,m_type,cid));
+	//m_his_location_card.reset(new location_vehicle(m_id,m_type,cid));
 }
 
 car::~car(){}

+ 1 - 1
card_person.cpp

@@ -29,7 +29,7 @@ person::person(const std::string &type,uint32_t cardid,uint16_t needdisplay,int1
 	,m_deptName(dname)
 {
 	m_message_handle.reset(new card_message_handle(this));
-	m_his_location_card.reset(new location_staff(m_id,m_type,cid));
+	//m_his_location_card.reset(new location_staff(m_id,m_type,cid));
 }
 
 person::~person()

+ 74 - 14
his_location.h

@@ -148,15 +148,24 @@ struct location_card
 		
 		if(!is_valid())
 		{
-		  if(p==m_p)
-		  {
-			  init_att();set(p,timestamp);
-			  m_d.emplace(p,timestamp);
-			  return ;
-		  }
-		  m_arg=make_arg(p,m_p);
-		  log_info("his_location:%d arg:%f",m_cardid,m_arg);
-		  insert();
+            //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);
+			    return ;
+            }
+            auto v=find_path(m_p,p);
+            if(v.empty())
+		        m_arg=make_arg(p,m_p);
+            else
+            {
+                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);
+                return;
+            }
+		    log_info("his_location:%d arg:%f",m_cardid,m_arg);
+		    insert();
 		}
 		bool flag=false;
 		bool iflag=false;
@@ -177,10 +186,9 @@ struct location_card
 			insert();
 		}
 	}
-	virtual std::string getTabName()=0;
 	void insert()
 	{
-		std::string tabName=getTabName();
+		//std::string tabName=getTabName();
 		char nsql[512]={0};
 		const char * sql = "replace into his_location (obj_id,card_type_id,ident,begin_time,map_id,area_id,begin_pt,direction)"
 		                   "values(%d,%d,%d,'%s',%d,%d,'%.2f,%.2f',%f);";
@@ -190,7 +198,7 @@ struct location_card
 	}
 	void update(const point &p,uint64_t timestamp)
 	{
-		std::string tabName=getTabName();
+		//std::string tabName=getTabName();
 		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);
@@ -202,9 +210,61 @@ struct location_card
 		log_info("his_location[%d]:%s",m_cardid,nsql);
 		sDBConnPool.PushAsync(nsql);
 	}
+    std::vector<point> find_path(const point &p1,const point &p2)
+    {
+        std::vector<point> rc=card_path::inst().find_path(point(p1.x,-p1.y),point(p2.x,-p2.y));
+        return std::move(rc);
+    }
+	//virtual bool  handle_message(const point &p,uint64_t timestamp)=0;
+	bool  handle_message(const point &p,uint64_t timestamp)
+    {
+		bool flag = false;
+		if(line_changed(p))
+        {
+            flag = true;
+            std::vector<point> rc=find_path(m_d.back().p,p);
+            if(rc.empty())
+            {
+			    log_info("his_location:line_changed rc.empty() %d",m_cardid);
+			    update(m_d.back().p,m_d.back().time);
+			    set(m_d.back().p,m_d.back().time);
+            }
+            else
+            {
+                if(handle_path(rc,timestamp,false))
+                  return true;
+            }
+            //置m_arg非法
+			init_att();
+        }
+        return flag;
+    }
+    bool handle_path(std::vector<point> &rc,uint64_t timestamp,bool flag)
+    {
+        double dis=0;point _p=m_p;
+        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;
+        if(t==0)return true;
+		double avge_speed= dis/t*1000;
+
+        for(const point & pp:rc)
+        {
+            if(flag){
+			    m_arg=make_arg(pp,m_p);insert();
+            }
+		    log_info("his_location:line_changed_x %d point(%.2f,%.2f)--circle point(%.2f,%.2f),speed:%.2f",m_cardid,m_p.x,m_p.y,pp.x,pp.y,avge_speed);
+            double dist=m_p.dist(pp);uint64_t tt=dist/avge_speed*1000;
+            uint64_t etime=m_timestamp+tt;
+			update(pp,etime);set(pp,etime);
+            flag=true;
+        }
+        return false;
+    }
 
-	virtual bool  handle_message(const point &p,uint64_t timestamp)=0;
 };
+#if 0
 struct location_staff:location_card
 {
 	location_staff(uint32_t id,uint64_t type,uint32_t objid)
@@ -228,7 +288,6 @@ struct location_staff:location_card
 			else
 			{
 				log_info("his_location:line_changed_find_path %d,(%.2f,%.2f)-->(%.2f,%.2f)-->(%.2f,%.2f)",m_cardid,m_p.x,m_p.y,m_d.back().p.x,m_d.back().p.y,p.x,p.y);
-				std::vector<point> rc=card_path::inst().find_path(point(m_d.back().p.x,-m_d.back().p.y),point(p.x,-p.y));
 				if(rc.empty())				
 				{
 					log_info("his_location:line_changed rc.empty() %d",m_cardid);
@@ -296,3 +355,4 @@ struct location_vehicle:location_card
 	}
 };
 #endif
+#endif

+ 12 - 13
main.cpp

@@ -25,10 +25,7 @@
 
 config_file config;
 void handlereader(uint32_t readerid,bool duration,uint32_t t)
-{
-
-}
-
+{}
 //三率模块中告警回调
 void Handle_ThreeRates_Event_Callback(const int evType, const int evId, uint64_t id
                                       , double limitVal, double curVal, bool bFalg)
@@ -88,15 +85,17 @@ struct Init_Setting
 		mine_business::inst()->load();
         event_list::instance()->load_his_data_from_db();
         card_list::instance()->load_his_card_postion_from_db();
-        db_para dp;	
-        dp.Host=DBSetting.Host;
-        dp.User=DBSetting.User;
-        dp.PWD=DBSetting.PWD ;
-        dp.DBName=DBSetting.DBName;
-        dp.CharSet=DBSetting.CharSet ;
-        dp.TimeOut=DBSetting.TimeOut;
-        dp.PoolSize=DBSetting.PoolSize;
-		init_three_rates(dp);
+        if(three_rates_flag){
+            db_para dp;	
+            dp.Host=DBSetting.Host;
+            dp.User=DBSetting.User;
+            dp.PWD=DBSetting.PWD ;
+            dp.DBName=DBSetting.DBName;
+            dp.CharSet=DBSetting.CharSet ;
+            dp.TimeOut=DBSetting.TimeOut;
+            dp.PoolSize=DBSetting.PoolSize;
+		    init_three_rates(dp);
+        }
 
 
         log_info("Init_Setting::init  Success. \n" );

+ 2 - 10
module_service/area_business_work_rate.cpp

@@ -8,9 +8,7 @@
 #include"struct_def.h"
 #include"three_rates.h"
 #include"area.h"
-#include"card.h"
 #include"tool_time.h"
-
 struct work_rate_data:business_data
 {
     work_rate_data()
@@ -27,10 +25,7 @@ void area_business_work_rate::on_load_his(const std::shared_ptr<area_hover>&area
 void area_business_work_rate::on_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
                                        const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>& ptr)
 {
-    if(!card_ptr->is_person())
-    {
-        return;
-    }
+    if(!card_ptr->is_person() || !three_rates_flag)return;
 
     auto card = std::make_shared<card_pos>();
     card->id = card_ptr->m_id;
@@ -55,10 +50,7 @@ void area_business_work_rate::on_hover(const std::shared_ptr<area_hover>&area_ho
 void area_business_work_rate::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
                                        const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
 {
-    if(!card_ptr->is_person())
-    {
-        return;
-    }
+    if(!card_ptr->is_person() || !three_rates_flag)return;
 
     auto card = std::make_shared<card_pos>();
     card->id = card_ptr->m_id;