|
@@ -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<1.5)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;
|
|
@@ -151,8 +167,7 @@ struct location_card
|
|
//if(p==m_p)
|
|
//if(p==m_p)
|
|
if(point::eq(p.x,m_p.x,0.2) && point::eq(p.y,m_p.y,0.2))
|
|
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 ;
|
|
return ;
|
|
}
|
|
}
|
|
auto v=find_path(m_p,p);
|
|
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);
|
|
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);
|
|
handle_path(v,timestamp,true);
|
|
|
|
+ set_invalid();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
log_info("his_location:%d arg:%f",m_cardid,m_arg);
|
|
log_info("his_location:%d arg:%f",m_cardid,m_arg);
|
|
insert();
|
|
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;
|
|
@@ -202,8 +220,8 @@ struct location_card
|
|
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());
|
|
@@ -219,7 +237,8 @@ struct location_card
|
|
bool handle_message(const point &p,uint64_t timestamp)
|
|
bool handle_message(const point &p,uint64_t timestamp)
|
|
{
|
|
{
|
|
bool flag = false;
|
|
bool flag = false;
|
|
- if(line_changed(p))
|
|
|
|
|
|
+ int df=0;
|
|
|
|
+ if(line_changed(p,df))
|
|
{
|
|
{
|
|
flag = true;
|
|
flag = true;
|
|
std::vector<point> rc=find_path(m_d.back().p,p);
|
|
std::vector<point> rc=find_path(m_d.back().p,p);
|
|
@@ -235,8 +254,9 @@ struct location_card
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
//置m_arg非法
|
|
//置m_arg非法
|
|
- init_att();
|
|
|
|
|
|
+ set_invalid();
|
|
}
|
|
}
|
|
|
|
+ if(df==1)flag=true;
|
|
return flag;
|
|
return flag;
|
|
}
|
|
}
|
|
bool handle_path(std::vector<point> &rc,uint64_t timestamp,bool 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){
|
|
std::for_each(rc.begin(),rc.end(),[&dis,&_p](point &pt){
|
|
pt.y=-pt.y;dis+=_p.dist(pt);_p=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;
|
|
if(t==0)return true;
|
|
- double avge_speed= dis/t*1000;
|
|
|
|
|
|
+ double avge_speed= dis/t;
|
|
|
|
|
|
for(const point & pp:rc)
|
|
for(const point & pp:rc)
|
|
{
|
|
{
|