|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
using BrilliantSightClient.Model.Entity.ApiEntity; |
|
|
|
|
using BrilliantSightClient.Model.Extension; |
|
|
|
|
using BrilliantSightClient.Model.GradeLevel; |
|
|
|
|
using BrilliantSightClient.Model.GradeLevel.Helper; |
|
|
|
|
using BrilliantSightClient.Model.GradeResult.Entity; |
|
|
|
|
using BrilliantSightClient.Model.GradeResult.Entity.Enums; |
|
|
|
@ -15,7 +17,7 @@ public class ViewDataInfoHelper |
|
|
|
|
{ |
|
|
|
|
public static List<DataInfo> GenerateDataInfos(AlgorithmResultEntity result) |
|
|
|
|
{ |
|
|
|
|
JToken measurements = JToken.Parse(JsonConvert.SerializeObject(result.Measurements)); |
|
|
|
|
JToken jData = JToken.Parse(JsonConvert.SerializeObject(result.Measurements)); |
|
|
|
|
List<DataInfo> dataInfos = new List<DataInfo>(); |
|
|
|
|
int shape = EntityHelper.GetValueFromName<DiamondShape>(result.Shape)??-1; |
|
|
|
|
if(shape == -1) throw new Exception("Unsupported shapes"); |
|
|
|
@ -24,11 +26,101 @@ public class ViewDataInfoHelper |
|
|
|
|
foreach (var viewData in showViewData) |
|
|
|
|
{ |
|
|
|
|
DataInfo dataInfo = new DataInfo(); |
|
|
|
|
|
|
|
|
|
dataInfo.TestItemId = viewData.InfoPath; |
|
|
|
|
dataInfo.TestItemName = "Name".Equals(MultilingualHelper.getString("ColumnNameBase"))? viewData.Name : viewData.EName; |
|
|
|
|
if(!viewData.AvgKey.IsNullOrEmpty()) |
|
|
|
|
dataInfo.Avg = DoubleDataFormatHelper.FormatDouble(jData[viewData.AvgKey], viewData.AvgType.ToAccuracy()); |
|
|
|
|
if(!viewData.DevKey.IsNullOrEmpty()) |
|
|
|
|
dataInfo.Dev = DoubleDataFormatHelper.FormatDouble(jData[viewData.DevKey], viewData.DevType.ToAccuracy()); |
|
|
|
|
if(!viewData.MaxKey.IsNullOrEmpty()) |
|
|
|
|
dataInfo.Max = DoubleDataFormatHelper.FormatDouble(jData[viewData.MaxKey], viewData.MaxType.ToAccuracy()); |
|
|
|
|
if(!viewData.MinKey.IsNullOrEmpty()) |
|
|
|
|
dataInfo.Min = DoubleDataFormatHelper.FormatDouble(jData[viewData.MinKey], viewData.MinType.ToAccuracy()); |
|
|
|
|
if (!viewData.DtlKey.IsNullOrEmpty()) |
|
|
|
|
{ |
|
|
|
|
List<string> dtlDoubles = GenerateDtlDoubles(jData, viewData); |
|
|
|
|
dataInfo.Dtl1 = dtlDoubles[0]; |
|
|
|
|
dataInfo.Dtl2 = dtlDoubles[1]; |
|
|
|
|
dataInfo.Dtl3 = dtlDoubles[2]; |
|
|
|
|
dataInfo.Dtl4 = dtlDoubles[3]; |
|
|
|
|
dataInfo.Dtl5 = dtlDoubles[4]; |
|
|
|
|
dataInfo.Dtl6 = dtlDoubles[5]; |
|
|
|
|
dataInfo.Dtl7 = dtlDoubles[6]; |
|
|
|
|
dataInfo.Dtl8 = dtlDoubles[7]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GradeLevelCalculator levelCalculator = new GradeLevelCalculator(result); |
|
|
|
|
dataInfos.Add(dataInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return dataInfos; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<string> GenerateDtlDoubles(JToken data, ViewData viewData) |
|
|
|
|
{ |
|
|
|
|
List<string> result = new List<string>(); |
|
|
|
|
int.TryParse(viewData.DtlCt, out int dtlCt); |
|
|
|
|
JToken? jToken = data[viewData.DtlKey]; |
|
|
|
|
if (jToken == null) return result; |
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= dtlCt; i++) |
|
|
|
|
{ |
|
|
|
|
result.Add(DoubleDataFormatHelper.FormatDouble(jToken[$"{viewData.DtlAttr}_{i}"], viewData.DtlType.ToAccuracy())); |
|
|
|
|
} |
|
|
|
|
return ProcessList(result); |
|
|
|
|
} |
|
|
|
|
/// <summary> |
|
|
|
|
/// 处理字符串列表,确保返回列表长度为8 |
|
|
|
|
/// 超过8个元素时保留最大值和最小值并缩减到8个元素 |
|
|
|
|
/// 不足8个元素时用空字符串补足 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="result">输入的字符串列表,所有元素应可转换为double</param> |
|
|
|
|
/// <returns>处理后的字符串列表,长度固定为8</returns> |
|
|
|
|
public static List<string> ProcessList(List<string> result) |
|
|
|
|
{ |
|
|
|
|
if (result == null) |
|
|
|
|
throw new ArgumentNullException(nameof(result)); |
|
|
|
|
if (result.Count < 8) |
|
|
|
|
{ |
|
|
|
|
var paddedList = new List<string>(result); |
|
|
|
|
while (paddedList.Count < 8) |
|
|
|
|
{ |
|
|
|
|
paddedList.Add(string.Empty); |
|
|
|
|
} |
|
|
|
|
return paddedList; |
|
|
|
|
} |
|
|
|
|
var indexedValues = result |
|
|
|
|
.Select((value, index) => new { Value = double.Parse(value), Index = index }) |
|
|
|
|
.ToList(); |
|
|
|
|
var max = indexedValues.OrderByDescending(x => x.Value).First(); |
|
|
|
|
var min = indexedValues.OrderBy(x => x.Value).First(); |
|
|
|
|
var remaining = indexedValues |
|
|
|
|
.Where(x => x.Index != max.Index && x.Index != min.Index) |
|
|
|
|
.ToList(); |
|
|
|
|
if (remaining.Count <= 6) |
|
|
|
|
{ |
|
|
|
|
var resultList = new List<string> |
|
|
|
|
{ |
|
|
|
|
result[max.Index], |
|
|
|
|
result[min.Index] |
|
|
|
|
}; |
|
|
|
|
resultList.AddRange(remaining.Select(x => result[x.Index])); |
|
|
|
|
while (resultList.Count < 8) |
|
|
|
|
{ |
|
|
|
|
resultList.Add(string.Empty); |
|
|
|
|
} |
|
|
|
|
return resultList; |
|
|
|
|
} |
|
|
|
|
var sampledIndices = new List<int>(); |
|
|
|
|
for (int i = 0; i < 6; i++) |
|
|
|
|
{ |
|
|
|
|
int index = (int)Math.Round(i * (remaining.Count - 1) / 5.0); |
|
|
|
|
sampledIndices.Add(remaining[index].Index); |
|
|
|
|
} |
|
|
|
|
var finalList = new List<string> { result[max.Index] }; |
|
|
|
|
finalList.AddRange(sampledIndices.Select(i => result[i])); |
|
|
|
|
finalList.Add(result[min.Index]); |
|
|
|
|
|
|
|
|
|
return finalList; |
|
|
|
|
} |
|
|
|
|
} |