123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- //
- // Created by lloyd on 2020/11/16.
- //
- #include "gtselectstandardgt.h"
- #include "DataMapping/gtdgnsdao.h"
- #include "DataMapping/dgns_gtstandard.h"
- #include "gtcvcore.h"
- #include "gtrunconf.h"
- #include "time.h"
- bool gtselectstandardgt::cal_std_sgt(dgns_gtstandard gt_pre_standard) {
- if(gt_pre_standard.sgtcharacters==NULL) return false;
- /*std::cout<<"当前功图特征("<<gt_pre_standard.sgtprodate<<"):"<<std::endl;
- for (int i = 0; i < cardgray_characters_num; ++i) {
- if(i>0) std::cout<<";";
- std::cout<<std::setw(10)<<gt_pre_standard.sgtcharacters[i];
- }
- std::cout<<std::endl;*/
- std::vector<dgns_gtstandard> gts = gtdgnsdao::get_dgns_gtstandard_list();
- bool cal_sus = false;
- gt_pre_standard.appearcounter = 1;
- gt_pre_standard.maxsemblance = 100;
- gt_pre_standard.minsemblance = 100;
- time_t t = time(NULL); //获取目前秒时间
- tm *local = localtime(&t); //转为本地时间
- //当前时间
- char tm_s[128];
- strftime(tm_s, 64, "%Y-%m-%d %H:%M:%S", local);
- gt_pre_standard.latestupdatedtime = tm_s;
- if (gts.empty()) {
- return gtdgnsdao::addDgns_gtstandardContent(gt_pre_standard);
- }
- gtcvcore::calgray ocalgray;
- int i = 0;
- for (; i < gts.size(); ++i) {
- //TODO:未考虑生产参数变化的情况 未考虑生产参数变化的情况, 后期添加
- //if(abs(std_gt.l-pre_gt.l)<xxx&& abs(std_gt.s-pre_gt.s)<xxx) ....
- /*std::cout<<"标准功图特征("<<gts[i].sgtprodate<<"):"<<std::endl;
- for (int j = 0; j < cardgray_characters_num; ++j) {
- if(j>0) std::cout<<";";
- std::cout<<std::setw(10)<<gts[i].sgtcharacters[j];
- }
- std::cout<<std::endl;*/
- double gray_si = ocalgray.compareCharacters(gts[i].sgtcharacters, gt_pre_standard.sgtcharacters);
- //std::cout<<"相似度 :"<<gray_si*100<<"%"<<std::endl;
- if (gray_si >= standard_gt_minest_semblance) {
- if (gray_si*100 < gts[i].minsemblance) gts[i].minsemblance = gray_si*100;
- if (gray_si*100 > gts[i].maxsemblance) gts[i].maxsemblance = gray_si*100;
- gts[i].appearcounter += gt_pre_standard.appearcounter;
- gts[i].latestupdatedtime = gt_pre_standard.latestupdatedtime;
- cal_sus = gtdgnsdao::alterDgns_gtstandardContent(gts[i]);
- break;
- }
- }
- if (i >= gts.size()) {
- if (gts.size() + 1 > standard_gt_groups_max_num) {
- tm d_tm_;
- strptime(gts[0].createtime.c_str(), "%Y-%m-%d %H:%M:%S", &d_tm_);
- time_t d_t_ = mktime(&d_tm_);
- int d_i = 0;
- for (int j = 1; j < gts.size(); ++j) {
- tm tm_;
- strptime(gts[j].createtime.c_str(), "%Y-%m-%d %H:%M:%S", &tm_);
- time_t t_ = mktime(&tm_);
- if (t_ < d_t_) {
- d_t_ = t_;
- d_i = j;
- }
- }
- if (!gtdgnsdao::deleteDgns_gtstandardContent(gts[d_i].id)) {
- std::cout << "Warning: delete dgns_gtstandard row fault:id=" << gts[d_i].id << std::endl;
- }
- }
- cal_sus = gtdgnsdao::addDgns_gtstandardContent(gt_pre_standard);
- }
- return cal_sus;
- }
- bool gtselectstandardgt::select_bzt_from_db(dgns_gtstandard >_data_std) {
- 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)+" )";
- std::vector<dgns_gtstandard> ls = gtdgnsdao::get_dgns_gtstandard_list(conditionsql);
- if (ls.empty() || ls.size() == 0) return false;
- gt_data_std=ls[0];
- return true;
- }
|