using LiveCharts;
using LiveCharts.Configurations;
using Misc;
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Media;

namespace FLY.FilmCasting.AutoDie.UI.Client.UiModule
{
    public class AutoDieGraphVmUt : AutoDieGraphVm
    {

        public AutoDieGraphVmUt()
        {


            #region 数据
            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;
            }
            double avg = datas.AverageNoNull();

            int kp = 3;

            double[] thickpercents = new double[nbolts];
            for (int i = 0; i < nbolts; i++)
            {
                thickpercents[i] = 100 * (datas[i] - avg) / avg;
            }
            int[] heatoffsets = new int[nbolts];
            for (int i = 0; i < nbolts; i++)
            {
                heatoffsets[i] = (int)(thickpercents[i] * kp);
            }

            int baseHeat = 20;

            int[] preheats = new int[nbolts];
            for (int i = 0; i < nbolts; i++)
            {
                preheats[i] = heatoffsets[i] + baseHeat;
            }

            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);
            }

            bool[] bads = new bool[nbolts];
            bads[20] = true;
            bads[21] = true;
            bads[70] = true;
            #endregion

            #region 界面数据
            Kp = kp;
            XMax = nbolts + 1;
            ThickPercents.AddRange(thickpercents);
            PreHeats.AddRange(preheats);
            Heats.AddRange(heats);
            HeatOffsets.AddRange(heatoffsets);
            Bads.AddRange(bads);

            #endregion

            LPress.Progress = 120;
        }

    }
}
