You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
12 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DQ.Construction.NewLook.DataManager;
using WorkData;
using WorkData.Entity;
#region 文件说明
/*-----------------------------------------------------
* 版权所有 c 2024 jdfcd
* CLR版本 4.0.30319.42000
* 命名空间 DQ.Construction.NewLook.Utility
*
* 创建者pnpe
* 电子邮件pnpe@qq.com
* 创建时间2024/7/6 16:52:09
*/
#endregion 文件说明
namespace WellWorkDataUI
{
public delegate void ProgressCallback(double progress);
public delegate void ProgressCallbackTwo(int progress, int count);
public delegate void ProgressCallbackThree(string name, int progress, int count);
public class CalcDataHelp
{
public static void Reset()
{
sysDeflectionsDict.Clear();
}
private static Dictionary<string, WellDeflectionHelp> sysDeflectionsDict = new Dictionary<string, WellDeflectionHelp>();
/// <summary>
/// 坐标计算
/// </summary>
/// <typeparam name="T">自定义类</typeparam>
/// <param name="list">数据list</param>
/// <param name="getName">获取井号</param>
/// <param name="getHeight">获取深度</param>
/// <param name="onXY">回写xy方法</param>
/// <returns>返回数据</returns>
public static List<T> ComputedXYCoreDetectionOrVertical<T>(List<T> list, Func<T, string> getName, Func<T, (double? sd, double? cs)> getHeight, Action<T, double, double> onXY)
where T : class
{
WellDeflectionHelp deflectionHelp = new WellDeflectionHelp();
deflectionHelp.Initialize();
global::System.Collections.Concurrent.ConcurrentBag<T> listUpdate = new ConcurrentBag<T>();
Parallel.ForEach(list, item =>
{
double? x = 0, y = 0; // , v = 0;
double? sd1 = getHeight(item).sd;
double? cs1 = getHeight(item).cs;
if (sd1.HasValue && deflectionHelp.ComputedXYByDetection(getName(item), sd1, ref x, ref y))
{
onXY(item, x.GetValueOrDefault(0), y.GetValueOrDefault(0));
listUpdate.Add(item);
}
else if (cs1.HasValue && deflectionHelp.ComputedXYByVerticalNew(getName(item), cs1, ref x, ref y))
{
onXY(item, x.GetValueOrDefault(0), y.GetValueOrDefault(0));
listUpdate.Add(item);
}
});
return listUpdate.ToList();
}
/// <summary>
/// Computeds the x y and z2 core single.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="getItem">The get item.</param>
/// <param name="dic_calc">The dic_calc.</param>
/// <param name="updateItem">The update item.</param>
/// <returns>A T.</returns>
public static T ComputedXYAndZ2CoreSingle<T>(T item, WellDeflectionHelp deflectionHelp, string JH, double? sd1, double? sd2, double? cs1, double? cs2, double? hd, double? v_hd, double? x, double? y, HashSet<int> dic_calc, Action<T, Dictionary<string, double?>> updateItem)
{
// 井斜xy
Dictionary<string, double?> update = new Dictionary<string, double?>();
if (cs1.HasValue && v_hd.HasValue && !cs2.HasValue)
{
cs2 = cs1.Value + v_hd.Value;
update.Add("CS_B", cs2);
}
else if (cs2.HasValue && v_hd.HasValue && !cs1.HasValue)
{
cs1 = cs2.Value - v_hd.Value;
update.Add("CS_T", cs1);
}
if (sd1.HasValue && hd.HasValue && !sd2.HasValue)
{
sd2 = sd1.Value + hd.Value;
update.Add("DJSD", sd2);
}
else if (sd2.HasValue && hd.HasValue && !sd1.HasValue)
{
sd1 = sd2.Value - hd.Value;
update.Add("SD", sd1);
}
// bool csStatus = true;
// bool sdStatus = true;
// if (!sd2.HasValue || !sd1.HasValue)
// {
// sdStatus = false;
// }
// if (!cs2.HasValue || !cs1.HasValue)
// {
// csStatus = false;
// }
if (dic_calc.Contains(3) && !cs1.HasValue && deflectionHelp.ComputedZByDetection(JH, sd1, ref cs1))
{
update.Add("CS_T", cs1);
}
if (dic_calc.Contains(4) && !cs2.HasValue && deflectionHelp.ComputedZByDetection(JH, sd2, ref cs2))
{
update.Add("CS_B", cs2);
}
// 垂深算测深
if (dic_calc.Contains(1) && !sd1.HasValue && deflectionHelp.ComputedZByVertical(JH, cs1, ref sd1))
{
update.Add("SD", sd1);
}
// 垂深算测深
if (dic_calc.Contains(2) && !sd2.HasValue && deflectionHelp.ComputedZByVertical(JH, cs2, ref sd2))
{
update.Add("DJSD", sd2);
}
if (!x.HasValue || !y.HasValue)
{
if (dic_calc.Contains(7) && sd1.HasValue && deflectionHelp.ComputedXYByDetection(JH, sd1, ref x, ref y))
{
update.Add("X", x);
update.Add("Y", y);
}
else if (dic_calc.Contains(7) && cs1.HasValue && deflectionHelp.ComputedXYByVerticalNew(JH, cs1, ref x, ref y))
{
update.Add("X", x);
update.Add("Y", y);
}
}
updateItem(item, update);
return item;
}
/// <summary>
/// 使用多线程计算xyz
/// </summary>
/// <param name="list">The list.</param>
/// <param name="getItem">The get item.</param>
/// <param name="dic_calc">The dic_calc.</param>
/// <param name="updateItem">The update item.</param>
/// <returns>A list of TS.</returns>
public static List<T> ComputedXYAndZ2Core<T>(List<T> list, Func<T, (string JH, double? sd1, double? sd2, double? cs1, double? cs2, double? hd, double? v_hd, double? x, double? y)> getItem, HashSet<int> dic_calc, Action<T, Dictionary<string, double?>> updateItem, ProgressCallback progressCallback)
where T : class
{
int totalCount = list.Count;
int processedCount = 0;
ConcurrentBag<T> listUpdate = new ConcurrentBag<T>();
Stopwatch sw = Stopwatch.StartNew();
SimpleWell[] simpleWells = DBHelp.Db.Queryable<WellBase>().Select(it => new SimpleWell() { JH = it.JH, X = it.X.Value, Y = it.Y.Value })
.Where(it => it.X > 0 && it.Y > 0).ToArray();
int i = 0;
List<WellDeflection> wds = DBHelp.Db.Queryable<WellDeflection>().ToList();
List<SimpleDeflection> wellDeflections = new List<SimpleDeflection>();
Parallel.ForEach(wds, EntityHelp.Options, item =>
{
try
{
i++;
if (item == null || string.IsNullOrWhiteSpace(item.JH) || sysDeflectionsDict.ContainsKey(item.JH))
{
return;
}
List<WellDeflection> itemDatas = EntityHelp.GetWellDeflections(item.FileName);
List<SimpleDeflection> sds = new List<SimpleDeflection>();
if (itemDatas != null && itemDatas.Any())
{
for (var j = 0; j < itemDatas.Count; j++)
{
var itemData = itemDatas[j];
var sd = new SimpleDeflection
{
JH = item.JH,
BZB = itemData.BZB.HasValue ? itemData.BZB.Value : 0,
DZB = itemData.DZB.HasValue ? itemData.DZB.Value : 0,
JS = itemData.JS.HasValue ? itemData.JS.Value : 0,
CS = itemData.CS.HasValue ? itemData.CS.Value : 0,
};
sds.Add(sd);
}
}
var deflectionHelp1 = new WellDeflectionHelp();
if (sds != null && sds.Count > 0)
{
deflectionHelp1.Initialize(item.JH, simpleWells, sds?.ToList().ToArray());
}
try
{
//Console.WriteLine($"******************{item.JH}*******************");
if (deflectionHelp1 != null)
{
sysDeflectionsDict.Add(item.JH, deflectionHelp1);
}
else
{
sysDeflectionsDict.Add(item.JH, new WellDeflectionHelp());
}
}
catch (Exception iex)
{
//Console.WriteLine($"******************{item.JH}*******************");
Console.WriteLine($"计算数据异常:{iex.Message}");
}
}
catch (Exception ex)
{
Console.WriteLine($"=============计算XYZ异常{ex.Message} =======================");
}
});
Console.WriteLine($"数据准备完毕{sw.Elapsed}");
object obj = new object();
Parallel.ForEach(list, (item, index) =>
{
string jh = getItem(item).JH;
if (jh != null)
{
double? sd1 = getItem(item).sd1;
double? sd2 = getItem(item).sd2;
double? cs1 = getItem(item).cs1;
double? cs2 = getItem(item).cs2;
double? hd = getItem(item).hd;
double? v_hd = getItem(item).v_hd;
double? x = getItem(item).x;
double? y = getItem(item).y;
WellDeflectionHelp deflectionHelp;
if (!sysDeflectionsDict.ContainsKey(jh))
{
deflectionHelp = new WellDeflectionHelp();
deflectionHelp.Initialize(jh, simpleWells, new List<SimpleDeflection>().ToArray());
}
else
{
deflectionHelp = sysDeflectionsDict[jh];
}
listUpdate.Add(ComputedXYAndZ2CoreSingle(item, deflectionHelp, jh, sd1, sd2, cs1, cs2, hd, v_hd, x, y, dic_calc, updateItem));
//Console.WriteLine($"{processedCount}耗时:{sw.Elapsed.TotalMilliseconds}");
}
Interlocked.Increment(ref processedCount);
double currentProgress = processedCount * 100.00 / totalCount;
if (currentProgress <= 100)
{
progressCallback(currentProgress);
}
});
sw.Stop();
Console.WriteLine($"总耗时:{sw.Elapsed.TotalMilliseconds}");
progressCallback(100);
return listUpdate.ToList();
}
}
}