示例#1
0
        static void Main(string[] args)
        {
            string outFile = @"c:\temp\losses_large_streamed_out";

            var executionDataflowBlockOptionsSingle = new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 1
            };
            var executionDataflowBlockOptions = new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 10
            };

            var roundCount = 1000000;

            var dataReader = new DataReaderBlock(DataFormat.Protobuf, roundCount);
            var dataWriter = new DataWriterBlock(outFile, DataFormat.Protobuf, roundCount, executionDataflowBlockOptionsSingle);
            var limiter    = new LimitBlock(300000, executionDataflowBlockOptions);
            var scaler     = new ScaleBlock(0.9m, executionDataflowBlockOptions);
            var risk       = new RiskMeasuresBlock(executionDataflowBlockOptionsSingle);
            var nullTarget = DataflowBlock.NullTarget <Trial>();

            dataReader
            .Then(limiter)
            .Then(scaler)
            .Then(risk)
            .Then(dataWriter)
            .Then(nullTarget);


            dataReader.InputBlock.Post(@"c:\temp\losses_large_streamed_in1");

            var calculationStartDate = DateTime.UtcNow;

            dataReader.InputBlock.Complete();

            while (!dataWriter.GetOutput().Completion.IsCompleted)
            {
                var totalTimeElapsed = Math.Round((DateTime.UtcNow - calculationStartDate).TotalSeconds, 2);
                var calculatedTrials = risk.GetProcessedItemsCount();
                var percentComplete  = (float)Math.Round(calculatedTrials / (float)roundCount * 100, 2);

                Console.WriteLine($"Elapsed: {totalTimeElapsed}s, {calculatedTrials}/{roundCount} ({percentComplete}%)");

                Task[] tasksToWaitFor = { Task.Delay(1000), dataWriter.GetOutput().Completion };
                Task.WaitAny(tasksToWaitFor);
            }
            Console.WriteLine("");
            var res = risk.GetCalculationResult();

            Console.WriteLine(res.ToString());

            Console.ReadKey();
        }
		protected override void DoStateTransition(Selectable.SelectionState state, bool instant) {
			
			float scale;
			float alpha;
			Color color;
			Sprite newSprite;
			string triggername;

			switch (state) {

				case Selectable.SelectionState.Normal:
					scale = this.scale.normalScale;
					alpha = this.alpha.normalAlpha;
					color = this.colors.normalColor;
					newSprite = null;
					triggername = this.animationTriggers.normalTrigger;
				break;
				case Selectable.SelectionState.Highlighted:
					scale = this.scale.highlightedScale;
					alpha = this.alpha.highlightedAlpha;
					color = this.colors.highlightedColor;
					newSprite = this.spriteState.highlightedSprite;
					triggername = this.animationTriggers.highlightedTrigger;
				break;
				case Selectable.SelectionState.Pressed:
					scale = this.scale.pressedScale;
					alpha = this.alpha.pressedAlpha;
					color = this.colors.pressedColor;
					newSprite = this.spriteState.pressedSprite;
					triggername = this.animationTriggers.pressedTrigger;
				break;
				case Selectable.SelectionState.Disabled:
					scale = this.scale.disabledScale;
					alpha = this.alpha.disabledAlpha;
					color = this.colors.disabledColor;
					newSprite = this.spriteState.disabledSprite;
					triggername = this.animationTriggers.disabledTrigger;
				break;
				default:
					scale = 0f;
					alpha = 0f;
					color = Color.black;
					newSprite = null;
					triggername = string.Empty;
				break;

			}

			if (base.gameObject.activeInHierarchy == true) {
				
				if ((this.transitionExtended & Transition.Scale) != 0) {
					
					this.StartScaleTween(scale * this.scale.scaleMultiplier, instant);
					
				}
				
				if ((this.transitionExtended & Transition.CanvasGroupAlpha) != 0) {
					
					this.StartAlphaTween(alpha * this.alpha.alphaMultiplier, instant);
					
				}
				
				if ((this.transitionExtended & Transition.ColorTint) != 0) {
					
					this.StartColorTween(color * this.colors.colorMultiplier, instant);
					
				}
				
				if ((this.transitionExtended & Transition.SpriteSwap) != 0) {
					
					this.DoSpriteSwap(newSprite);
					
				}
				
				if ((this.transitionExtended & Transition.Animation) != 0) {
					
					this.TriggerAnimation(triggername);
					
				}

			}

		}
