WeighterCsService.cs 5.3 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using FLY.Weight.Common;
using System.Collections.ObjectModel;

namespace FLY.Weight.UI.Client.UnitTests
{
    public class WeighterCsService
    {
        /// <summary>
        /// 称重其它附件
        /// </summary>
        public WeighterAccessory Accessory { get; } = new WeighterAccessory();
        /// <summary>
        /// 各层称重
        /// </summary>
        public ObservableCollection<WeighterC> Items { get; } = new ObservableCollection<WeighterC>();


    }
    public class UnitTests_Weights : WeighterCsService
    {
        public UnitTests_Weights()
        {
            Random random = new Random();

            Items.Add(new FLY.Weight.Common.WeighterC("A", 0, 6)
            {
                CurrentFlow = 150,
                FlowSetting = 140,
                CumulativeProduction = 1000,
                BinWeight = 15,
                MixBucketWeight = 4
            });
            Items.Add(new FLY.Weight.Common.WeighterC("B", 1, 2)
            {
                CurrentFlow = 100,
                FlowSetting = 100,
                CumulativeProduction = 1200,
                BinWeight = 10,
                MixBucketWeight = 4
            });
            Items.Add(new FLY.Weight.Common.WeighterC("C", 2, 0)
            {
                CurrentFlow = 50,
                FlowSetting = 50,
                CumulativeProduction = 500,
                BinWeight = 5,
                MixBucketWeight = 4
            });
            Items.Add(new FLY.Weight.Common.WeighterC("D", 3, 2)
            {
                CurrentFlow = 10,
                CumulativeProduction = 200,
                BinWeight = 1,
                MixBucketWeight = 4
            });
            Items.Add(new FLY.Weight.Common.WeighterC("E", 4, 6)
            {
                CurrentFlow = 10,
                CumulativeProduction = 100,
                BinWeight = 1,
                MixBucketWeight = 4
            });

            //Items.Add(new FLY.Weight.Common.WeighterC("F", 5, 2)
            //{
            //    CurrentFlow = 10,
            //    CumulativeProduction = 200,
            //    BinWeight = 1,
            //    MixBucketWeight = 4
            //});
            //Items.Add(new FLY.Weight.Common.WeighterC("G", 6, 6)
            //{
            //    CurrentFlow = 10,
            //    CumulativeProduction = 100,
            //    BinWeight = 1,
            //    MixBucketWeight = 4
            //});

            foreach (FLY.Weight.Common.WeighterC w in Items) {
                w.Color = WeighterColorDB.GetSelf(w.Index);
            }

            Accessory.TotalFlow = (UInt16)Items.Sum((w) => { return w.CurrentFlow; });
            Accessory.TotalProduction = (UInt16)Items.Sum((w) => { return w.CumulativeProduction; });
            Accessory.TotalFlowSetting = Accessory.TotalFlow;
            foreach (FLY.Weight.Common.WeighterC w in Items) {
                w.ScrewPDisp = (UInt16)(w.CurrentFlow * 100 / Accessory.TotalFlow);
                w.ScrewPSet = w.ScrewPDisp;
            }

            Accessory.WheelPerimeter = 378;
            Accessory.WheelPulse = 3000;
            Accessory.Density = 1;
            Accessory.RimCharge = 30;
            Accessory.Thickness = 80;
            Accessory.CurrentVelocity = 50.3f;
            Accessory.TotalFilmWidth = 2134;
            Accessory.RimWidth = 20;
            Accessory.ActFilmWidth = Accessory.TotalFilmWidth - Accessory.RimWidth * 2;
            Accessory.SetThickness = 79;
            Accessory.TargetVelocity = 50.1f;
            Accessory.ACurrentLen = 200;
            Accessory.ACurrent = 200;
            Accessory.ALast = 230;
            Accessory.BCurrentLen = 300;
            Accessory.BLast = 290;

            //Ingredients
            foreach (WeighterC w in Items)
            {
                if (w.IsSingle)
                    continue;
                for (int i = 0; i < w.Ingredients.Count(); i++)
                {
                    w.Ingredients[i].Color = WeighterColorDB.GetItem(w.Index, i);
                    w.Ingredients[i].MixDisp = 0.3f * (i + 1);
                    w.Ingredients[i].MixSet = 0.3f * (i + 1);
                    w.Ingredients[i].MixCum = (float)(10 * Math.Pow(i + 1, 2));
                }
                
                float t_mixdisp = w.Ingredients.Sum(i => i.MixDisp);
                float t_mixset = w.Ingredients.Sum(i => i.MixSet);
                float t_mixcum = w.Ingredients.Sum(i => i.MixCum);
                for (int i = 0; i < w.Ingredients.Count(); i++)
                {
                    w.Ingredients[i].MixPDisp = 100.0f * w.Ingredients[i].MixDisp / t_mixdisp;
                    w.Ingredients[i].MixPSet = 100.0f * w.Ingredients[i].MixSet / t_mixset;
                    w.Ingredients[i].MixCumPercent = 100.0f * w.Ingredients[i].MixCum / t_mixcum;

                    

                    w.Ingredients[i].FeedingDeviation = 0.3f * (i + 1);
                    w.Ingredients[i].FeedSet = 0.3f * (i + 1);
                    w.Ingredients[i].InitTime = 0;
                    w.Ingredients[i].MinTime = 10;
                    w.Ingredients[i].StableTime = 20;

                }
                w.Ingredients[random.Next(w.Ingredients.Count() - 1)].MixLight = true;

            }
        }
    }
}