123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using NEIntelligentControl2.Models.Datas;
- using OxyPlot;
- using OxyPlot.Axes;
- using OxyPlot.Series;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace NEIntelligentControl2.Models.AGC
- {
- /// <summary>
- /// AGC曲线模型
- /// </summary>
- public class ViewModel : PlotModel
- {
- private List<TsData> _ActPower; // 实发有功数据
- public List<TsData> ActPower { get => _ActPower; }
- private List<TsData> _PowerSet;// 有功设定数据
- public List<TsData> PowerSet { get => _PowerSet; }
- private List<TsData> _IdeaPower;// 理论功率数据
- public List<TsData> IdeaPower { get => _IdeaPower; }
- private LineSeries ls1;
- private LineSeries ls2;
- private LineSeries ls3;
- public DateTimeAxis AxisX;
- public ViewModel()
- {
- this.PlotAreaBorderThickness = new OxyThickness(0);
- this.Legends.Add(new OxyPlot.Legends.Legend()
- {
- Key = "power",
- LegendPosition = OxyPlot.Legends.LegendPosition.BottomCenter,
- LegendPlacement = OxyPlot.Legends.LegendPlacement.Outside,
- LegendOrientation = OxyPlot.Legends.LegendOrientation.Horizontal,
- LegendTextColor = OxyColor.Parse("#FF000000"),
- //LegendFontSize = 10
- });
- var dta2 = new LinearAxis() { Position = AxisPosition.Left };
- dta2.MinorTicklineColor = OxyColors.Transparent;
- dta2.AxislineColor = OxyColors.Transparent;
- dta2.TickStyle = TickStyle.None;
- //dta2.MajorStep = 20;
- dta2.IntervalLength = 20;
- dta2.IsZoomEnabled = false;
- dta2.IsPanEnabled = false;
- dta2.TextColor = OxyColor.Parse("#FF000000");
- this.Axes.Add(dta2);
- AxisX = new DateTimeAxis { Position = AxisPosition.Bottom, StringFormat = "HH:mm" };
- AxisX.MinorTicklineColor = OxyColors.Transparent;
- AxisX.TickStyle = TickStyle.None;
- AxisX.IsZoomEnabled = false;
- AxisX.IsPanEnabled = false;
- //_AxisX.IntervalLength = 45;
- AxisX.TextColor = OxyColor.Parse("#FF000000");
- this.Axes.Add(AxisX);
- ls1 = new LineSeries() { Title = "实发有功", Color = OxyColor.Parse("#FFF4A460"), StrokeThickness = 1.5 };
- ls1.LegendKey = "power";
- ls2 = new LineSeries() { Title = "有功设定", Color = OxyColor.Parse("#FF31B9FB"), StrokeThickness = 1.5 };
- ls2.LegendKey = "power";
- ls3 = new LineSeries() { Title = "理论功率", Color = OxyColor.Parse("#FFED937F"), StrokeThickness = 1.5 };
- ls3.LegendKey = "power";
- Series.Add(ls1);
- Series.Add(ls2);
- Series.Add(ls3);
- }
- /// <summary>
- /// AGC曲线模型
- /// </summary>
- /// <param name="ap">实发有功</param>
- /// <param name="ps">有功设定</param>
- public ViewModel(List<TsData> ap, List<TsData> ps) : this()
- {
- _PowerSet = ps;
- AddData(ls2, ps);
- _ActPower = ap;
- AddData(ls1, ap);
- }
- internal void SetValueNow(TagInfo arg1, List<TsData> arg2)
- {
- if (arg2 == null || arg2.Count < 2) return;
- if (arg1.Type == TagType.PowerSet)
- {
- _PowerSet = arg2;
- AddData(ls2, arg2);
- }
- else if(arg1.Type == TagType.ActualPower)
- {
- _ActPower = arg2;
- AddData(ls1, arg2);
- }
- else
- {
- _IdeaPower = arg2;
- AddData(ls3, arg2);
- }
- var dt = DateTime.Now;
- AxisX.AbsoluteMinimum = DateTimeAxis.ToDouble(dt.AddHours(-8));
- AxisX.AbsoluteMaximum = DateTimeAxis.ToDouble(dt);
- }
- internal void SetValue(TagInfo arg1, List<TsData> arg2)
- {
- if (arg2 == null || arg2.Count < 2) return;
- if (arg1.Type == TagType.PowerSet)
- {
- _PowerSet = arg2;
- AddData(ls2, arg2);
- }
- else if (arg1.Type == TagType.ActualPower)
- {
- _ActPower = arg2;
- AddData(ls1, arg2);
- }
- else
- {
- _IdeaPower = arg2;
- AddData(ls3, arg2);
- }
- var dts = arg2[0].Ts.GetLongDateTime();
- var dte = arg2[arg2.Count - 1].Ts.GetLongDateTime();
- AxisX.AbsoluteMinimum = DateTimeAxis.ToDouble(dts);
- AxisX.AbsoluteMaximum = DateTimeAxis.ToDouble(dte);
- }
- private void AddData(LineSeries ls, List<TsData> vs)
- {
- ls.Points.Clear();
- if (vs == null) return;
- foreach(var v in vs)
- {
- DataPoint dp = new DataPoint(DateTimeAxis.ToDouble(v.Ts.GetLongDateTime()), Math.Round(v.Value, 2));
- ls.Points.Add(dp);
- }
- }
- }
- }
|