using GalaSoft.MvvmLight.Command;
using LiveCharts;
using LiveCharts.Configurations;
using Misc;
using System;
using System.ComponentModel;
using System.Linq;

namespace FLY.FilmCasting.AutoDie.UI.Client
{
    public class UcThickHeatVmUt : UcThickHeatVm
    {

        public UcThickHeatVmUt() 
        {
            SimuData();
        }

        /// <summary>
        /// 模拟数据
        /// </summary>
        void SimuData()
        {
            double target = 150;
            double tolerance = target * 0.02;
            int nbolts = 88;
            double[] datas = new double[nbolts];
            Random random = new Random();
            for (int i = 0; i < nbolts; i++)
            {
                datas[i] = (Math.Sin(i * Math.PI / nbolts) * 3) * tolerance + target + (random.NextDouble() - 0.5) * 1 - 6;
            }

            int kp = 3;

            int[] heats = new int[nbolts];
            for (int i = 0; i < nbolts; i++)
            {
                heats[i] = (int)((Math.Sin(i * Math.PI / nbolts)) * 20 + 30 + (random.NextDouble() - 0.5) * 5);
            }


            XMax = nbolts + 1;

            Title = "记录1";
            Number = -1;
            Id = 12313122;
            LastId = 321211;
            Time = DateTime.Now;
            EndTime = Time - TimeSpan.FromMinutes(6.5);

            ScanDataId = 1121;
            FilmWidth = 2130;
            FilmVelocity = 30.2;


            Average = datas.AverageNoNull();
            Sigma2Percent = datas.Sigma() / Average * 2;

            double[] thickPercents = new double[datas.Count()];

            for (int i = 0; i < datas.Count(); i++)
            {
                var data = datas[i];
                var percent = 0.0;
                if (!double.IsNaN(data))
                {
                    percent = (data - Average) / Average * 100 * Kp;
                }
                thickPercents[i] = percent;
            }
            ThickPercents.Clear();
            ThickPercents.AddRange(thickPercents);

            IsStable = true;
            HTime = Time - TimeSpan.FromMinutes(20);

            Heats.Clear();
            Heats.AddRange(heats);

            IsVaild = true;
        }


        
    
    }
}
