ViewModel.cs 5.1 KB

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