WeighterCsService.cs 4.91 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
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()
        {
            Items.Add(new FLY.Weight.Common.WeighterC("A",5)
            {
                CurrentFlow = 150,
                FlowSetting = 140,
                CumulativeProduction = 1000,
                BinWeight = 15,
                MixBucketWeight = 4
            });
            Items.Add(new FLY.Weight.Common.WeighterC("B", 3)
            {
                CurrentFlow = 100,
                FlowSetting = 100,
                CumulativeProduction = 1200,
                BinWeight = 10,
                MixBucketWeight = 4
            });
            Items.Add(new FLY.Weight.Common.WeighterC("C", 4)
            {
                CurrentFlow = 50,
                FlowSetting = 50,
                CumulativeProduction = 500,
                BinWeight = 5,
                MixBucketWeight = 4
            });
            Items.Add(new FLY.Weight.Common.WeighterC("D", 3)
            {
                CurrentFlow = 10,
                CumulativeProduction = 200,
                BinWeight = 1,
                MixBucketWeight = 4
            });
            Items.Add(new FLY.Weight.Common.WeighterC("E", 5)
            {
                CurrentFlow = 10,
                CumulativeProduction = 100,
                BinWeight = 1,
                MixBucketWeight = 4
            });
            foreach (FLY.Weight.Common.WeighterC w in Items) {
                w.Color = WeighterColorDB.GetSelf(w.Number);
            }

            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)
            {
                for (int i = 0; i < w.Ingredients.Count(); i++)
                {
                    w.Ingredients[i].Color = WeighterColorDB.GetItem(w.Number, 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;
                }
                Random r = new Random();
                w.Ingredients[r.Next(w.Ingredients.Count() - 1)].MixLight = true;
            }

            //IngredientParams
            foreach (WeighterC w in Items)
            {
                for (int i = 0; i < w.IngredientParams.Count(); i++)
                {
                    w.IngredientParams[i].FeedingDeviation = 0.3f * (i + 1);
                    w.IngredientParams[i].FeedSet = 0.3f * (i + 1);
                    w.IngredientParams[i].InitTime = 0;
                    w.IngredientParams[i].MinTime = 10;
                    w.IngredientParams[i].StableTime = 20;
                }
            }
        }
    }
}