using Prism.Commands;
using System.Collections.ObjectModel;
using System.Windows.Input;
using UIShare.PubEvent;
using UIShare.ViewModelBase;
namespace CurveModule.ViewModels.Dialogs
{
///
/// 曲线统计结果弹窗 ViewModel。
///
public class CurveStatisticsViewModel : DialogViewModelBase
{
#region 属性
private string _title = "曲线数学统计";
public string Title
{
get => _title;
set => SetProperty(ref _title, value);
}
public ObservableCollection Results { get; } = new();
#endregion
#region 命令
public ICommand CloseCommand { get; }
#endregion
public CurveStatisticsViewModel(IContainerProvider containerProvider) : base(containerProvider)
{
CloseCommand = new DelegateCommand(Close);
}
private void Close()
{
RequestClose.Invoke(ButtonResult.OK);
}
#region Prism Dialog 规范
public override void OnDialogClosed()
{
_eventAggregator.GetEvent().Publish(false);
}
public override void OnDialogOpened(IDialogParameters parameters)
{
_eventAggregator.GetEvent().Publish(true);
if (parameters.ContainsKey("Results"))
{
var list = parameters.GetValue>("Results");
Results.Clear();
foreach (var item in list)
Results.Add(item);
}
}
#endregion
}
///
/// 单条曲线的数学统计结果。
///
public class CurveStatisticsResult
{
/// 曲线名称
public string DisplayName { get; set; } = string.Empty;
/// 数据点数
public int PointCount { get; set; }
/// 最大值
public double Max { get; set; }
/// 最小值
public double Min { get; set; }
/// 平均值
public double Average { get; set; }
/// 线性回归斜率(单位/秒)
public double Slope { get; set; }
/// 梯形积分值(单位·秒)
public double Integral { get; set; }
public string MaxText => Max.ToString("G6");
public string MinText => Min.ToString("G6");
public string AverageText => Average.ToString("G6");
public string SlopeText => Slope.ToString("G6");
public string IntegralText => Integral.ToString("G6");
}
}