PgBlowingExtVmUt.cs 8.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
using GalaSoft.MvvmLight.Command;
using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
潘栩锋's avatar
潘栩锋 committed
11
using System.Windows.Media;
12

13
namespace FLY.Thick.Blowing.UI
14
{
15
    public class PgBlowingExtVmUt : PgBlowingExtVm
16 17 18 19 20 21
    {
        public event PropertyChangedEventHandler PropertyChanged;


        public PgBlowingExtVmUt()
        {
22 23
            Cfl = new CalFilmLenUt();

24 25 26 27
            init_virtualdata();
        }


潘栩锋's avatar
潘栩锋 committed
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
        /// <summary>
        /// 产生虚拟数据
        /// </summary>
        void init_virtualdata()
        {
            #region 虚拟数据
            int[] thicks = new int[]{
                3518    ,
                3484    ,
                3634    ,
                3620    ,
                3579    ,
                3625    ,
                3635    ,
                3638    ,
                3635    ,
                3606    ,
                3611    ,
                3603    ,
                3590    ,
                3631    ,
                3646    ,
                3647    ,
                3710    ,
                3705    ,
                3607    ,
                3720    ,
                3680    ,
                3637    ,
                3659    ,
                3703    ,
                3860    ,
                3720    ,
                3615    ,
                3810    ,
                3772    ,
                3666    ,
                3614    ,
                3627    ,
                3618    ,
                3502    ,
                3575    ,
                3583    ,
                3615    ,
                3680    ,
                3730    ,
                3840    ,
                3927    ,
                3946    ,
                3923    ,
                3841    ,
                3797    ,
                3865    ,
                3810    ,
                3711    ,
                3754    ,
                3705    ,
                3723    ,
                3699    ,
                3723    ,
                3801    ,
                3786    ,
                3798    ,
                3907    ,
                3945    ,
                3828    ,
                3860    ,
                3846    ,
                3903    ,
                3871    ,
                3844    ,
                3759    ,
                3816    ,
                3886    ,
                3815    ,
                3789    ,
                3876    ,
                3942    ,
                3854    ,
                3842    ,
                3921    ,
                3846    ,
                3835    ,
                3886    ,
                3881    ,
                3820    ,
                3787    ,
                3730    ,
                3617    ,
                3650    ,
                3610    ,
                3536    ,
                3545    ,
                3564    ,
                3584    ,
                3580    ,
                3572    ,
                3571    ,
                3579    ,
                3620    ,
                3634    ,
                3484    ,
                3518    ,
                };
            //辊周长 m
            double RollPerimeter = 0.314;
            //线速度 m/min
            double FilmVelocity = 20;
            //旋转周期
            TimeSpan RInterval = TimeSpan.FromMinutes(6.1);
            //速度震荡周期 m
            double FV_Range = 2;
            TimeSpan DataLen = TimeSpan.FromMinutes(30);

            DateTime dt_begin = DateTime.Now;
            DateTime dt_end = dt_begin + DataLen;

            List<TimeValue> vList = new List<TimeValue>();
            List<TimeValue> tList = new List<TimeValue>();
            List<TimeValue> lList = new List<TimeValue>();

            for (TimeSpan ts = TimeSpan.Zero; ts < DataLen; ts += TimeSpan.FromSeconds(1))
            {
                DateTime dt = dt_begin + ts;
                double min = ts.TotalMinutes;

                //速度以1/2旋转周期变化
                double v = FilmVelocity + Math.Sin(Math.PI * 2 * min / (RInterval.TotalMinutes / 2)) * FV_Range;

                vList.Add(new TimeValue() { Time = dt, Value = v });

                int n = ((int)(min / RInterval.TotalMinutes)) % 2;

                double m = min % RInterval.TotalMinutes;
                int idx = (int)(thicks.Count() * m / RInterval.TotalMinutes);
                if (idx < 0) idx = 0;
                else if (idx > thicks.Count()) idx = thicks.Count() - 1;

                double thick;

                if (n == 0)
潘栩锋's avatar
潘栩锋 committed
170
                    thick = thicks[idx] / 100.0;
171
                else
潘栩锋's avatar
潘栩锋 committed
172
                    thick = thicks[thicks.Count() - 1 - idx] / 100.0;
173 174 175 176 177


                tList.Add(new TimeValue()
                {
                    Time = dt,
潘栩锋's avatar
潘栩锋 committed
178 179
                    Value = thick
                }) ;
180 181 182

                if (lList.Count() == 0)
                {
潘栩锋's avatar
潘栩锋 committed
183
                    lList.Add(new TimeValue() { Time = dt_begin + RInterval, Value = thick });
184 185 186
                }
                else if (dt >= lList.Last().Time)
                {
潘栩锋's avatar
潘栩锋 committed
187
                    lList.Add(new TimeValue() { Time = lList.Last().Time + RInterval, Value = thick });
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
                }
            }

            List<TimeValue> fList = new List<TimeValue>();
            double sum = 0;
            double avg = vList.Average(tv => tv.Value);

            foreach (var tv in vList)
            {
                sum += (tv.Value - avg) * TimeSpan.FromSeconds(1).TotalMinutes;

                fList.Add(new TimeValue() { Time = tv.Time, Value = sum });
            }
            {
                double min = fList.Min(tv => tv.Value);
                foreach (var tv in vList)
                {
                    tv.Value -= min;
                }
            }

            List<double> setFilmLength = new List<double>();
            foreach (var tv in fList)
            {
                if (tv.Time >= lList[0].Time && tv.Time <= lList[1].Time)
                {
                    setFilmLength.Add(tv.Value);
                }
                else if (tv.Time > lList[1].Time)
                {
                    break;
                }
            }
            Random r = new Random();
            List<double> currFilmLength = new List<double>();
            foreach (var f in setFilmLength)
            {
                currFilmLength.Add(f + r.NextDouble() - 0.5);
            }


            List<List<double>> frames = new List<List<double>>();
            for (int i = 0; i < lList.Count() - 1; i++)
            {
                List<double> frame = new List<double>();
                frame.AddRange(thicks.Select(t => (t + (r.NextDouble() - 0.5) * t * 2 / 100) / 100.0));
                frames.Add(frame);
            }
            #endregion



潘栩锋's avatar
潘栩锋 committed
240
            //            LimitValues.AddRange(lList);
241

潘栩锋's avatar
潘栩锋 committed
242
            for (int i = 0; i < lList.Count(); i++)
243 244
            {

潘栩锋's avatar
潘栩锋 committed
245 246 247 248 249 250 251 252 253 254 255 256 257 258
                var value = lList[i];
                var axisSection = new AxisSection()
                {
                    StrokeThickness = 1,
                    DataLabel = true,
                    DisableAnimations = true,
                    DataLabelForeground = new SolidColorBrush(Colors.White),
                    Opacity = 1,
                    Stroke = new SolidColorBrush(Colors.Orange),
                };
                if (value.Value == 1)
                    axisSection.Stroke = new SolidColorBrush(Colors.DarkBlue);
                axisSection.Value = value.Time.Ticks;
                LimitSections.Add(axisSection);
259 260 261
            }


潘栩锋's avatar
潘栩锋 committed
262 263 264 265 266
            VelocityValues.AddRange(GetLimitedList(vList, 100));
            ThicknessValues.AddRange(GetLimitedList(tList, 100));
            FilmLength3DValues.AddRange(GetLimitedList(fList, 100));
            CurrFilmLength3D.AddRange(GetLimitedList(currFilmLength, 100));
            NewFilmLength3D.AddRange(GetLimitedList(setFilmLength, 100));
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283

            for (int i = 0; i < frames.Count(); i++)
            {
                var frame = frames[i];
                FrameSeries.Add(
                    new LineSeries()
                    {
                        Title = i.ToString(),
                        Values = new ChartValues<double>(frame),
                        LineSmoothness = 1,
                        StrokeThickness = 3,
                        PointGeometrySize = 0
                    });
            }
        }
    }

284
    public class CalFilmLenUt : CalFilmLen
285
    {
286 287 288 289 290 291
        public CalFilmLenUt()
        {
            IsCanDownload = true;
            Msg = "下载中";
            IsDataReady = true;
        }
292 293
    }
}