module_geofault.h 2.1 KB

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