public void ClearFunctionThatIsBoundToDecorator()
        {
            IFunction function = new Function("time series");

            function.Arguments.Add(new Variable<DateTime>("time"));
            function.Components.Add(new Variable<double>("water_discharge"));

            // set initial values
            DateTime time1 = DateTime.Now;
            DateTime time2 = time1.AddMinutes(1);
            DateTime time3 = time2.AddMinutes(1);
            function[time1] = 0.0;
            function[time2] = 1.0;
            function[time3] = 2.0;

            ILineChartSeries lineChartSeries = ChartSeriesFactory.CreateLineSeries();

            lineChartSeries.XValuesDataMember = function.Arguments[0].DisplayName;
            lineChartSeries.YValuesDataMember = function.Components[0].DisplayName;

            var control = new Control();
            WindowsFormsTestHelper.Show(control);

            var functionBindingList = new FunctionBindingList(function) { SynchronizeInvoke = control };
            lineChartSeries.DataSource = functionBindingList;
            
            function.Clear();

            while(functionBindingList.IsProcessing)
            {
                Application.DoEvents();
            }

        }
 /// <summary>
 /// Fills gridvalues function with profiledata based on profileline over the grid
 /// </summary>
 /// <param name="function"></param>
 /// <param name="grid"></param>
 /// <param name="polyline"></param>
 public static void UpdateGridValues(Function function, IRegularGridCoverage grid, ILineString polyline)
 {
     function.Clear();
     double offset = 0;
     double step = polyline.Length / 100;
     foreach (ICoordinate coordinate in GetGridProfileCoordinates(polyline, step))
     {
         function[offset] = grid.Evaluate(coordinate);
         offset += step;
     }
 }
 public void CheckFunctionValuesChangedConsistency()
 {
     //assert we only get a FunctionValuesChanged event when the function is consistent.
     IFunction func = new Function();
     IVariable x = new Variable<int>("x");
     IVariable y = new Variable<int>("y");
     func.Arguments.Add(x);
     func.Components.Add(y);
     func[0] = 2;
     func.Store.FunctionValuesChanged += delegate
                                             {
                                                 Assert.IsTrue(func.Components[0].Values.Count == func.Arguments[0].Values.Count);
                                             };
     func.Clear();
 }
示例#4
0
        public void Clear()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");

            IFunction f = new Function();
            f.Arguments.Add(x);
            f.Components.Add(y);

            f.SetValues(new[] {100.0, 200.0, 300.0}, new VariableValueFilter<double>(x, new[] {1.0, 2.0, 3.0}));

            IList values = f.GetValues();
            Assert.AreEqual(3, values.Count);

            f.Clear();
            Assert.AreEqual(0, values.Count);
        }
        public void AddManyFunctionValuesWithBindingListShouldBeFast()
        {
            var f = new Function
                        {
                            Arguments = {new Variable<double>("x")}, 
                            Components = {new Variable<double>("y")}
                        };

            var values = Enumerable.Range(0, 1000).Select(i => (double)i);

            // first time is slower so we add/clear values a few times first
            f.SetValues(values, new VariableValueFilter<double>(f.Arguments[0], values));
            f.Clear();
            f.SetValues(values, new VariableValueFilter<double>(f.Arguments[0], values));
            f.Clear();

            // measure overhead (add values to function)
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            AddValuesWithoutBindingList(f, values);
            stopwatch.Stop();

            var overhead = stopwatch.ElapsedMilliseconds;
            log.DebugFormat("Added 1000 values to function in {0} ms", overhead);

            f.Clear();

            // add values with FunctionBindingList
            new FunctionBindingList(f);

            stopwatch.Reset();
            stopwatch.Start();
            AddValuesWithBindingList(f, values);
            stopwatch.Stop();

            log.DebugFormat("Added 1000 values to function wrapped with a binding list in {0} ms, {1}x slower", stopwatch.ElapsedMilliseconds, (stopwatch.ElapsedMilliseconds / (double)overhead));

            (stopwatch.ElapsedMilliseconds - overhead)
                .Should("Updating binding list should be fast").Be.LessThan(50);

            (stopwatch.ElapsedMilliseconds / (double)overhead)
                .Should("Setting values to function with function binding list should be almost as fast as without it")
                    .Be.LessThan(4);
        }
        public void ClearSourceFunctionShouldClearFilteredBindingList()
        {
            IFunction function = new Function
            {
                Arguments = { new Variable<int>("x")},
                Components = { new Variable<int>("f") }
            };

            function[1] = 1;
            function[2] = 4;

            var filteredFunction = function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] { 1 }));

            IFunctionBindingList functionBindingList = new FunctionBindingList { Function = filteredFunction };

            functionBindingList.Count
                .Should().Be.EqualTo(1);

            function.Clear();

            functionBindingList.Count
                .Should().Be.EqualTo(0);
        }
        public void ClearSourceFunctionShouldClearBindingList()
        {
            IFunction function = new Function
            {
                Arguments = { new Variable<int>("x") },
                Components = { new Variable<int>("f") }
            };

            function[1] = 1;
            function[2] = 4;

            var functionBindingList = new FunctionBindingList {Function = function};

            functionBindingList.Count
                .Should().Be.EqualTo(2);

            function.Clear();

            // wait until binding list is actually cleared.
            WaitUntilLastOperationIsFinished(functionBindingList);

            functionBindingList.Count
                .Should().Be.EqualTo(0);
        }
示例#8
0
        public void ClearFunction_ShouldNotClearAttributes()
        {
            // setup
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");
            IFunction f = new Function();
            f.Arguments.Add(x);
            f.Components.Add(y);
            string kie = "kie";
            string expected = "veljoe";
            f.Attributes[kie] = expected;
            f.Components[0].Attributes[kie] = expected;

            f.SetValues(new[] { 100.0, 200.0, 300.0 }, new VariableValueFilter<double>(x, new[] { 1.0, 2.0, 3.0 }));

            // call
            f.Clear();

            // check
            Assert.AreEqual(0, f.GetValues().Count);
            var funcVal = f.Attributes[kie];
            Assert.AreEqual(expected,funcVal);
            var val = f.Components[0].Attributes[kie];
            Assert.AreEqual(expected,val);
        }
示例#9
0
        /// <summary>
        /// Fills gridvalues function with profiledata based on profileline over the grid
        /// </summary>
        /// <param name="function"></param>
        /// <param name="coverage"></param>
        /// <param name="polyline"></param>
        /// <param name="resolution">Defines the sample resolution along <paramref name="polyline"/> (each resolution step a sample).
        /// Null will cause 101 samples to be take along the line uniformly.</param>
        /// <exception cref="ArgumentException">When <paramref name="resolution"/> is 0.0 or less.</exception> 
        public static void UpdateProfileFunctionValues(Function function, ICoverage coverage, ILineString polyline, DateTime? time, double? resolution = null)
        {
            // when coverage is empty (has no times), we cannot call Evaluate below...
            if (time != null && time.Equals(default(DateTime))) return;

            function.Clear();
            double offset = 0;
            double step = resolution ?? polyline.Length / 100;
            var gridProfileCoordinates = GetGridProfileCoordinates(polyline, step).ToArray();
            foreach (ICoordinate coordinate in gridProfileCoordinates)
            {
                var value = time != null ? coverage.Evaluate(coordinate, time.Value) : coverage.Evaluate(coordinate);
                if (value == null)
                {
                    offset += step;
                    continue;
                }
                function[offset] = value;
                offset += step;
            }
        }