area_business_geofault.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef AREA_BUSINESS_GEOFAULT
  2. #define AREA_BUSINESS_GEOFAULT
  3. /**
  4. * @brief 简要说明
  5. * @author 戴月腾
  6. * @date 2019-01-15
  7. */
  8. #include<area_business.h>
  9. #include <unordered_map>
  10. #include<vector>
  11. #include<area.h>
  12. #include<point.h>
  13. #include"config_file.h"
  14. /**
  15. * @brief 当采煤机和掘进机有数据点过来的时候,判断当前点与地址断层坐标点的距离d。如d<设置的阈值,则告警,d>阈值则取消。
  16. */
  17. class area_business_geofault:public area_business
  18. {
  19. public:
  20. int area_business_type()
  21. {
  22. return 10;
  23. }
  24. void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);
  25. void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
  26. void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
  27. static void init(config_file& config)
  28. {
  29. _geofault_count_limit = std::stoi(config.get("service.geofault_count_limit","10"));
  30. }
  31. static void init_geofault_from_db();
  32. private:
  33. static bool _is_near(std::shared_ptr<area>& area_ptr, double x, double y, double& out_dist);
  34. static std::vector<std::string> split(const std::string& str, char tag)
  35. {
  36. std::vector<std::string> arr;
  37. std::string subStr;
  38. for(size_t i = 0; i < str.length(); i++)
  39. {
  40. if(tag == str[i])
  41. {
  42. if(!subStr.empty())
  43. {
  44. arr.push_back(subStr);
  45. subStr.clear();
  46. }
  47. }
  48. else
  49. {
  50. subStr.push_back(str[i]);
  51. }
  52. }
  53. if(!subStr.empty())
  54. {
  55. arr.push_back(subStr);
  56. }
  57. return arr;
  58. }
  59. static std::string points2str(std::vector<point>& points)
  60. {
  61. std::string str;
  62. for(auto&p : points)
  63. {
  64. char ch[64] = {0};
  65. sprintf(ch, "x=%f,y=%f;", p.x, p.y);
  66. str.append(ch);
  67. }
  68. return str;
  69. }
  70. private:
  71. //area_id: points
  72. static std::unordered_map<int, std::vector<point>> _area_geofault_map;
  73. static int _geofault_count_limit;
  74. };
  75. #endif // AREA_BUSINESS_GEOFAULT