using FLY.Thick.FilmCasting.Server.Model;
using Misc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.Thick.FilmCasting.UI.Server
{
    public class ScanGraphVmUt: ScanGraphVm
    {

        public ScanGraphVmUt()
        {

            SimuData();
        }
        void SimuData()
        {
            picHistory = new PicHistory();
            picHistory.IsPercent = true;
            picHistory.YRangePercent = 3;
            picHistory.XStep = 10;

            profileParam = new Common.FilmCastingProfileParam();
            profileParam.ScanRange = new RangeStruct(10, 110);
            profileParam.DataRange = new RangeStruct(30, 90);
            profileParam.Target = 150;
            profileParam.TolerancePercent = 0.02;
            profileParam.PName = "hahahah";
            profileParam.Batch = "00-01212";
            profileParam.Number = "13";

            #region 数据


            double target = profileParam.Target;
            double tolerance = target * profileParam.TolerancePercent;
            double yrangepercent = picHistory.YRangePercent;

            int nbolts = 120;
            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;
            }

            for (int i = 0; i < profileParam.DataRange.Begin; i++)
            {
                datas[i] = double.NaN;
            }
            for (int i = profileParam.DataRange.End; i < nbolts; i++)
            {
                datas[i] = double.NaN;
            }
            scanData = new Lc_ScanData
            {
                ID = 1234456,
                FilmWidth = (int)(profileParam.DataRange.Width * 25.4 * (1 - 0.03)),
                FilmVelocity = 40.1,
                FilmPosition = 800.4,
                Time = DateTime.Now.AddSeconds(-30),
                EndTime = DateTime.Now,
                K = 1,
                B = 0,
                SampleADs = new int[] { 50300,-1,-1},
                Thicks = datas,
                Target = profileParam.Target,
                TolerancePercent = profileParam.TolerancePercent,
                
            };

            #endregion



            #region 界面数据
            UpdateTitle();
            UpdateValue(
                new IService.Pack_GetFrameReponse()
                {
                    scanData = scanData,
                    Request = new IService.Pack_GetFrameRequest
                    {
                        Mix = 2,
                    }
                }, true);

            #endregion
        }
    }
}
