ViewModel.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using NEIntelligentControl2.Models.Datas;
  2. using OxyPlot;
  3. using OxyPlot.Axes;
  4. using OxyPlot.Series;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace NEIntelligentControl2.Models.AGC
  11. {
  12. /// <summary>
  13. /// AGC曲线模型
  14. /// </summary>
  15. public class ViewModel : PlotModel
  16. {
  17. private List<TsData> _ActPower; // 实发有功数据
  18. public List<TsData> ActPower { get => _ActPower; }
  19. private List<TsData> _PowerSet;// 有功设定数据
  20. public List<TsData> PowerSet { get => _PowerSet; }
  21. private LineSeries ls1;
  22. private LineSeries ls2;
  23. public DateTimeAxis AxisX;
  24. public ViewModel()
  25. {
  26. this.PlotAreaBorderThickness = new OxyThickness(0);
  27. this.Legends.Add(new OxyPlot.Legends.Legend()
  28. {
  29. Key = "power",
  30. LegendPosition = OxyPlot.Legends.LegendPosition.BottomCenter,
  31. LegendPlacement = OxyPlot.Legends.LegendPlacement.Outside,
  32. LegendOrientation = OxyPlot.Legends.LegendOrientation.Horizontal,
  33. LegendTextColor = OxyColor.Parse("#FF000000"),
  34. //LegendFontSize = 10
  35. });
  36. var dta2 = new LinearAxis() { Position = AxisPosition.Left };
  37. dta2.MinorTicklineColor = OxyColors.Transparent;
  38. dta2.AxislineColor = OxyColors.Transparent;
  39. dta2.TickStyle = TickStyle.None;
  40. //dta2.MajorStep = 20;
  41. dta2.IntervalLength = 20;
  42. dta2.IsZoomEnabled = false;
  43. dta2.IsPanEnabled = false;
  44. dta2.TextColor = OxyColor.Parse("#FF000000");
  45. this.Axes.Add(dta2);
  46. AxisX = new DateTimeAxis { Position = AxisPosition.Bottom, StringFormat = "HH:mm" };
  47. AxisX.MinorTicklineColor = OxyColors.Transparent;
  48. AxisX.TickStyle = TickStyle.None;
  49. AxisX.IsZoomEnabled = false;
  50. AxisX.IsPanEnabled = false;
  51. //_AxisX.IntervalLength = 45;
  52. AxisX.TextColor = OxyColor.Parse("#FF000000");
  53. this.Axes.Add(AxisX);
  54. ls1 = new LineSeries() { Title = "实发有功", Color = OxyColor.Parse("#FFF4A460"), StrokeThickness = 1.5 };
  55. ls1.LegendKey = "power";
  56. ls2 = new LineSeries() { Title = "有功设定", Color = OxyColor.Parse("#FF31B9FB"), StrokeThickness = 1.5 };
  57. ls2.LegendKey = "power";
  58. Series.Add(ls1);
  59. Series.Add(ls2);
  60. }
  61. /// <summary>
  62. /// AGC曲线模型
  63. /// </summary>
  64. /// <param name="ap">实发有功</param>
  65. /// <param name="ps">有功设定</param>
  66. public ViewModel(List<TsData> ap, List<TsData> ps) : this()
  67. {
  68. _PowerSet = ps;
  69. AddData(ls2, ps);
  70. _ActPower = ap;
  71. AddData(ls1, ap);
  72. }
  73. internal void SetValueNow(TagInfo arg1, List<TsData> arg2)
  74. {
  75. if (arg2 == null || arg2.Count < 2) return;
  76. if (arg1.Type == TagType.PowerSet)
  77. {
  78. _PowerSet = arg2;
  79. AddData(ls2, arg2);
  80. }
  81. else
  82. {
  83. _ActPower = arg2;
  84. AddData(ls1, arg2);
  85. }
  86. var dt = DateTime.Now;
  87. AxisX.AbsoluteMinimum = DateTimeAxis.ToDouble(dt.AddHours(-8));
  88. AxisX.AbsoluteMaximum = DateTimeAxis.ToDouble(dt);
  89. }
  90. internal void SetValue(TagInfo arg1, List<TsData> arg2)
  91. {
  92. if (arg2 == null || arg2.Count < 2) return;
  93. if (arg1.Type == TagType.PowerSet)
  94. {
  95. _PowerSet = arg2;
  96. AddData(ls2, arg2);
  97. }
  98. else
  99. {
  100. _ActPower = arg2;
  101. AddData(ls1, arg2);
  102. }
  103. var dts = arg2[0].Ts.GetLongDateTime();
  104. var dte = arg2[arg2.Count - 1].Ts.GetLongDateTime();
  105. AxisX.AbsoluteMinimum = DateTimeAxis.ToDouble(dts);
  106. AxisX.AbsoluteMaximum = DateTimeAxis.ToDouble(dte);
  107. }
  108. private void AddData(LineSeries ls, List<TsData> vs)
  109. {
  110. ls.Points.Clear();
  111. if (vs == null) return;
  112. foreach(var v in vs)
  113. {
  114. DataPoint dp = new DataPoint(DateTimeAxis.ToDouble(v.Ts.GetLongDateTime()), Math.Round(v.Value, 2));
  115. ls.Points.Add(dp);
  116. }
  117. }
  118. }
  119. }