215 lines
6.5 KiB
C#
215 lines
6.5 KiB
C#
using HardwareControl.Core.Scanning;
|
|
|
|
namespace HardwareWeb.Models
|
|
{
|
|
/// <summary>位移台实时位置。</summary>
|
|
public sealed record StagePositionPayload(
|
|
int X,
|
|
int Y,
|
|
int Z,
|
|
bool Moving,
|
|
DateTimeOffset UpdatedAt)
|
|
{
|
|
public static StagePositionPayload From(StagePosition position) =>
|
|
new(position.X, position.Y, position.Z, position.Moving, position.UpdatedAt);
|
|
}
|
|
|
|
/// <summary>扫描进度。</summary>
|
|
public sealed record ScanProgressPayload(
|
|
string ScanId,
|
|
string Phase,
|
|
int PointIndex,
|
|
int TotalPoints,
|
|
int CompletedPoints,
|
|
int Percent,
|
|
string Message,
|
|
int StageX,
|
|
int StageY,
|
|
bool StageMoving,
|
|
DateTimeOffset UpdatedAt)
|
|
{
|
|
public static ScanProgressPayload From(ScanProgress progress) =>
|
|
new(
|
|
progress.ScanId,
|
|
progress.Phase.ToString(),
|
|
progress.PointIndex,
|
|
progress.TotalPoints,
|
|
progress.CompletedPoints,
|
|
progress.Percent,
|
|
progress.Message,
|
|
progress.StageX,
|
|
progress.StageY,
|
|
progress.StageMoving,
|
|
progress.UpdatedAt);
|
|
}
|
|
|
|
public sealed record ScanSegmentPayload(
|
|
int DeviceIndex,
|
|
string SerialNumber,
|
|
double WavelengthStart,
|
|
double WavelengthEnd,
|
|
int PointCount)
|
|
{
|
|
public static ScanSegmentPayload From(ScanSegmentRecord segment) =>
|
|
new(
|
|
segment.DeviceIndex,
|
|
segment.SerialNumber,
|
|
segment.WavelengthStart,
|
|
segment.WavelengthEnd,
|
|
segment.PointCount);
|
|
}
|
|
|
|
/// <summary>单个采样点采集完成时的实时光谱。</summary>
|
|
public sealed record ScanSpectrumPayload(
|
|
string ScanId,
|
|
int PointIndex,
|
|
int TotalPoints,
|
|
float[] Wavelengths,
|
|
float[] Spectrum,
|
|
IReadOnlyList<ScanSegmentPayload> Segments)
|
|
{
|
|
public static ScanSpectrumPayload From(ScanPointAcquired acquired) =>
|
|
new(
|
|
acquired.ScanId,
|
|
acquired.PointIndex,
|
|
acquired.TotalPoints,
|
|
acquired.Wavelengths,
|
|
acquired.Spectrum,
|
|
acquired.Segments.Select(ScanSegmentPayload.From).ToList());
|
|
}
|
|
|
|
public sealed record ScanFinishedPayload(
|
|
string ScanId,
|
|
string Status,
|
|
string? Error);
|
|
|
|
public sealed record ScanElementPayload(
|
|
string Symbol,
|
|
string Name,
|
|
string IntensityLevel,
|
|
double Abundance,
|
|
double RawAbundance,
|
|
string Verdict,
|
|
double MaxIntensity,
|
|
double MatchedWavelength,
|
|
int MatchedLines)
|
|
{
|
|
public static ScanElementPayload From(ScanElementRecord element) =>
|
|
new(
|
|
element.Symbol,
|
|
element.Name,
|
|
element.IntensityLevel,
|
|
element.Abundance,
|
|
element.RawAbundance,
|
|
element.Verdict,
|
|
element.MaxIntensity,
|
|
element.MatchedWavelength,
|
|
element.MatchedLines);
|
|
}
|
|
|
|
public sealed record ScanPointPayload(
|
|
int Index,
|
|
int PixelX,
|
|
int PixelY,
|
|
int StageX,
|
|
int StageY,
|
|
bool Succeeded,
|
|
string? Error,
|
|
float[] Wavelengths,
|
|
float[] Spectrum,
|
|
IReadOnlyList<ScanSegmentPayload> Segments,
|
|
IReadOnlyList<ScanElementPayload> Elements,
|
|
double Temperature,
|
|
double ElectronDensity,
|
|
DateTimeOffset AcquiredAt)
|
|
{
|
|
public static ScanPointPayload From(ScanPointRecord point) =>
|
|
new(
|
|
point.Index,
|
|
point.PixelX,
|
|
point.PixelY,
|
|
point.StageX,
|
|
point.StageY,
|
|
point.Succeeded,
|
|
point.Error,
|
|
point.Wavelengths,
|
|
point.Spectrum,
|
|
point.Segments.Select(ScanSegmentPayload.From).ToList(),
|
|
point.Elements.Select(ScanElementPayload.From).ToList(),
|
|
point.Temperature,
|
|
point.ElectronDensity,
|
|
point.AcquiredAt);
|
|
}
|
|
|
|
/// <summary>一次完整扫描的结果。</summary>
|
|
public sealed record ScanRunPayload(
|
|
string ScanId,
|
|
string Status,
|
|
DateTimeOffset StartedAt,
|
|
DateTimeOffset? FinishedAt,
|
|
string? Error,
|
|
int TotalPoints,
|
|
int CompletedPoints,
|
|
int ImageWidth,
|
|
int ImageHeight,
|
|
string? ImageMimeType,
|
|
string? ImageBase64,
|
|
IReadOnlyList<ScanPointPayload> Points)
|
|
{
|
|
public static ScanRunPayload From(
|
|
ScanRunRecord run,
|
|
IReadOnlyList<ScanPointRecord> points) =>
|
|
new(
|
|
run.ScanId,
|
|
run.Status.ToString(),
|
|
run.StartedAt,
|
|
run.FinishedAt,
|
|
run.Error,
|
|
run.TotalPoints,
|
|
run.CompletedPoints,
|
|
run.ImageWidth,
|
|
run.ImageHeight,
|
|
run.ImageMimeType,
|
|
run.ImageData is { Length: > 0 }
|
|
? Convert.ToBase64String(run.ImageData)
|
|
: null,
|
|
points.Select(ScanPointPayload.From).ToList());
|
|
}
|
|
|
|
public sealed record ScanStartResponse(string ScanId, int TotalPoints);
|
|
|
|
/// <summary>历史列表中的一条扫描记录(不含图片与光谱数据)。</summary>
|
|
public sealed record ScanHistoryItemPayload(
|
|
string ScanId,
|
|
string Status,
|
|
DateTimeOffset StartedAt,
|
|
DateTimeOffset? FinishedAt,
|
|
int TotalPoints,
|
|
int CompletedPoints,
|
|
string? Error)
|
|
{
|
|
public static ScanHistoryItemPayload From(ScanRunRecord run) =>
|
|
new(
|
|
run.ScanId,
|
|
run.Status.ToString(),
|
|
run.StartedAt,
|
|
run.FinishedAt,
|
|
run.TotalPoints,
|
|
run.CompletedPoints,
|
|
run.Error);
|
|
}
|
|
|
|
public sealed record DeviceStatusItemPayload(
|
|
string Key,
|
|
string Name,
|
|
bool Connected,
|
|
string Status,
|
|
string? Message,
|
|
DateTimeOffset UpdatedAt);
|
|
|
|
public sealed record DeviceStatusPayload(
|
|
bool AllConnected,
|
|
IReadOnlyList<DeviceStatusItemPayload> Devices,
|
|
DateTimeOffset UpdatedAt);
|
|
}
|