This commit is contained in:
GukSang.Jin
2026-05-29 16:32:14 +08:00
parent 3701c3cb02
commit 9d9d091e74
2 changed files with 41 additions and 7 deletions

View File

@@ -119,10 +119,10 @@ public sealed class NpoiReportExportService : IReportExportService
SetValueBesideLabel(sheet, "大气压力", input.AtmosphericPressure); SetValueBesideLabel(sheet, "大气压力", input.AtmosphericPressure);
SetValueBesideLabel(sheet, "大气湿度", input.AtmosphericHumidity); SetValueBesideLabel(sheet, "大气湿度", input.AtmosphericHumidity);
SetValueBesideLabel(sheet, "时间记录", input.TimeRecord); SetValueBesideLabel(sheet, "时间记录", input.TimeRecord);
SetValueBesideLabel(sheet, "点燃时间", FirstNonEmpty(input.IgnitionTime, summary.IgnitionTime)); SetValueBesideLabel(sheet, "点燃时间", summary.IgnitionTime);
SetValueBesideLabel(sheet, "熄灭时间", input.FlameoutTime); SetValueBesideLabel(sheet, "熄灭时间", input.FlameoutTime);
SetValueBesideLabel(sheet, "结束标准", input.EndCriteria); SetValueBesideLabel(sheet, "结束标准", input.EndCriteria);
SetValueBesideLabel(sheet, "结束时间", FirstNonEmpty(input.EndTime, summary.EndTime)); SetValueBesideLabel(sheet, "结束时间", summary.EndTime);
SetValueBesideLabel(sheet, "E等价热值", input.EquivalentHeatValue); SetValueBesideLabel(sheet, "E等价热值", input.EquivalentHeatValue);
SetRequiredValueBesideLabel(sheet, "C-系数", FirstNonEmpty(input.CFactor, summary.CFactor)); SetRequiredValueBesideLabel(sheet, "C-系数", FirstNonEmpty(input.CFactor, summary.CFactor));
SetValueBesideLabel(sheet, "光程", input.LightPath); SetValueBesideLabel(sheet, "光程", input.LightPath);
@@ -325,6 +325,7 @@ public sealed class NpoiReportExportService : IReportExportService
private static bool SetValueBesideLabel(ISheet sheet, string label, string value) private static bool SetValueBesideLabel(ISheet sheet, string label, string value)
{ {
var updated = false;
for (var rowIndex = sheet.FirstRowNum; rowIndex <= sheet.LastRowNum; rowIndex++) for (var rowIndex = sheet.FirstRowNum; rowIndex <= sheet.LastRowNum; rowIndex++)
{ {
var row = sheet.GetRow(rowIndex); var row = sheet.GetRow(rowIndex);
@@ -349,11 +350,11 @@ public sealed class NpoiReportExportService : IReportExportService
var targetColumn = FindTargetColumn(sheet, rowIndex, columnIndex); var targetColumn = FindTargetColumn(sheet, rowIndex, columnIndex);
var target = row.GetCell(targetColumn) ?? row.CreateCell(targetColumn); var target = row.GetCell(targetColumn) ?? row.CreateCell(targetColumn);
SetTextOrBlank(target, value); SetTextOrBlank(target, value);
return true; updated = true;
} }
} }
return false; return updated;
} }
private static void SetGraphValuesBesideLabel(ISheet sheet, string label, string value) private static void SetGraphValuesBesideLabel(ISheet sheet, string label, string value)
@@ -561,8 +562,6 @@ public sealed class NpoiReportExportService : IReportExportService
} }
var last = records[^1]; var last = records[^1];
var ignition = records.FirstOrDefault(record => record.FlameDetected)?.TestSeconds;
return new ReportSummary( return new ReportSummary(
PeakHeatReleaseRate: FormatWithUnit(LastFinite(records, record => record.PeakHeatReleaseRate), "kW/㎡"), PeakHeatReleaseRate: FormatWithUnit(LastFinite(records, record => record.PeakHeatReleaseRate), "kW/㎡"),
PeakSmokeProduction: FormatWithUnit(MaxFinite(records, record => record.SmokeProduction), "m²/s"), PeakSmokeProduction: FormatWithUnit(MaxFinite(records, record => record.SmokeProduction), "m²/s"),
@@ -571,7 +570,7 @@ public sealed class NpoiReportExportService : IReportExportService
MassLoss: FormatWithUnit(LastFinite(records, record => record.MassLoss), "g"), MassLoss: FormatWithUnit(LastFinite(records, record => record.MassLoss), "g"),
InitialMass: FormatWithUnit(LastFinite(records, record => record.InitialMass), "g"), InitialMass: FormatWithUnit(LastFinite(records, record => record.InitialMass), "g"),
CFactor: FormatValue(LastFinite(records, record => record.CFactor)), CFactor: FormatValue(LastFinite(records, record => record.CFactor)),
IgnitionTime: FormatSeconds(ignition), IgnitionTime: FormatSeconds(LastNonNegative(records, record => record.IgnitionSeconds)),
EndTime: FormatSeconds(last.TestSeconds)); EndTime: FormatSeconds(last.TestSeconds));
} }
@@ -646,6 +645,20 @@ public sealed class NpoiReportExportService : IReportExportService
return max; return max;
} }
private static int? LastNonNegative(IReadOnlyList<RealtimeDataRecord> records, Func<RealtimeDataRecord, int> selector)
{
for (var i = records.Count - 1; i >= 0; i--)
{
var value = selector(records[i]);
if (value >= 0)
{
return value;
}
}
return null;
}
private static string FirstNonEmpty(params string[] values) private static string FirstNonEmpty(params string[] values)
{ {
return values.FirstOrDefault(value => !string.IsNullOrWhiteSpace(value)) ?? string.Empty; return values.FirstOrDefault(value => !string.IsNullOrWhiteSpace(value)) ?? string.Empty;

View File

@@ -251,6 +251,8 @@ public sealed class ReportPageViewModel : PageViewModel
{ {
FindField("InitialMass")?.SetAutoValue(FormatWithUnit(LastFinite(records, record => record.InitialMass), "g")); FindField("InitialMass")?.SetAutoValue(FormatWithUnit(LastFinite(records, record => record.InitialMass), "g"));
FindField("CFactor")?.SetAutoValue(FormatValue(LastFinite(records, record => record.CFactor))); FindField("CFactor")?.SetAutoValue(FormatValue(LastFinite(records, record => record.CFactor)));
FindField("IgnitionTime")?.SetAutoValue(FormatSeconds(LastNonNegative(records, record => record.IgnitionSeconds)));
FindField("EndTime")?.SetAutoValue(FormatSeconds(LastNonNegative(records, record => record.TestSeconds)));
} }
private ReportFieldViewModel? FindField(string key) private ReportFieldViewModel? FindField(string key)
@@ -273,6 +275,25 @@ public sealed class ReportPageViewModel : PageViewModel
return double.NaN; return double.NaN;
} }
private static int? LastNonNegative(IReadOnlyList<RealtimeDataRecord> records, Func<RealtimeDataRecord, int> selector)
{
for (var i = records.Count - 1; i >= 0; i--)
{
var value = selector(records[i]);
if (value >= 0)
{
return value;
}
}
return null;
}
private static string FormatSeconds(int? value)
{
return value.HasValue ? $"{value.Value} s" : string.Empty;
}
private static string FormatValue(double value) private static string FormatValue(double value)
{ {
return double.IsFinite(value) ? $"{value:0.00}" : string.Empty; return double.IsFinite(value) ? $"{value:0.00}" : string.Empty;