|
@@ -28,6 +28,7 @@ struct location_card
|
|
int m_mapid;//地图
|
|
int m_mapid;//地图
|
|
uint64_t m_timestamp;//入库后的时间
|
|
uint64_t m_timestamp;//入库后的时间
|
|
point m_p;//入库后的点
|
|
point m_p;//入库后的点
|
|
|
|
+ int m_direct_index;
|
|
struct mini_data
|
|
struct mini_data
|
|
{
|
|
{
|
|
mini_data(const point &p,uint64_t t)
|
|
mini_data(const point &p,uint64_t t)
|
|
@@ -44,13 +45,15 @@ struct location_card
|
|
m_mapid=-1;
|
|
m_mapid=-1;
|
|
m_timestamp=0;
|
|
m_timestamp=0;
|
|
m_p.set(0,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;
|
|
std::queue<mini_data> tmp;
|
|
m_d.swap(tmp);
|
|
m_d.swap(tmp);
|
|
|
|
+ m_d.emplace(pt,time);
|
|
}
|
|
}
|
|
void set_invalid()
|
|
void set_invalid()
|
|
{
|
|
{
|
|
@@ -69,21 +72,34 @@ struct location_card
|
|
{
|
|
{
|
|
m_timestamp=time;
|
|
m_timestamp=time;
|
|
m_p.set(pt);
|
|
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())
|
|
if(!is_valid())
|
|
return false;
|
|
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;
|
|
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);
|
|
double dis1=m_p.dist(pt);
|
|
- if(dis1<1.5)return false;
|
|
|
|
|
|
+ if(dis1<2)return false;
|
|
double dis = p.dist(pt);
|
|
double dis = p.dist(pt);
|
|
double arg = make_arg(pt,p);
|
|
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);
|
|
return !point::eq(arg,m_arg,1e-10);
|
|
}
|
|
}
|
|
bool is_speed_changed(const point& pt,uint64_t time)
|
|
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)
|
|
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);
|
|
set(p,timestamp);
|
|
m_areaid=areaid;m_mapid=mapid;
|
|
m_areaid=areaid;m_mapid=mapid;
|
|
@@ -148,18 +164,29 @@ struct location_card
|
|
|
|
|
|
if(!is_valid())
|
|
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))
|
|
|
|
+ {
|
|
|
|
+ set(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);
|
|
|
|
+ set_invalid();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ log_info("his_location:%d arg:%f",m_cardid,m_arg);
|
|
|
|
+ insert();
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
bool flag=false;
|
|
bool flag=false;
|
|
bool iflag=false;
|
|
bool iflag=false;
|
|
|
|
+ //判断是否路径发生了变化
|
|
flag=handle_message(p,timestamp);
|
|
flag=handle_message(p,timestamp);
|
|
//if(time_out(p,timestamp))
|
|
//if(time_out(p,timestamp))
|
|
// if(!flag)iflag=true;
|
|
// if(!flag)iflag=true;
|
|
@@ -177,34 +204,87 @@ struct location_card
|
|
insert();
|
|
insert();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- virtual std::string getTabName()=0;
|
|
|
|
void insert()
|
|
void insert()
|
|
{
|
|
{
|
|
- std::string tabName=getTabName();
|
|
|
|
|
|
+ //std::string tabName=getTabName();
|
|
char nsql[512]={0};
|
|
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)"
|
|
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);";
|
|
"values(%d,%d,%d,'%s',%d,%d,'%.2f,%.2f',%f);";
|
|
snprintf(nsql,512,sql,m_objid,m_type,m_cardid,tool_time::to_str(m_timestamp/1000).c_str(),m_mapid,m_areaid,m_p.x,m_p.y,m_arg);
|
|
snprintf(nsql,512,sql,m_objid,m_type,m_cardid,tool_time::to_str(m_timestamp/1000).c_str(),m_mapid,m_areaid,m_p.x,m_p.y,m_arg);
|
|
- log_info("his_location[%d]:%s",m_cardid,nsql);
|
|
|
|
|
|
+ log_info("his_location[%d,%lu]:%s",m_cardid,m_timestamp,nsql);
|
|
sDBConnPool.PushAsync(nsql);
|
|
sDBConnPool.PushAsync(nsql);
|
|
}
|
|
}
|
|
void update(const point &p,uint64_t timestamp)
|
|
void update(const point &p,uint64_t timestamp)
|
|
{
|
|
{
|
|
- std::string tabName=getTabName();
|
|
|
|
|
|
+ //std::string tabName=getTabName();
|
|
char nsql[512]={0};
|
|
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;";
|
|
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 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;
|
|
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());
|
|
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());
|
|
- log_info("his_location[%d]:%s",m_cardid,nsql);
|
|
|
|
|
|
+ log_info("his_location[%d]:%s[%lu,%lu]",m_cardid,nsql,timestamp,m_timestamp);
|
|
sDBConnPool.PushAsync(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;
|
|
|
|
+ int df=0;
|
|
|
|
+ if(line_changed(p,df))
|
|
|
|
+ {
|
|
|
|
+ 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非法
|
|
|
|
+ set_invalid();
|
|
|
|
+ }
|
|
|
|
+ if(df==1)flag=true;
|
|
|
|
+ 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/1000 - m_timestamp/1000;
|
|
|
|
+ if(t==0||dis<0.1)return true;
|
|
|
|
+ double avge_speed= dis/t;
|
|
|
|
+
|
|
|
|
+ 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
|
|
struct location_staff:location_card
|
|
{
|
|
{
|
|
location_staff(uint32_t id,uint64_t type,uint32_t objid)
|
|
location_staff(uint32_t id,uint64_t type,uint32_t objid)
|
|
@@ -228,7 +308,6 @@ struct location_staff:location_card
|
|
else
|
|
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);
|
|
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())
|
|
if(rc.empty())
|
|
{
|
|
{
|
|
log_info("his_location:line_changed rc.empty() %d",m_cardid);
|
|
log_info("his_location:line_changed rc.empty() %d",m_cardid);
|
|
@@ -296,3 +375,4 @@ struct location_vehicle:location_card
|
|
}
|
|
}
|
|
};
|
|
};
|
|
#endif
|
|
#endif
|
|
|
|
+#endif
|