gtsecondanalysize.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. //
  2. // Created by lloyd on 2020/9/28.
  3. //
  4. #include <iostream>
  5. #include "gtsecondanalysize.h"
  6. #include "gtbaseparamanalysize.h"
  7. #include "DataMapping/dgns_gtcvrparam.h"
  8. #include "gtrunconf.h"
  9. #include "gtcommonkits.h"
  10. #include "DataMapping/gtdgnsdao.h"
  11. #include "DataMapping/dgns_gtbaseparam.h"
  12. std::string gtsecondanalysize::pro_worksystemchange(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
  13. dgns_gtcvrparam::paramworksyschange param) {
  14. if (std::abs(oGTParam.n - nGTParam.n) > param.param1 || std::abs(oGTParam.s - nGTParam.s) > param.param2)
  15. return "生产参数变化";//"unusual"
  16. else return "";//"usual";
  17. }
  18. std::string
  19. gtsecondanalysize::pro_topbottomtouch(std::vector<std::vector<double>> gtFormate, double MinF, double MaxF, double MaxS,
  20. int sgtpointnum) {
  21. int sum_xp_A = 0;
  22. int sum_xp_B = 0;
  23. int sum_sg_A = 0;
  24. int sum_sg_B = 0;
  25. std::string result = "";
  26. std::vector<std::vector<double>> d = gtFormate;
  27. double **temp = new double *[sgtpointnum];
  28. for (int i = 0; i < sgtpointnum; i++) {
  29. temp[i] = new double[2]{0, 0};
  30. }
  31. int count = 0;
  32. double MinLoad = MinF;
  33. double MaxLoad = MaxF;
  34. double MaxStroke = MaxS;
  35. for (int i = 1; i < sgtpointnum; i++) {
  36. if (d[i][0] > d[i - 1][0]) {
  37. double wy_A = d[i][0];
  38. double zh_A = d[i][1];
  39. for (int j = sgtpointnum - 1; j > 0; j--) {
  40. if (d[j][0] > d[i][0]) {
  41. if (j == sgtpointnum - 1) {
  42. if (zh_A >= d[j][1]) {
  43. break;
  44. } else {
  45. temp[count][0] = d[i][0];
  46. temp[count][1] = d[i][1];
  47. count++;
  48. break;
  49. }
  50. } else {
  51. double wy_B1 = d[j][0];
  52. double zh_B1 = d[j][1];
  53. double wy_B2 = d[j + 1][0];
  54. double zh_B2 = d[j + 1][1];
  55. if (zh_B1 < zh_A && zh_B2 < zh_A) {
  56. break;
  57. } else {
  58. temp[count][0] = d[i][0];
  59. temp[count][1] = d[i][1];
  60. count++;
  61. break;
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }
  68. for (int i = 0; i < count; i++) {
  69. if (temp[i][1] > 0 && temp[i][1] - MinLoad < 5 && temp[i][0] > 0.1 && temp[i][0] < 0.5) {
  70. if (temp[i][1] - MinLoad > 1) {
  71. sum_xp_A++;
  72. }
  73. if (temp[i][1] - MinLoad < 0.02) {
  74. sum_xp_B++;
  75. }
  76. }
  77. if (temp[i][1] > 0 && MaxLoad - temp[i][1] < 5 && temp[i][0] < MaxStroke - 0.1 &&
  78. temp[i][0] > MaxStroke - 0.5) {
  79. if (MaxLoad - temp[i][1] > 1) {
  80. sum_sg_A++;
  81. }
  82. if (MaxLoad - temp[i][1] < 0.02) {
  83. sum_xp_B++;
  84. }
  85. }
  86. }
  87. if (sum_xp_A > 0 && sum_xp_B > 0 && (sum_xp_A + sum_xp_B > sum_sg_A + sum_sg_B))
  88. result = "下碰";
  89. else if (sum_sg_A > 0 && sum_sg_B > 0 && (sum_xp_A + sum_xp_B < sum_sg_A + sum_sg_B))
  90. result = "上挂";
  91. else
  92. result = "";
  93. return result;
  94. }
  95. std::string gtsecondanalysize::pro_rodbreaktype_gather(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
  96. std::string ngtcvresult, double cal_simiwithbzt,
  97. dgns_gtcvrparam::paramrodbreaktype param) {
  98. //连喷带抽:1跟标准功图相似度>90%;2.载荷差变化小于20%;3.功图面积变化小于10%
  99. if (cal_simiwithbzt > param.SimilarOfBZT && std::abs(oGTParam.l - nGTParam.l) <= oGTParam.l * param.DLoadWave &&
  100. std::abs(oGTParam.area - nGTParam.area) <= oGTParam.area * param.GTAreaWave) {
  101. //动液面小于100 连喷带抽 else 泵工作正常
  102. return "泵工作正常或连喷带抽";
  103. }
  104. if (nGTParam.l > oGTParam.l || nGTParam.area > oGTParam.area) {
  105. if (nGTParam.l - oGTParam.l > param.DLoadWave * oGTParam.l)
  106. return "结蜡影响";
  107. else
  108. return "泵工作正常";
  109. }
  110. /* not use
  111. if ((oGTParam.L >= nGTParam.L && oGTParam.L - nGTParam.L <= oGTParam.L * param.DLoadWave &&
  112. oGTParam.gt_area >= nGTParam.gt_area &&
  113. oGTParam.gt_area - nGTParam.gt_area <= oGTParam.gt_area * param.GTAreaWave))
  114. return "泵工作正常";*/
  115. //载荷差缩小20%
  116. if (oGTParam.l - nGTParam.l < oGTParam.l * param.DLoadDown3)
  117. return "泵工作正常";
  118. {
  119. //最大载荷最小载荷在中线下方
  120. if (nGTParam.l_max < oGTParam.l_mid && nGTParam.l_min < oGTParam.l_mid) {
  121. return pro_rodbreaktype_part3(oGTParam, nGTParam, param);
  122. } else {
  123. if (!ngtcvresult.empty() &&
  124. (ngtcvresult.find("供液不足") != std::string::npos || ngtcvresult.find("气体影响") != std::string::npos)) {
  125. double ozh = oGTParam.l_fistdownturnpoint;
  126. double nzh = nGTParam.l_fistdownturnpoint;
  127. if (ozh != baseparam_l_fistdownturnpoint_default && nzh != baseparam_l_fistdownturnpoint_default &&
  128. nGTParam.l_max > nzh && oGTParam.l_max > ozh) {
  129. if (std::abs(ozh - nzh) <= 1.15)
  130. return "供液不足(不出液)";//"正常"
  131. if (std::abs((nGTParam.l_max - nzh) - (oGTParam.l_max - ozh)) <= 1.15 &&
  132. nGTParam.l_max > (oGTParam.l_max - ozh) * 0.5 + ozh)
  133. return "供液不足(不出液)";
  134. }
  135. }
  136. //若最大载荷最小载荷在(标准功图)中线上方
  137. if (nGTParam.l_max >
  138. oGTParam.l_mid && nGTParam.l_min > oGTParam.l_mid) {
  139. return pro_rodbreaktype_part1(oGTParam, nGTParam, param);
  140. }
  141. //若最大载荷最小载荷在(标准功图)中线两侧
  142. else if (nGTParam.l_max > oGTParam.l_mid && nGTParam.l_min < oGTParam.l_mid) {
  143. if (nGTParam.l_min > oGTParam.l_min && nGTParam.l_min < oGTParam.l_min + (oGTParam.l * 0.15) &&
  144. nGTParam.l >= oGTParam.l * 0.4) {
  145. return "油管漏失";
  146. } else if (nGTParam.l_max - oGTParam.l_mid < nGTParam.l * 0.25) {
  147. return pro_rodbreaktype_part3(oGTParam, nGTParam, param);
  148. } else if (oGTParam.l_mid - nGTParam.l_min < nGTParam.l * 0.25) {
  149. return pro_rodbreaktype_part1(oGTParam, nGTParam, param);
  150. } else {
  151. return "双凡尔漏失或双凡尔失灵";
  152. }
  153. }
  154. }
  155. }
  156. }
  157. std::string gtsecondanalysize::pro_rodbreaktype_part3(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
  158. dgns_gtcvrparam::paramrodbreaktype param) {
  159. if (nGTParam.l_max > oGTParam.l_mid * param.case3_param1 &&
  160. nGTParam.l_min < oGTParam.l_min + (oGTParam.l * param.case3_param2) &&
  161. nGTParam.l_min > oGTParam.l_min && nGTParam.l >= oGTParam.l * param.case3_param3) {
  162. return "油管漏失";
  163. } else if (nGTParam.l_min < oGTParam.l_min * param.case3_param4 &&
  164. nGTParam.l_max < oGTParam.l_mid - oGTParam.l * param.case3_param5) {
  165. return "油杆断脱";
  166. } else {
  167. return "油杆断脱或游动凡尔失灵";
  168. }
  169. }
  170. std::string gtsecondanalysize::pro_rodbreaktype_part1(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
  171. dgns_gtcvrparam::paramrodbreaktype param) {
  172. if (nGTParam.l_min < oGTParam.l_max * param.case1_param1) {
  173. //nHsink >= 500
  174. //return "固定凡尔失灵";
  175. return "气锁或固定凡尔失灵";
  176. } else {
  177. return "功图有误或参数变化";
  178. }
  179. }
  180. std::string gtsecondanalysize::pro_outsandorvibration(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
  181. dgns_gtcvrparam::paramoutsandorvibration param)//新增参数类型
  182. {
  183. gtcommonkits kits;
  184. int start = 0;
  185. int end = 100;
  186. int weight = 2;
  187. std::vector<std::vector<double>> WaveCrest = kits.FindPeakValue(nGTParam.sgt, start, end, weight, 1);
  188. std::vector<std::vector<double>> WaveTrough = kits.FindPeakValue(nGTParam.sgt, start, end, weight, -1);
  189. if (WaveCrest.size() == 0 || WaveTrough.size() == 0 || WaveCrest.size() <= param.WaveCrest_MinNum ||
  190. WaveTrough.size() <= param.WaveTrough_MinNum)
  191. return "泵工作正常";
  192. std::vector<double> VibrationDistance;
  193. double VibrationDistance_Average = 0.0;
  194. for (int i = 0; i < WaveCrest.size() && i < WaveTrough.size(); i++) {
  195. VibrationDistance.push_back(std::abs(WaveCrest[i][1] - WaveTrough[i][1]));
  196. VibrationDistance_Average += VibrationDistance[i];
  197. }
  198. if (VibrationDistance.size() == 0) return "泵工作正常";
  199. VibrationDistance_Average = VibrationDistance_Average / VibrationDistance.size();
  200. if (VibrationDistance_Average <= (nGTParam.l) * param.AmplitudeMin) return "泵工作正常";
  201. double cvd = kits.cStandardDeviation(VibrationDistance);
  202. if (cvd <= param.SD_Vibration) return "机械振动";
  203. else if (cvd >= param.SD_Sand) return "油井出砂";
  204. else return "泵工作正常";//界值为测试阶段,且范围外的值暂时不能确定是什么
  205. }
  206. std::string gtsecondanalysize::secondanalysize_main(dgns_gtbaseparam oGTParam, dgns_gtbaseparam nGTParam,
  207. int firstanalysizeresult_code, std::string firstanalysizeresult_str,
  208. double cal_simiwithbzt) {
  209. if (oGTParam.wellname.empty() || nGTParam.wellname.empty()) {
  210. std::cout << "Warning:不满诊断数据条件,二次诊断已跳过,使用一次诊断结果" << std::endl;
  211. return firstanalysizeresult_str;
  212. }
  213. std::vector<dgns_gtcvrparam> params = gtdgnsdao::getDgns_gtcvrparamContent(sec_func_paramid, sec_func_paramname);
  214. dgns_gtcvrparam paramintegrate;
  215. if (params.size() == 0) {
  216. paramintegrate.paramitemname = sec_func_paramname;
  217. paramintegrate.paramid = sec_func_paramid;
  218. paramintegrate.paramcontent = paramintegrate.allParamToJsonTranslate();
  219. gtdgnsdao::addDgns_gtcvrparamContent(paramintegrate);
  220. } else {
  221. paramintegrate = params[0];
  222. }
  223. std::string sec_result;
  224. dgns_gtcvrparam::paramworksyschange *p = (dgns_gtcvrparam::paramworksyschange *) paramintegrate.getParam(
  225. dgns_gtcvrparam::paramworksyschange_);
  226. sec_result = pro_worksystemchange(oGTParam, nGTParam, *p);
  227. if (!sec_result.empty()) return sec_result;
  228. switch (firstanalysizeresult_code) {
  229. case 1:
  230. case 6:
  231. case 8:
  232. case 17:
  233. case 18: {
  234. dgns_gtcvrparam::paramrodbreaktype *pa = (dgns_gtcvrparam::paramrodbreaktype *) paramintegrate.getParam(
  235. dgns_gtcvrparam::paramrodbreaktype_);
  236. sec_result = pro_rodbreaktype_gather(oGTParam, nGTParam, firstanalysizeresult_str, cal_simiwithbzt, *pa);
  237. break;
  238. }
  239. case 2: {
  240. sec_result = firstanalysizeresult_str;
  241. break;
  242. }
  243. case 3: {
  244. sec_result = firstanalysizeresult_str;
  245. break;
  246. }
  247. case 4: {
  248. sec_result = firstanalysizeresult_str;
  249. break;
  250. }
  251. case 5: {
  252. sec_result = firstanalysizeresult_str;
  253. break;
  254. }
  255. case 7: {
  256. sec_result = firstanalysizeresult_str;
  257. break;
  258. }
  259. case 9: {
  260. sec_result = firstanalysizeresult_str;
  261. break;
  262. }
  263. case 10: {
  264. sec_result = firstanalysizeresult_str;
  265. break;
  266. }
  267. case 11:
  268. case 13:
  269. case 14:
  270. case 15: {
  271. sec_result = pro_topbottomtouch(nGTParam.sgt, nGTParam.l_min, nGTParam.l_max, nGTParam.s_max,
  272. nGTParam.sgtpointnum);
  273. if (sec_result.empty()) sec_result = "严重供液不足";
  274. else return sec_result = firstanalysizeresult_str;
  275. break;
  276. }
  277. case 12: {
  278. sec_result = firstanalysizeresult_str;
  279. break;
  280. }
  281. case 16: {
  282. sec_result = firstanalysizeresult_str;
  283. break;
  284. }
  285. case 19: {
  286. sec_result = firstanalysizeresult_str;
  287. break;
  288. }
  289. case 20: {
  290. sec_result = firstanalysizeresult_str;
  291. break;
  292. }
  293. case 21: {
  294. dgns_gtcvrparam::paramoutsandorvibration *pa = (dgns_gtcvrparam::paramoutsandorvibration *) paramintegrate.getParam(
  295. dgns_gtcvrparam::paramoutsandorvibration_);
  296. sec_result = pro_outsandorvibration(oGTParam, nGTParam, *pa);
  297. break;
  298. }
  299. default: {
  300. std::cout << "undefined gtmlypte !! please improve the case:* ?" << std::endl;
  301. break;
  302. }
  303. }
  304. if (sec_result.empty()) {
  305. std::cout << "secondly diagnose is fault!" << std::endl;
  306. }
  307. return sec_result;
  308. }