示例#3
0
        protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
        {
            float  scale;
            float  alpha;
            Color  color;
            Sprite newSprite;
            string triggername;

            if (this.interactable == false)
            {
                state = SelectionState.Disabled;
            }

            switch (state)
            {
            case Selectable.SelectionState.Normal:
                scale       = this.scale.normalScale;
                alpha       = this.alpha.normalAlpha;
                color       = this.colors.normalColor;
                newSprite   = null;
                triggername = this.animationTriggers.normalTrigger;
                break;

            case Selectable.SelectionState.Highlighted:
                scale       = this.scale.highlightedScale;
                alpha       = this.alpha.highlightedAlpha;
                color       = this.colors.highlightedColor;
                newSprite   = this.spriteState.highlightedSprite;
                triggername = this.animationTriggers.highlightedTrigger;
                break;

            case Selectable.SelectionState.Pressed:
                scale       = this.scale.pressedScale;
                alpha       = this.alpha.pressedAlpha;
                color       = this.colors.pressedColor;
                newSprite   = this.spriteState.pressedSprite;
                triggername = this.animationTriggers.pressedTrigger;
                break;

            case Selectable.SelectionState.Disabled:
                scale       = this.scale.disabledScale;
                alpha       = this.alpha.disabledAlpha;
                color       = this.colors.disabledColor;
                newSprite   = this.spriteState.disabledSprite;
                triggername = this.animationTriggers.disabledTrigger;
                break;

            default:
                scale       = 0f;
                alpha       = 0f;
                color       = Color.black;
                newSprite   = null;
                triggername = string.Empty;
                break;
            }

            //if (base.gameObject.activeInHierarchy == true) {

            if ((this.transitionExtended & Transition.Scale) != 0)
            {
                this.StartScaleTween(scale * this.scale.scaleMultiplier, instant);
            }

            if ((this.transitionExtended & Transition.CanvasGroupAlpha) != 0)
            {
                this.StartAlphaTween(alpha * this.alpha.alphaMultiplier, instant);
            }

            if ((this.transitionExtended & Transition.ColorTint) != 0)
            {
                this.StartColorTween(color * this.colors.colorMultiplier, instant);
            }

            if ((this.transitionExtended & Transition.SpriteSwap) != 0)
            {
                this.DoSpriteSwap(newSprite);
            }

            if ((this.transitionExtended & Transition.Animation) != 0)
            {
                this.TriggerAnimation(triggername);
            }

            if ((this.transitionExtended & Transition.TargetGraphics) != 0)
            {
                this.StartColorTweenGraphics(state, instant);
            }

            //}
        }
示例#4
0
        public void TestScaleBlockExecute()
        {
            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var scaleBlock = new ScaleBlock
            {
                TimeScalingFactor      = 2,
                AmplitudeScalingFactor = 0.5
            };

            scaleBlock.Execute();

            signalBlock.OutputNodes[0].ConnectTo(scaleBlock.InputNodes[0]);
            Assert.IsNotNull(scaleBlock.Name);
            Assert.IsNotNull(scaleBlock.Description);
            Assert.IsNotNull(scaleBlock.ProcessingType);

            signalBlock.Execute();
            Assert.AreEqual("0.0 0.5 0.0 0.5 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual(0, scaleBlock.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(10, scaleBlock.OutputNodes[0].Object[0].Finish);

            scaleBlock.TimeScalingFactor = 1;
            signalBlock.Execute();
            Assert.AreEqual("0.0 0.5 0.0 0.5 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual("ScaleBlock", scaleBlock.GetAssemblyClassName());
            Assert.AreEqual(0, scaleBlock.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(5, scaleBlock.OutputNodes[0].Object[0].Finish);

            scaleBlock.AmplitudeScalingFactor = 1;
            signalBlock.Execute();
            Assert.AreEqual("0.0 1.0 0.0 1.0 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));

            scaleBlock.TimeScalingFactor = -1;
            Assert.AreEqual(0, scaleBlock.TimeScalingFactor);
            signalBlock.Execute();
            Assert.AreEqual("0.0 1.0 0.0 1.0 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));

            scaleBlock.AmplitudeScalingFactor = -1;
            Assert.AreEqual(0, scaleBlock.AmplitudeScalingFactor);
            signalBlock.Execute();
            Assert.AreEqual("0.0 0.0 0.0 0.0 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual(0, scaleBlock.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(5, scaleBlock.OutputNodes[0].Object[0].Finish);

            scaleBlock.AmplitudeScalingFactor = 5;
            scaleBlock.TimeScalingFactor      = 2;
            signalBlock.Execute();
            Assert.AreEqual("0.0 5.0 0.0 5.0 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual(0, scaleBlock.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(10, scaleBlock.OutputNodes[0].Object[0].Finish);

            var scaleBlock2 = (ScaleBlock)scaleBlock.Clone();

            scaleBlock2.AmplitudeScalingFactor = 3;
            scaleBlock2.TimeScalingFactor      = 2;
            scaleBlock.OutputNodes[0].ConnectTo(scaleBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual("0.00 15.00 0.00 15.00 0.00", scaleBlock2.OutputNodes[0].Object.ToString(2));
            Assert.AreEqual(0, scaleBlock2.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(20, scaleBlock2.OutputNodes[0].Object[0].Finish);

            scaleBlock.Cascade = false;
            scaleBlock2        = (ScaleBlock)scaleBlock.Clone();
            scaleBlock.OutputNodes[0].ConnectTo(scaleBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual(0, scaleBlock2.OutputNodes[0].Object.Count);
        }