gtselectstandardgt.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Created by lloyd on 2020/11/16.
  3. //
  4. #include "gtselectstandardgt.h"
  5. #include "DataMapping/gtdgnsdao.h"
  6. #include "DataMapping/dgns_gtstandard.h"
  7. #include "gtcvcore.h"
  8. #include "gtrunconf.h"
  9. #include "time.h"
  10. bool gtselectstandardgt::cal_std_sgt(dgns_gtstandard gt_pre_standard) {
  11. if(gt_pre_standard.sgtcharacters==NULL) return false;
  12. /*std::cout<<"当前功图特征("<<gt_pre_standard.sgtprodate<<"):"<<std::endl;
  13. for (int i = 0; i < cardgray_characters_num; ++i) {
  14. if(i>0) std::cout<<";";
  15. std::cout<<std::setw(10)<<gt_pre_standard.sgtcharacters[i];
  16. }
  17. std::cout<<std::endl;*/
  18. std::vector<dgns_gtstandard> gts = gtdgnsdao::get_dgns_gtstandard_list();
  19. bool cal_sus = false;
  20. gt_pre_standard.appearcounter = 1;
  21. gt_pre_standard.maxsemblance = 100;
  22. gt_pre_standard.minsemblance = 100;
  23. time_t t = time(NULL); //获取目前秒时间
  24. tm *local = localtime(&t); //转为本地时间
  25. //当前时间
  26. char tm_s[128];
  27. strftime(tm_s, 64, "%Y-%m-%d %H:%M:%S", local);
  28. gt_pre_standard.latestupdatedtime = tm_s;
  29. if (gts.empty()) {
  30. return gtdgnsdao::addDgns_gtstandardContent(gt_pre_standard);
  31. }
  32. gtcvcore::calgray ocalgray;
  33. int i = 0;
  34. for (; i < gts.size(); ++i) {
  35. //TODO:未考虑生产参数变化的情况 未考虑生产参数变化的情况, 后期添加
  36. //if(abs(std_gt.l-pre_gt.l)<xxx&& abs(std_gt.s-pre_gt.s)<xxx) ....
  37. /*std::cout<<"标准功图特征("<<gts[i].sgtprodate<<"):"<<std::endl;
  38. for (int j = 0; j < cardgray_characters_num; ++j) {
  39. if(j>0) std::cout<<";";
  40. std::cout<<std::setw(10)<<gts[i].sgtcharacters[j];
  41. }
  42. std::cout<<std::endl;*/
  43. double gray_si = ocalgray.compareCharacters(gts[i].sgtcharacters, gt_pre_standard.sgtcharacters);
  44. //std::cout<<"相似度 :"<<gray_si*100<<"%"<<std::endl;
  45. if (gray_si >= standard_gt_minest_semblance) {
  46. if (gray_si*100 < gts[i].minsemblance) gts[i].minsemblance = gray_si*100;
  47. if (gray_si*100 > gts[i].maxsemblance) gts[i].maxsemblance = gray_si*100;
  48. gts[i].appearcounter += gt_pre_standard.appearcounter;
  49. gts[i].latestupdatedtime = gt_pre_standard.latestupdatedtime;
  50. cal_sus = gtdgnsdao::alterDgns_gtstandardContent(gts[i]);
  51. break;
  52. }
  53. }
  54. if (i >= gts.size()) {
  55. if (gts.size() + 1 > standard_gt_groups_max_num) {
  56. tm d_tm_;
  57. strptime(gts[0].createtime.c_str(), "%Y-%m-%d %H:%M:%S", &d_tm_);
  58. time_t d_t_ = mktime(&d_tm_);
  59. int d_i = 0;
  60. for (int j = 1; j < gts.size(); ++j) {
  61. tm tm_;
  62. strptime(gts[j].createtime.c_str(), "%Y-%m-%d %H:%M:%S", &tm_);
  63. time_t t_ = mktime(&tm_);
  64. if (t_ < d_t_) {
  65. d_t_ = t_;
  66. d_i = j;
  67. }
  68. }
  69. if (!gtdgnsdao::deleteDgns_gtstandardContent(gts[d_i].id)) {
  70. std::cout << "Warning: delete dgns_gtstandard row fault:id=" << gts[d_i].id << std::endl;
  71. }
  72. }
  73. cal_sus = gtdgnsdao::addDgns_gtstandardContent(gt_pre_standard);
  74. }
  75. return cal_sus;
  76. }
  77. bool gtselectstandardgt::select_bzt_from_db(dgns_gtstandard &gt_data_std) {
  78. std::string conditionsql = " where date_part('day',latestupdatedtime-createtime)>"+std::to_string(standard_gt_effect_days)+" and appearcounter= (select max(appearcounter) from dgns_gtstandard where date_part('day',latestupdatedtime-createtime)>"+std::to_string(standard_gt_effect_days)+" )";
  79. std::vector<dgns_gtstandard> ls = gtdgnsdao::get_dgns_gtstandard_list(conditionsql);
  80. if (ls.empty() || ls.size() == 0) return false;
  81. gt_data_std=ls[0];
  82. return true;
  83. }