更新122
This commit is contained in:
@@ -60,7 +60,7 @@ namespace TabletTester2025.Services
|
||||
{
|
||||
var data = batches.ToList();
|
||||
var sheet = package.Workbook.Worksheets.Add("硬度报表");
|
||||
WriteHeader(sheet, "检测时间", "样品名称", "平均值(N)", "RSD(%)", "最大值(N)", "最小值(N)", "测试次数", "内控下限(N)", "内控上限(N)", "判定");
|
||||
WriteHeader(sheet, "检测时间", "样品名称", "平均值(N)", "平均偏差(N)", "RSD(%)", "最大值(N)", "最小值(N)", "测试次数", "单次数据(N)", "内控下限(N)", "内控上限(N)", "判定");
|
||||
|
||||
if (data.Count == 0)
|
||||
{
|
||||
@@ -75,13 +75,40 @@ namespace TabletTester2025.Services
|
||||
sheet.Cells[row, 1].Value = b.TestTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
sheet.Cells[row, 2].Value = b.SampleName;
|
||||
sheet.Cells[row, 3].Value = b.HardnessAvg;
|
||||
sheet.Cells[row, 4].Value = b.HardnessRSD;
|
||||
sheet.Cells[row, 5].Value = b.HardnessMax;
|
||||
sheet.Cells[row, 6].Value = b.HardnessMin;
|
||||
sheet.Cells[row, 7].Value = b.HardnessTestCount;
|
||||
sheet.Cells[row, 8].Value = b.HardnessInternalMin;
|
||||
sheet.Cells[row, 9].Value = b.HardnessInternalMax;
|
||||
sheet.Cells[row, 10].Value = b.HardnessPassText;
|
||||
sheet.Cells[row, 4].Value = b.HardnessAverageDeviation;
|
||||
sheet.Cells[row, 5].Value = b.HardnessRSD;
|
||||
sheet.Cells[row, 6].Value = b.HardnessMax;
|
||||
sheet.Cells[row, 7].Value = b.HardnessMin;
|
||||
sheet.Cells[row, 8].Value = b.HardnessTestCount;
|
||||
sheet.Cells[row, 9].Value = b.HardnessSampleSummary;
|
||||
sheet.Cells[row, 10].Value = b.HardnessInternalMin;
|
||||
sheet.Cells[row, 11].Value = b.HardnessInternalMax;
|
||||
sheet.Cells[row, 12].Value = b.HardnessPassText;
|
||||
row++;
|
||||
}
|
||||
|
||||
sheet.Cells.AutoFitColumns();
|
||||
AddHardnessSamplesSheet(package, data);
|
||||
}
|
||||
|
||||
private static void AddHardnessSamplesSheet(ExcelPackage package, IEnumerable<TestBatch> batches)
|
||||
{
|
||||
var samples = GetHardnessSampleRows(batches).ToList();
|
||||
if (samples.Count == 0)
|
||||
return;
|
||||
|
||||
var sheet = package.Workbook.Worksheets.Add("硬度单次明细");
|
||||
WriteHeader(sheet, "检测时间", "样品名称", "序号", "硬度值(N)", "与平均值偏差(N)", "记录时间");
|
||||
|
||||
int row = 2;
|
||||
foreach (var item in samples)
|
||||
{
|
||||
sheet.Cells[row, 1].Value = item.Batch.TestTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
sheet.Cells[row, 2].Value = item.Batch.SampleName;
|
||||
sheet.Cells[row, 3].Value = item.Sample.SequenceNo;
|
||||
sheet.Cells[row, 4].Value = item.Sample.Value;
|
||||
sheet.Cells[row, 5].Value = item.Sample.DeviationFromAverage;
|
||||
sheet.Cells[row, 6].Value = item.Sample.RecordedAt.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
row++;
|
||||
}
|
||||
|
||||
@@ -297,6 +324,15 @@ namespace TabletTester2025.Services
|
||||
.ThenBy(x => x.Sample.ScheduledTimeMin);
|
||||
}
|
||||
|
||||
private static IEnumerable<(TestBatch Batch, HardnessSamplePoint Sample)> GetHardnessSampleRows(IEnumerable<TestBatch> batches)
|
||||
{
|
||||
return batches
|
||||
.SelectMany(batch => (batch.HardnessSamples ?? Enumerable.Empty<HardnessSamplePoint>())
|
||||
.Select(sample => (Batch: batch, Sample: sample)))
|
||||
.OrderBy(x => x.Batch.TestTime)
|
||||
.ThenBy(x => x.Sample.SequenceNo);
|
||||
}
|
||||
|
||||
private static void WriteHeader(ExcelWorksheet sheet, params string[] headers)
|
||||
{
|
||||
for (int i = 0; i < headers.Length; i++)
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace TabletTester2025.Services
|
||||
{
|
||||
public readonly record struct HardnessStatistics(
|
||||
double Average,
|
||||
double AverageDeviation,
|
||||
double RsdPercent,
|
||||
double Maximum,
|
||||
double Minimum,
|
||||
@@ -26,9 +27,10 @@ namespace TabletTester2025.Services
|
||||
.ToList();
|
||||
|
||||
if (validValues.Count == 0)
|
||||
return new HardnessStatistics(0, 0, 0, 0, 0, false);
|
||||
return new HardnessStatistics(0, 0, 0, 0, 0, 0, false);
|
||||
|
||||
double average = validValues.Average();
|
||||
double averageDeviation = validValues.Average(value => Math.Abs(value - average));
|
||||
double standardDeviation = CalculateSampleStandardDeviation(validValues, average);
|
||||
double rsd = average == 0 ? 0 : standardDeviation / average * 100;
|
||||
bool countMet = validValues.Count >= Math.Max(1, requiredCount);
|
||||
@@ -36,6 +38,7 @@ namespace TabletTester2025.Services
|
||||
|
||||
return new HardnessStatistics(
|
||||
average,
|
||||
averageDeviation,
|
||||
rsd,
|
||||
validValues.Max(),
|
||||
validValues.Min(),
|
||||
|
||||
Reference in New Issue
Block a user