123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- #include <iostream>
- #include "opencv2/opencv.hpp"
- #include "gtdatasource.h"
- #include "gtbaseparamanalysize.h"
- #include "gtstandardlization.h"
- #include "gtcvcore.h"
- #include "DataMapping/gtdgnsdao.h"
- #include "DataMapping/dgns_gtbaseparam.h"
- #include "DataMapping/dgns_gtmloutcode.h"
- #include "Test/modbustest.hpp"
- #include "Test/jsontest.hpp"
- #include "pthread.h"
- #include "gtsecondanalysize.h"
- #include "gtselectstandardgt.h"
- #include "gtrunconf.h"
- #include "DataMapping/dgns_gtcvrresult.h"
- #include "gtaoidcore.h"
- #include "DataMapping/aoid_config_data.h"
- #include "DataMapping/aoid_gk_model.h"
- #include "DataMapping/aoid_singlewell_config.h"
- #include "DataMapping/gtaoiddao.h"
- #include "DataMapping/aoid_singlegt_yield.h"
- void *cal_liqproc(const std::string &recitime) {
- /*dgns_gtbaseparam *_baseparam = (dgns_gtbaseparam *) args[0];
- dgns_gtcvrresult *_cvrresult = (dgns_gtcvrresult *) args[1];*/
- std::cout<<"----------------------------cal liq---------------------"<<std::endl;
- dgns_gtbaseparam _baseparam;
- if(!gtdgnsdao::get_dgns_gtbaseparam_single(_baseparam,"",recitime)) {
- std::cout << "Waring:未找到对应的功图" << std::endl;
- return 0;
- }
- std::vector<dgns_gtcvrresult> _cvrresultlist=gtdgnsdao::getDgns_gtcvrresultContent("",_baseparam.recivetime);
- if (_cvrresultlist.empty() || _cvrresultlist.size() == 0) {
- std::cout << "Waring:无诊断结果已跳过" << std::endl;
- return 0;
- }
- dgns_gtcvrresult _cvrresult=_cvrresultlist[0];
- gtaoidcore::gtrevision rev;
- rev.sgt_encode(&_baseparam);
- gtaoidcore::calbgt cbgt;
- cbgt.cal_bgt(rev, _cvrresult.result2);
- aoid_config_data cdata;
- if(!gtaoiddao::get_aoid_config_data_and_open_hotupdate(cdata)){
- std::cout<<"Warning:没有配置井筒基础数据";
- return 0;
- }
- aoid_gk_model gkModel;
- gtaoiddao::get_aoid_gk_model_fromDB(_cvrresult.result2, gkModel);
- aoid_singlewell_config singlewellConfig;
- gtaoiddao::get_aoid_singlewell_config_fromDB(gtly_cal_effectstroke_fun, singlewellConfig);
- gtaoidcore _gtaoidcore;
- std::vector<double> cal_ly_r = _gtaoidcore.cal_ylandon(_baseparam.sgt,
- cbgt.bgt, _baseparam.s, _baseparam.n,
- _cvrresult.result2, cdata.bj,
- cdata.bs, cdata.hsl, cdata.smd, cdata.ymd, cdata.qyb,
- cdata.dym, gkModel.gkxs,
- singlewellConfig.gradient_1, singlewellConfig.gradient_10,
- singlewellConfig.gradient_2,
- singlewellConfig.gradient_3,
- singlewellConfig.gradient_4, singlewellConfig.gradient_5,
- singlewellConfig.gradient_6,
- singlewellConfig.gradient_7,
- singlewellConfig.gradient_8, singlewellConfig.gradient_9,
- singlewellConfig.dividenum_1,
- singlewellConfig.dividenum_2,
- singlewellConfig.dividenum_3, singlewellConfig.dividenum_4,
- singlewellConfig.dividenum_5,
- singlewellConfig.dividenum_6,
- singlewellConfig.dividenum_7, singlewellConfig.dividenum_8,
- singlewellConfig.dividenum_9,
- singlewellConfig.dividenum_10);
- if (cal_ly_r.empty() || cal_ly_r.size() == 0) {
- std::cout << "Error:量液结果计算出错!" << std::endl;
- return 0;
- }
- {
- aoid_singlegt_yield singlegtYield;
- singlegtYield.qyb = cdata.qyb;
- singlegtYield.hsl = cdata.hsl;
- singlegtYield.bj = cdata.bj;
- singlegtYield.sgt = _baseparam.sgt;
- singlegtYield.bgt=cbgt.bgt;
- singlegtYield.bdxs = gkModel.gkxs;
- singlegtYield.bs = cdata.bs;
- singlegtYield.cmd = cdata.dym - cdata.bs;
- singlegtYield.eczdjg = _cvrresult.result2;
- singlegtYield.frequence = _baseparam.n;
- singlegtYield.stroke = _baseparam.s;
- singlegtYield.yy = cdata.yy;
- singlegtYield.ty = cdata.ty;
- singlegtYield.hy = cdata.hy;
- singlegtYield.prod_date = _baseparam.recivetime;
- singlegtYield.refrencesgt = _baseparam.sgt;
- singlegtYield.zdjg = _cvrresult.result2;
- singlegtYield.scsj = 24;//TODO::修改计算部分的时间,根据一天多少功图平均一下,直接写24也没事
- singlegtYield.pumpdepth = cdata.bs;
- singlegtYield.yzzj = cdata.bj;
- //日产液量 日产油量 日产水量 日产气量 泵效 理论排量 实际冲程 有效冲程 左冲程 右冲程 冲程损失 漏失损失 gyss 有效冲程比例
- singlegtYield.liq_prod_daily = cal_ly_r[0];
- singlegtYield.oil_prod_daily = cal_ly_r[1];
- singlegtYield.water_prod_daily = cal_ly_r[2];
- singlegtYield.gas_prod_daily = cal_ly_r[3];
- singlegtYield.bx = cal_ly_r[4];
- singlegtYield.llpl = cal_ly_r[5];
- singlegtYield.sjcc = cal_ly_r[6];
- singlegtYield.yxcc = cal_ly_r[8];
- singlegtYield.zcc = cal_ly_r[9];
- singlegtYield.ycc = cal_ly_r[10];
- singlegtYield.ccss = cal_ly_r[11];
- singlegtYield.lsss = cal_ly_r[12];
- singlegtYield.gyss = cal_ly_r[13];
- singlegtYield.stroke_ratio = cal_ly_r[14];
- if (!gtaoiddao::add_aoid_singlegt_yield(singlegtYield)) {
- std::cout << "Error:单功图量液计算结果保存失败" << std::endl;
- }
- else std::cout << "液量计算完成" << std::endl;
- }
- {
- gtdatasource kit_gtsource;
- if (kit_gtsource.send_gtaoid_out_singlegtproc_to_modbuscode_rf(cal_ly_r[0], cdata.totalgtnum)) {
- std::cout << "量液数据写入modbus成功" << std::endl;
- }else std::cout << "Error:量液数据写入modbus失败" << std::endl;
- }
- }
- void *cal_main(void *args) {
- gtcvcore::calgray kit_cgray;
- gtdatasource kit_gtsource;
- using kit_dao = typeof(gtdgnsdao);// kit_dao;
- gtbaseparamanalysize kit_gtparam;
- gtselectstandardgt kit_stdgt;
- gtcvcore kit_gtcvcore;
- kit_gtcvcore.initSVM(gtrunconf_svmmodel_load);
- dgns_gtbaseparam gt_data_cur;
- kit_gtsource.getGTFromModbus(>_data_cur);
- kit_gtparam.analysisParam(>_data_cur);
- if (gt_data_cur.islegal != 1) {
- std::cout << "Error:没有输入正确的功图!!!" << std::endl;
- return 0;
- }
- dgns_gtbaseparam gt_data_his;
- dgns_gtstandard gt_data_his_std;
- kit_stdgt.select_bzt_from_db(gt_data_his_std);
- kit_gtsource.get_std_gt(gt_data_his, gt_data_his_std.sgtprodate);
- //TODO:这里数据库的实时功图数据定时将3个月之前的功图删除,保证数据库占用空间稳定
- if (!kit_dao::add_dgns_gtbaseparam_single(gt_data_cur)) {
- //数据库有唯一主键(功图产生时间)控制,插入失败人为是已诊断过功图,跳过本次诊断
- return 0;
- }
- dgns_gtstandard gt_data_cur_std;
- if (!kit_cgray.calGrayCharacters(gt_data_cur_std, gt_data_cur)) {
- std::cout << "gt cal gray error!!!" << std::endl;
- return 0;
- }
- gtstandardlization _gtstandardization;
- _gtstandardization.standardization(>_data_cur);
- _gtstandardization.paddingMap();
- std::cout << "-----------------The first diagnose---------------" << std::endl;
- std::string predictresult_code_str = "1";
- predictresult_code_str = kit_gtcvcore.HOGSVMPredict(_gtstandardization.mapGT_Standard1,
- _gtstandardization.mapGT_Standard2, gtrunconf_cvcore_regnfunc,
- gtrunconf_svmmodel_load, "test");
- std::map<int, dgns_gtmloutcode> dgns_gtmloutcode_map = kit_dao::get_dgns_gtmloutcode_map();
- int predictresult_code = std::atoi(predictresult_code_str.c_str());
- std::map<int, dgns_gtmloutcode>::iterator iter = dgns_gtmloutcode_map.find(predictresult_code);
- std::string predictresult_std = "";
- if (iter != dgns_gtmloutcode_map.end()) predictresult_std = iter->second.gkdec;
- std::cout << std::endl << "图形特征识别:" << predictresult_std << std::endl;
- std::cout << "----------------------------------------------" << std::endl;
- std::cout << "-----------------The compare GTSimillar---------------" << std::endl;
- /* cv::Scalar siml = _gtcvcore.C_GTSimillar_HOG(_gtstandardization.mapGT_Standard1,
- _gtstandardization.mapGT_Standard2,
- _gtstandardization2.mapGT_Standard1,
- _gtstandardization2.mapGT_Standard2);*/
- //std::cout << "the two gt img similar (MSSIM):" << siml << std::endl;
- double siml2 = kit_cgray.compareCharacters(gt_data_cur_std.sgtcharacters, gt_data_his_std.sgtcharacters);
- std::cout << "功图相似度变化解释 (Gray):" << siml2 << std::endl;
- std::cout << "----------------------------------------------" << std::endl;
- std::cout << "-----------------The sec func diagnose---------------" << std::endl;
- gtsecondanalysize secfunc;
- std::string secresult = secfunc.secondanalysize_main(gt_data_his, gt_data_cur, predictresult_code,
- predictresult_std,
- siml2);
- std::cout << std::endl << "最终工况解释结果:" << secresult << std::endl;
- std::cout << "----------------------------------------------" << std::endl;
- {
- dgns_gtcvrresult gtcvrresult;
- gtcvrresult.sgt = gt_data_cur.sgt;
- gtcvrresult.result2 = secresult;
- gtcvrresult.result1 = predictresult_std;
- gtcvrresult.isexpected = 1;
- gtcvrresult.isproblem = "0";//TODO:是否是问题配置到gk code表里
- gtcvrresult.processparam= "{\"sgt_recivetime\":\""+gt_data_cur.recivetime+"\"}";
- if (kit_dao::addDgns_gtcvrresultContent(gtcvrresult)) {
- std::cout << "诊断结果保存成功" << std::endl;
- } else
- std::cout << "诊断结果保存失败" << std::endl;
- }
- {
- std::cout << "----------------write modbus rf_server----------------" << std::endl;
- //写回modbus
- if (kit_gtsource.send_gtcvr_out_content_to_modbuscode_rf(secresult)) {
- std::cout << "写入瑞飞RTU成功!" << std::endl;
- } else
- std::cout << "写入瑞飞RTU失败!" << std::endl;
- std::cout << "----------------------------------------------" << std::endl;
- }
- {
- std::cout << "----------------cal bzt----------------" << std::endl;
- //标准功图计算
- gt_data_cur_std.graphicfeatureinterpretation = predictresult_std;
- if (kit_stdgt.cal_std_sgt(gt_data_cur_std)) {
- std::cout << "标准功图计算成功!" << std::endl;
- } else
- std::cout << "标准功图计算失败!" << std::endl;
- std::cout << "----------------------------------------------" << std::endl;
- }
- cal_liqproc(gt_data_cur.recivetime);
- }
- int main() {
- /* dgns_gtcvrparam pa;
- std::string s= pa.allParamToJsonTranslate();
- std::cout<<s<<std::endl;
- return 0;*/
- /* if (0) {
- jsontest jt;
- jt.maintest(0, NULL);
- gtdgnsdao dd;
- dgns_gtbaseparam p;
- p.id = "3434f539-d1b5-4265-b32e-b31bffbfb05a";
- p.s_effect = 0.65;
- p.l_max = 9;
- if (dd.add_dgns_gtbaseparam_single(p)) {
- std::cout << "insert successfully!" << std::endl;
- }
- modbustest mb;
- mb.maintest();
- }*/
- /*gtdgnsdao d;
- std::vector<dgns_gtcvrparam> ds= d.getTableContent(0,"sd");
- dgns_gtcvrparam d3;
- d.alterTableContent( &d3);
- return 2;*/
- /*int cycle = 3;
- while (cycle > 0) {
- pthread_t pid;
- if (pthread_create((&pid), NULL, cal_main,NULL) < 0) {
- printf("creat thread faild\r\n");
- }*/
- while (1) {
- //cv::waitKey(1000);
- cal_main(NULL);
- //cal_liqproc();
- //TODO:报错后这里会导致无限重连,延迟一下?
- //目前多线程延迟或许不支持
- //主进程延迟,会导致上下文数据丢失,导致奇葩指针错误
- //_sleep(200);
- }
- // --cycle;
- // }
- return 0;
- }
|