123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- //
- // Created by lloyd on 2020/9/28.
- //
- #include <iostream>
- #include "gtsecondanalysize.h"
- #include "gtbaseparamanalysize.h"
- #include "DataMapping/dgns_gtcvrparam.h"
- #include "gtrunconf.h"
- #include "gtcommonkits.h"
- #include "DataMapping/gtdgnsdao.h"
- #include "DataMapping/dgns_gtbaseparam.h"
- std::string gtsecondanalysize::pro_worksystemchange(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
- dgns_gtcvrparam::paramworksyschange param) {
- if (std::abs(oGTParam.n - nGTParam.n) > param.param1 || std::abs(oGTParam.s - nGTParam.s) > param.param2)
- return "生产参数变化";//"unusual"
- else return "";//"usual";
- }
- std::string
- gtsecondanalysize::pro_topbottomtouch(std::vector<std::vector<double>> gtFormate, double MinF, double MaxF, double MaxS,
- int sgtpointnum) {
- int sum_xp_A = 0;
- int sum_xp_B = 0;
- int sum_sg_A = 0;
- int sum_sg_B = 0;
- std::string result = "";
- std::vector<std::vector<double>> d = gtFormate;
- double **temp = new double *[sgtpointnum];
- for (int i = 0; i < sgtpointnum; i++) {
- temp[i] = new double[2]{0, 0};
- }
- int count = 0;
- double MinLoad = MinF;
- double MaxLoad = MaxF;
- double MaxStroke = MaxS;
- for (int i = 1; i < sgtpointnum; i++) {
- if (d[i][0] > d[i - 1][0]) {
- double wy_A = d[i][0];
- double zh_A = d[i][1];
- for (int j = sgtpointnum - 1; j > 0; j--) {
- if (d[j][0] > d[i][0]) {
- if (j == sgtpointnum - 1) {
- if (zh_A >= d[j][1]) {
- break;
- } else {
- temp[count][0] = d[i][0];
- temp[count][1] = d[i][1];
- count++;
- break;
- }
- } else {
- double wy_B1 = d[j][0];
- double zh_B1 = d[j][1];
- double wy_B2 = d[j + 1][0];
- double zh_B2 = d[j + 1][1];
- if (zh_B1 < zh_A && zh_B2 < zh_A) {
- break;
- } else {
- temp[count][0] = d[i][0];
- temp[count][1] = d[i][1];
- count++;
- break;
- }
- }
- }
- }
- }
- }
- for (int i = 0; i < count; i++) {
- if (temp[i][1] > 0 && temp[i][1] - MinLoad < 5 && temp[i][0] > 0.1 && temp[i][0] < 0.5) {
- if (temp[i][1] - MinLoad > 1) {
- sum_xp_A++;
- }
- if (temp[i][1] - MinLoad < 0.02) {
- sum_xp_B++;
- }
- }
- if (temp[i][1] > 0 && MaxLoad - temp[i][1] < 5 && temp[i][0] < MaxStroke - 0.1 &&
- temp[i][0] > MaxStroke - 0.5) {
- if (MaxLoad - temp[i][1] > 1) {
- sum_sg_A++;
- }
- if (MaxLoad - temp[i][1] < 0.02) {
- sum_xp_B++;
- }
- }
- }
- if (sum_xp_A > 0 && sum_xp_B > 0 && (sum_xp_A + sum_xp_B > sum_sg_A + sum_sg_B))
- result = "下碰";
- else if (sum_sg_A > 0 && sum_sg_B > 0 && (sum_xp_A + sum_xp_B < sum_sg_A + sum_sg_B))
- result = "上挂";
- else
- result = "";
- return result;
- }
- std::string gtsecondanalysize::pro_rodbreaktype_gather(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
- std::string ngtcvresult, double cal_simiwithbzt,
- dgns_gtcvrparam::paramrodbreaktype param) {
- //连喷带抽:1跟标准功图相似度>90%;2.载荷差变化小于20%;3.功图面积变化小于10%
- if (cal_simiwithbzt > param.SimilarOfBZT && std::abs(oGTParam.l - nGTParam.l) <= oGTParam.l * param.DLoadWave &&
- std::abs(oGTParam.area - nGTParam.area) <= oGTParam.area * param.GTAreaWave) {
- //动液面小于100 连喷带抽 else 泵工作正常
- return "泵工作正常或连喷带抽";
- }
- if (nGTParam.l > oGTParam.l || nGTParam.area > oGTParam.area) {
- if (nGTParam.l - oGTParam.l > param.DLoadWave * oGTParam.l)
- return "结蜡影响";
- else
- return "泵工作正常";
- }
- /* not use
- if ((oGTParam.L >= nGTParam.L && oGTParam.L - nGTParam.L <= oGTParam.L * param.DLoadWave &&
- oGTParam.gt_area >= nGTParam.gt_area &&
- oGTParam.gt_area - nGTParam.gt_area <= oGTParam.gt_area * param.GTAreaWave))
- return "泵工作正常";*/
- //载荷差缩小20%
- if (oGTParam.l - nGTParam.l < oGTParam.l * param.DLoadDown3)
- return "泵工作正常";
- {
- //最大载荷最小载荷在中线下方
- if (nGTParam.l_max < oGTParam.l_mid && nGTParam.l_min < oGTParam.l_mid) {
- return pro_rodbreaktype_part3(oGTParam, nGTParam, param);
- } else {
- if (!ngtcvresult.empty() &&
- (ngtcvresult.find("供液不足") != std::string::npos || ngtcvresult.find("气体影响") != std::string::npos)) {
- double ozh = oGTParam.l_fistdownturnpoint;
- double nzh = nGTParam.l_fistdownturnpoint;
- if (ozh != baseparam_l_fistdownturnpoint_default && nzh != baseparam_l_fistdownturnpoint_default &&
- nGTParam.l_max > nzh && oGTParam.l_max > ozh) {
- if (std::abs(ozh - nzh) <= 1.15)
- return "供液不足(不出液)";//"正常"
- if (std::abs((nGTParam.l_max - nzh) - (oGTParam.l_max - ozh)) <= 1.15 &&
- nGTParam.l_max > (oGTParam.l_max - ozh) * 0.5 + ozh)
- return "供液不足(不出液)";
- }
- }
- //若最大载荷最小载荷在(标准功图)中线上方
- if (nGTParam.l_max >
- oGTParam.l_mid && nGTParam.l_min > oGTParam.l_mid) {
- return pro_rodbreaktype_part1(oGTParam, nGTParam, param);
- }
- //若最大载荷最小载荷在(标准功图)中线两侧
- else if (nGTParam.l_max > oGTParam.l_mid && nGTParam.l_min < oGTParam.l_mid) {
- if (nGTParam.l_min > oGTParam.l_min && nGTParam.l_min < oGTParam.l_min + (oGTParam.l * 0.15) &&
- nGTParam.l >= oGTParam.l * 0.4) {
- return "油管漏失";
- } else if (nGTParam.l_max - oGTParam.l_mid < nGTParam.l * 0.25) {
- return pro_rodbreaktype_part3(oGTParam, nGTParam, param);
- } else if (oGTParam.l_mid - nGTParam.l_min < nGTParam.l * 0.25) {
- return pro_rodbreaktype_part1(oGTParam, nGTParam, param);
- } else {
- return "双凡尔漏失或双凡尔失灵";
- }
- }
- }
- }
- }
- std::string gtsecondanalysize::pro_rodbreaktype_part3(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
- dgns_gtcvrparam::paramrodbreaktype param) {
- if (nGTParam.l_max > oGTParam.l_mid * param.case3_param1 &&
- nGTParam.l_min < oGTParam.l_min + (oGTParam.l * param.case3_param2) &&
- nGTParam.l_min > oGTParam.l_min && nGTParam.l >= oGTParam.l * param.case3_param3) {
- return "油管漏失";
- } else if (nGTParam.l_min < oGTParam.l_min * param.case3_param4 &&
- nGTParam.l_max < oGTParam.l_mid - oGTParam.l * param.case3_param5) {
- return "油杆断脱";
- } else {
- return "油杆断脱或游动凡尔失灵";
- }
- }
- std::string gtsecondanalysize::pro_rodbreaktype_part1(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
- dgns_gtcvrparam::paramrodbreaktype param) {
- if (nGTParam.l_min < oGTParam.l_max * param.case1_param1) {
- //nHsink >= 500
- //return "固定凡尔失灵";
- return "气锁或固定凡尔失灵";
- } else {
- return "功图有误或参数变化";
- }
- }
- std::string gtsecondanalysize::pro_outsandorvibration(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
- dgns_gtcvrparam::paramoutsandorvibration param)//新增参数类型
- {
- gtcommonkits kits;
- int start = 0;
- int end = 100;
- int weight = 2;
- std::vector<std::vector<double>> WaveCrest = kits.FindPeakValue(nGTParam.sgt, start, end, weight, 1);
- std::vector<std::vector<double>> WaveTrough = kits.FindPeakValue(nGTParam.sgt, start, end, weight, -1);
- if (WaveCrest.size() == 0 || WaveTrough.size() == 0 || WaveCrest.size() <= param.WaveCrest_MinNum ||
- WaveTrough.size() <= param.WaveTrough_MinNum)
- return "泵工作正常";
- std::vector<double> VibrationDistance;
- double VibrationDistance_Average = 0.0;
- for (int i = 0; i < WaveCrest.size() && i < WaveTrough.size(); i++) {
- VibrationDistance.push_back(std::abs(WaveCrest[i][1] - WaveTrough[i][1]));
- VibrationDistance_Average += VibrationDistance[i];
- }
- if (VibrationDistance.size() == 0) return "泵工作正常";
- VibrationDistance_Average = VibrationDistance_Average / VibrationDistance.size();
- if (VibrationDistance_Average <= (nGTParam.l) * param.AmplitudeMin) return "泵工作正常";
- double cvd = kits.cStandardDeviation(VibrationDistance);
- if (cvd <= param.SD_Vibration) return "机械振动";
- else if (cvd >= param.SD_Sand) return "油井出砂";
- else return "泵工作正常";//界值为测试阶段,且范围外的值暂时不能确定是什么
- }
- std::string gtsecondanalysize::secondanalysize_main(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
- int firstanalysizeresult_code, std::string firstanalysizeresult_str,
- double cal_simiwithbzt) {
- if (oGTParam.wellname.empty() || nGTParam.wellname.empty()) {
- std::cout << "Warning:不满诊断数据条件,二次诊断已跳过,使用一次诊断结果" << std::endl;
- return firstanalysizeresult_str;
- }
- std::vector<dgns_gtcvrparam> params = gtdgnsdao::getDgns_gtcvrparamContent(sec_func_paramid, sec_func_paramname);
- dgns_gtcvrparam paramintegrate;
- if (params.size() == 0) {
- paramintegrate.paramitemname = sec_func_paramname;
- paramintegrate.paramid = sec_func_paramid;
- paramintegrate.paramcontent = paramintegrate.allParamToJsonTranslate();
- gtdgnsdao::addDgns_gtcvrparamContent(paramintegrate);
- } else {
- paramintegrate = params[0];
- }
- std::string sec_result;
- dgns_gtcvrparam::paramworksyschange *p = (dgns_gtcvrparam::paramworksyschange *) paramintegrate.getParam(
- dgns_gtcvrparam::paramworksyschange_);
- sec_result = pro_worksystemchange(oGTParam, nGTParam, *p);
- if (!sec_result.empty()) return sec_result;
- switch (firstanalysizeresult_code) {
- case 1:
- case 6:
- case 8:
- case 17:
- case 18: {
- dgns_gtcvrparam::paramrodbreaktype *pa = (dgns_gtcvrparam::paramrodbreaktype *) paramintegrate.getParam(
- dgns_gtcvrparam::paramrodbreaktype_);
- sec_result = pro_rodbreaktype_gather(oGTParam, nGTParam, firstanalysizeresult_str, cal_simiwithbzt, *pa);
- break;
- }
- case 2: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 3: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 4: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 5: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 7: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 9: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 10: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 11:
- case 13:
- case 14:
- case 15: {
- sec_result = pro_topbottomtouch(nGTParam.sgt, nGTParam.l_min, nGTParam.l_max, nGTParam.s_max,
- nGTParam.sgtpointnum);
- if (sec_result.empty()) sec_result = "严重供液不足";
- else return sec_result = firstanalysizeresult_str;
- break;
- }
- case 12: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 16: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 19: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 20: {
- sec_result = firstanalysizeresult_str;
- break;
- }
- case 21: {
- dgns_gtcvrparam::paramoutsandorvibration *pa = (dgns_gtcvrparam::paramoutsandorvibration *) paramintegrate.getParam(
- dgns_gtcvrparam::paramoutsandorvibration_);
- sec_result = pro_outsandorvibration(oGTParam, nGTParam, *pa);
- break;
- }
- default: {
- std::cout << "undefined gtmlypte !! please improve the case:* ?" << std::endl;
- break;
- }
- }
- if (sec_result.empty()) {
- std::cout << "secondly diagnose is fault!" << std::endl;
- }
- return sec_result;
- }
|