1
0

area.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #ifndef _AREA_HPP_
  2. #define _AREA_HPP_
  3. #include <atomic>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <point.h>
  7. #include <write-copy.h>
  8. //下午查看代码,整理了一下思路,如下
  9. //普通区域和考勤区域就不分开了,使用同一个具现类,至于里面的操作,是否区域告警之类的可以通过数据库配置进行控制,比如超员可以查看超员配置是否为0,0则不会进行告警
  10. //其他区域 井上和井下 考勤区域则不在区域模块进行考虑
  11. //猴车区域拥有一般区域的行为,所以打算通过继承方式
  12. //区域超速win版本有实现,没有应用,统一是井下超速,这里待讨论
  13. //区域超员win版本是通过一个线程循环来进行判断的。这里我觉着可以不采用
  14. //区域超时win版本的确是当有点过来的时候才会进行判断。这里需讨论是否满足需求,即丢失信号,是否进行告警判断
  15. //告警对象:分井下 卡 分站 区域 ,不同的告警对象下分不同的告警类型,告警类型分人和车(win版本设计)。
  16. //考虑到业务需要,以及重叠区域,之前(志军哥)的代码设计可能不使用。至于以后是否考虑重叠区域,后续可以有需求再处理。
  17. //代码中有对通过坐标点找不到区域的逻辑,使用的是分站注册时候的区域id,这块是否沿用之前思路。
  18. //益俊那边的json组装需尽快提供
  19. //月腾那边的区域代码逻辑尽快完善,这边可能需要在你代码实现的基础上进行操作,框架可以先给我
  20. //区域超员,超时,人车阈值win版本不同,这里需讨论
  21. //区域进出,插入的数据库表,人车分离。
  22. struct area_hover;
  23. struct point;
  24. struct area
  25. {
  26. area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid)
  27. :m_id(id)
  28. ,m_limit_time_second(limit_time_person)
  29. ,m_limit_person_count(limit_count_person)
  30. ,m_scale(scale)
  31. ,m_mapid(mapid)
  32. {
  33. }
  34. virtual void on_hover(int64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
  35. virtual void on_enter(int64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
  36. virtual void on_leave(int64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
  37. bool in_area(const point & p);
  38. int id()const
  39. {
  40. return m_id;
  41. }
  42. int mapid()const
  43. {
  44. return m_mapid;
  45. }
  46. double scale()const
  47. {
  48. return m_scale;
  49. }
  50. virtual ~area()
  51. {}
  52. std::vector<point> m_bound;
  53. private:
  54. std::atomic<int> m_card_count;
  55. int m_id;
  56. double m_limit_speed;
  57. int m_limit_time_second;
  58. int m_limit_person_count;
  59. double m_scale;
  60. int32_t m_mapid;
  61. };
  62. struct area_list:single_base<area_list,int,std::shared_ptr<area>>
  63. {
  64. area_list();
  65. std::shared_ptr<area> get_area(const point&pt);
  66. std::vector<point> init_path(std::string &str);
  67. void init_from_db();
  68. void init_monkeycar_area();
  69. };
  70. struct area_hover
  71. {
  72. std::shared_ptr<area> m_area;
  73. time_t m_enter_time,m_last_time;
  74. point m_enter_point,m_last_point;
  75. int m_num_speeding;
  76. bool m_is_over_time;
  77. int landmark_id;
  78. int landmark_dir;
  79. double landmark_dis;
  80. area_hover()=default;
  81. area_hover(std::shared_ptr<area>&area,const point&pt,double speed)
  82. :m_area(area)
  83. {
  84. m_enter_time=m_last_time=time(0);
  85. m_enter_point=m_last_point=pt;
  86. m_num_speeding=0;
  87. landmark_id=0;
  88. landmark_dir=0;
  89. landmark_dis=0;
  90. }
  91. int id()const
  92. {
  93. return m_area->id();
  94. }
  95. int mapid()const
  96. {
  97. return m_area->mapid();
  98. }
  99. double scale()const
  100. {
  101. return m_area->scale();
  102. }
  103. bool operator == (const area_hover&o)const
  104. {
  105. return m_area->id()==o.m_area->id();
  106. }
  107. bool operator < (const area_hover&o)const
  108. {
  109. return m_area->id()<o.m_area->id();
  110. }
  111. std::tuple<time_t,time_t,int,int,int,int,double> getLandmark()
  112. {
  113. return std::make_tuple(m_enter_time,m_last_time,mapid(),id(),landmark_id,landmark_dir,landmark_dis);
  114. }
  115. void setLandmark(const point &pt);
  116. void set(const point&pt)
  117. {
  118. m_last_time=time(0);
  119. m_last_point = pt;
  120. }
  121. };
  122. //每张卡包含一个对象
  123. //在解析出数据点时,调用on_point
  124. struct area_tool
  125. {
  126. std::shared_ptr<area_hover> m_area_hover=nullptr;
  127. void on_point(int64_t card_id,const point&pt,double speed,int16_t type);
  128. void setLandmark(const point &pt)
  129. {
  130. if(m_area_hover)
  131. {
  132. m_area_hover->setLandmark(pt);
  133. }
  134. }
  135. std::tuple<time_t,time_t,int,int,int,int,double> getLandmark()
  136. {
  137. if(m_area_hover)
  138. return m_area_hover->getLandmark();
  139. else
  140. return std::make_tuple(0,0,0,0,0,0,0);
  141. }
  142. //检测是否超时
  143. void on_timer(int64_t card_id)
  144. {
  145. }
  146. void do_hover_biz(int64_t card_id,double speed,int16_t type)
  147. {
  148. m_area_hover->m_area->on_hover(card_id,m_area_hover,speed,type);
  149. }
  150. void do_enter_biz(int64_t card_id,double speed,int16_t type)
  151. {
  152. m_area_hover->m_area->on_enter(card_id,m_area_hover,speed,type);
  153. }
  154. void do_leave_biz(int64_t card_id,double speed,int16_t type)
  155. {
  156. m_area_hover->m_area->on_leave(card_id,m_area_hover,speed,type);
  157. }
  158. };
  159. #endif