using ErrorAnalysis.Repository; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Runtime.InteropServices.JavaScript.JSType; namespace ErrorAnalysis.Service { public class COMergeCalcService { //Ncoef=1e8*2.54*2.54*2*6*11*2*77*0.2/0.6*speed; //Fcoef=1e8*2.54*2.54*4*6*2*11*77*0.2/0.6*speed; const double _gg = (9.0 - 0.0) / 255.0;//0.03529 const double _offset = 0.0; const int _cWinStartIndex = (int)(3.3 / _gg + _offset); //C窗口index const int _cWinEndIndex = (int)(4.78 / _gg + _offset); // width= 4.78-3.3 = 1.48 const int _oWinStartIndex = (int)(4.88 / _gg + _offset); // org const int _oWinEndIndex = (int)(6.36 / _gg + _offset); // width = 6.36-4.88=1.48 private static double GetFarInterplolateResult(string modelId, double porosity, double sw, int readSw, double speed, double depth) { double result = 0; var cResult = RepositoryInstance.Instance.COFarResultRepository?.GetCOFarResult(modelId, (int)porosity, readSw); if (cResult == null) throw new InvalidDataException("COFarResult not found"); var cArr = cResult.InelasticSpec?.Split(',').Select(v => Convert.ToDouble(v)).ToArray(); if (cArr == null) throw new InvalidDataException("COFarResult InelasticSpec is null"); var length = readSw == 0 ? _cWinEndIndex - _cWinStartIndex + 1 : _oWinEndIndex - _oWinStartIndex + 1; var originC = cArr.Skip(readSw == 0 ? _cWinStartIndex : _oWinStartIndex).Take(length).Sum(); var coef = originC * 1e8 * 2.54 * 2.54 * 4 * 6 * 2 * 11 * 77 * 0.2 / 0.6 / speed * depth * 0.07; result = coef; if (sw > 0 && sw < 100) { if (readSw == 0) result = Utility.Interpolate(sw, 100, 0, 0, coef); else result = Utility.Interpolate(sw, 0, 0, 100, coef); } return result; } private static double GetNearInterplolateResult(string modelId, double porosity, double sw, int readSw, double speed, double depth) { double result = 0; var cResult = RepositoryInstance.Instance.CONearResultRepository?.GetCONearResult(modelId, (int)porosity, readSw); if (cResult == null) throw new InvalidDataException("CONearResult not found"); var cArr = cResult.InelasticSpec?.Split(',').Select(v => Convert.ToDouble(v)).ToArray(); if (cArr == null) throw new InvalidDataException("CONearResult InelasticSpec is null"); var length = readSw == 0 ? _cWinEndIndex - _cWinStartIndex + 1 : _oWinEndIndex - _oWinStartIndex + 1; var originC = cArr.Skip(readSw == 0 ? _cWinStartIndex : _oWinStartIndex).Take(length).Sum(); var coef = originC * 1e8 * 2.54 * 2.54 * 2 * 6 * 11 * 2 * 77 * 0.2 / 0.6 / speed * depth * 0.07; result = coef; if (sw > 0 && sw < 100) { if (readSw == 0) result = Utility.Interpolate(sw, 100, 0, 0, coef); else result = Utility.Interpolate(sw, 0, 0, 100, coef); } return result; } /// /// 获取远探头C或O值 /// /// 数据库连接字符串 /// 管柱ID /// 孔隙度 /// 含水饱和度 /// 读取含水饱和度(0为碳,100为氧) /// 测速 /// 深度 /// 碳或氧值 /// 孔隙度超过范围 public static double GetFarMergeCOResult(string modelId, double porosity, double sw, int readSw, double speed, double depth) { if (porosity > 40) throw new InvalidDataException("Porosity value out of range!"); double result = 0; if (porosity % 5 == 0) { result = GetFarInterplolateResult(modelId, porosity, sw, readSw, speed, depth); } else { double ceilingResult = 0; var ceilingPorosity = Math.Ceiling(porosity / 5) * 5; ceilingResult = GetFarInterplolateResult(modelId, ceilingPorosity, sw, readSw, speed, depth); double floorResult = 0; var floorPorosity = Math.Floor(porosity / 5) * 5; floorResult = GetFarInterplolateResult(modelId, floorPorosity, sw, readSw, speed, depth); result = Utility.Interpolate(porosity, floorPorosity, floorResult, ceilingPorosity, ceilingResult); } return result; } /// /// 获取近探头C或O值 /// /// 数据库连接字符串 /// 管柱ID /// 孔隙度 /// 含水饱和度 /// 读取含水饱和度(0为碳,100为氧) /// 测速 /// 深度 /// 碳或氧值 /// 孔隙度超过范围 public static double GetNearMergeCOResult(string modelId, double porosity, double sw, int readSw, double speed, double depth) { if (porosity > 40) throw new InvalidDataException("Porosity value out of range!"); double result = 0; if (porosity % 5 == 0) { result = GetNearInterplolateResult(modelId, porosity, sw, readSw, speed, depth); } else { double ceilingResult = 0; var ceilingPorosity = Math.Ceiling(porosity / 5) * 5; ceilingResult = GetNearInterplolateResult(modelId, ceilingPorosity, sw, readSw, speed, depth); double floorResult = 0; var floorPorosity = Math.Floor(porosity / 5) * 5; floorResult = GetNearInterplolateResult(modelId, floorPorosity, sw, readSw, speed, depth); result = Utility.Interpolate(porosity, floorPorosity, floorResult, ceilingPorosity, ceilingResult); } return result; } } }