|
@@ -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
|