#ifndef _AREA_HPP_ #define _AREA_HPP_ #include #include #include #include #include //下午查看代码,整理了一下思路,如下 //普通区域和考勤区域就不分开了,使用同一个具现类,至于里面的操作,是否区域告警之类的可以通过数据库配置进行控制,比如超员可以查看超员配置是否为0,0则不会进行告警 //其他区域 井上和井下 考勤区域则不在区域模块进行考虑 //猴车区域拥有一般区域的行为,所以打算通过继承方式 //区域超速win版本有实现,没有应用,统一是井下超速,这里待讨论 //区域超员win版本是通过一个线程循环来进行判断的。这里我觉着可以不采用 //区域超时win版本的确是当有点过来的时候才会进行判断。这里需讨论是否满足需求,即丢失信号,是否进行告警判断 //告警对象:分井下 卡 分站 区域 ,不同的告警对象下分不同的告警类型,告警类型分人和车(win版本设计)。 //考虑到业务需要,以及重叠区域,之前(志军哥)的代码设计可能不使用。至于以后是否考虑重叠区域,后续可以有需求再处理。 //代码中有对通过坐标点找不到区域的逻辑,使用的是分站注册时候的区域id,这块是否沿用之前思路。 //益俊那边的json组装需尽快提供 //月腾那边的区域代码逻辑尽快完善,这边可能需要在你代码实现的基础上进行操作,框架可以先给我 //区域超员,超时,人车阈值win版本不同,这里需讨论 //区域进出,插入的数据库表,人车分离。 struct area_hover; struct point; struct area { area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid) :m_id(id) ,m_limit_time_second(limit_time_person) ,m_limit_person_count(limit_count_person) ,m_scale(scale) ,m_mapid(mapid) { } virtual void on_hover(int64_t card_id,std::shared_ptr&c,double speed,uint64_t type); virtual void on_enter(int64_t card_id,std::shared_ptr&c,double speed,uint64_t type); virtual void on_leave(int64_t card_id,std::shared_ptr&c,double speed,uint64_t type); bool in_area(const point & p); int id()const { return m_id; } int mapid()const { return m_mapid; } double scale()const { return m_scale; } virtual ~area() {} std::vector m_bound; private: std::atomic m_card_count; int m_id; double m_limit_speed; int m_limit_time_second; int m_limit_person_count; double m_scale; int32_t m_mapid; }; struct area_list:single_base> { area_list(); std::shared_ptr get_area(const point&pt); std::vector init_path(std::string &str); void init_from_db(); void init_monkeycar_area(); }; struct area_hover { std::shared_ptr m_area; time_t m_enter_time,m_last_time; point m_enter_point,m_last_point; int m_num_speeding; bool m_is_over_time; int landmark_id; int landmark_dir; double landmark_dis; area_hover()=default; area_hover(std::shared_ptr&area,const point&pt,double speed) :m_area(area) { m_enter_time=m_last_time=time(0); m_enter_point=m_last_point=pt; m_num_speeding=0; landmark_id=0; landmark_dir=0; landmark_dis=0; } int id()const { return m_area->id(); } int mapid()const { return m_area->mapid(); } double scale()const { return m_area->scale(); } bool operator == (const area_hover&o)const { return m_area->id()==o.m_area->id(); } bool operator < (const area_hover&o)const { return m_area->id()id(); } std::tuple getLandmark() { return std::make_tuple(m_enter_time,m_last_time,mapid(),id(),landmark_id,landmark_dir,landmark_dis); } void setLandmark(const point &pt); void set(const point&pt) { m_last_time=time(0); m_last_point = pt; } }; //每张卡包含一个对象 //在解析出数据点时,调用on_point struct area_tool { std::shared_ptr m_area_hover=nullptr; void on_point(int64_t card_id,const point&pt,double speed,int16_t type); void setLandmark(const point &pt) { if(m_area_hover) { m_area_hover->setLandmark(pt); } } std::tuple getLandmark() { if(m_area_hover) return m_area_hover->getLandmark(); else return std::make_tuple(0,0,0,0,0,0,0); } //检测是否超时 void on_timer(int64_t card_id) { } void do_hover_biz(int64_t card_id,double speed,int16_t type) { m_area_hover->m_area->on_hover(card_id,m_area_hover,speed,type); } void do_enter_biz(int64_t card_id,double speed,int16_t type) { m_area_hover->m_area->on_enter(card_id,m_area_hover,speed,type); } void do_leave_biz(int64_t card_id,double speed,int16_t type) { m_area_hover->m_area->on_leave(card_id,m_area_hover,speed,type); } }; #endif