using FLY.Thick.FilmCasting.IService;
using LiveCharts;
using LiveCharts.Configurations;
using Misc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Media;

namespace FLY.Thick.FilmCasting.UI.UiModule
{
    public class TrendGraphVmUt : TrendGraphVm
    {
        public TrendGraphVmUt()
        {
            #region 数据
            double target = 150;

            double tolerancePercent = 0.05;
            double yRangePercent = 3;
            int len = Len;
            DateTime startTime = DateTime.Now;
            TimeSpan tsInterval = TimeSpan.FromSeconds(30);
            DateTime time = startTime;
            int id = 312456;
            Random random = new Random();

            List<TrendValue> tvs = new List<TrendValue>();
            for (int i = 0; i < len; i++, time += tsInterval)
            {
                TrendValue tv = new TrendValue();
                tv.Time = time;
                tv.Value = target + (random.NextDouble() - 0.5) * target * tolerancePercent * 0.5;
                tv.Sigma = (Math.Sin(i * Math.PI / len) * 3) * target * tolerancePercent * random.NextDouble();

                tvs.Add(tv);
                
            }
            Values.AddRange(tvs);

            #endregion

            profileParam = new Common.FilmCastingProfileParam()
            {
                ScanRange = new RangeStruct(10, 110),
                DataRange = new RangeStruct(30, 90),
                Target = target,
                TolerancePercent = tolerancePercent
            };
            graphparam = new TrendGraphItemParam()
            {
                YRangePercent = yRangePercent,
                Mix = 2
            };

            #region 界面数据
            UpdateX();

            Mix = 2;
            BeginTime = Values.First().Time;
            EndTime = Values.Last().Time;
            Id = id;

            UpdateAverage();
            UpdateY();
            #endregion
        }
    }
}
