コード例 #1
0
        /*
         * [Test]
         * public void Sum_Function_Decimal()
         * {
         *      SumFunction<decimal> fn = new SumFunction<decimal>();
         *      decimal[] values = { 1.22m, 2.33m, 3.44m };
         *
         *      foreach (decimal value in values) fn.ProcessValue(fn.Result + value);
         *
         *      Assert.AreEqual(1.22m + 2.33m + 3.44m, fn.Result);
         * }
         *
         * [Test]
         * public void Sum_Function_String()
         * {
         *      SumFunction<string> fn = new SumFunction<string>();
         *      string[] values = { "this", " ", "is", " ", "a", " ", "test" };
         *
         *      foreach (string value in values) fn.ProcessValue(fn.Result + value);
         *
         *      Assert.AreEqual("this is a test", fn.Result);
         * }
         *
         * [Test]
         * public void Sum_Function_With_Initial_Value_Test()
         * {
         *      SumFunction<double> fn = new SumFunction<double>();
         *      fn.Initialize(11.2);
         *      double[] values = { 1.1, 2.1, 3.1, 4.1, 5.1 };
         *
         *      foreach (double value in values) fn.ProcessValue(fn.Result + value);
         *
         *      Assert.AreEqual(11.2 + 1.1 + 2.1 + 3.1 + 4.1 + 5.1, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }
         *
         * [Test]
         * public void Min_Function_Test()
         * {
         *      MinFunction<int> fn = new MinFunction<int>();
         *      int[] values = { 1, 2, 3, 4, 5 };
         *
         *      ProcessValues(fn, values);
         *      Assert.AreEqual(1, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }
         *
         * [Test]
         * public void Min_Function_With_Initial_Value_Test()
         * {
         *      MinFunction<int> fn = new MinFunction<int>();
         *      fn.Initialize(-2);
         *      int[] values = { 1, 2, 3, 4, 5 };
         *
         *      ProcessValues(fn, values);
         *      Assert.AreEqual(-2, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }
         *
         * [Test]
         * public void Max_Function_Test()
         * {
         *      MaxFunction<int> fn = new MaxFunction<int>();
         *      int[] values = { 1, 2, 3, 4, 5 };
         *
         *      ProcessValues(fn, values);
         *      Assert.AreEqual(5, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }
         *
         * [Test]
         * public void Max_Function_With_Initial_Value_Test()
         * {
         *      MaxFunction<int> fn = new MaxFunction<int>();
         *      fn.Initialize(22);
         *      int[] values = { 1, 2, 3, 4, 5 };
         *
         *      ProcessValues(fn, values);
         *      Assert.AreEqual(22, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }
         *
         * [Test]
         * public void Avg_Function_Test()
         * {
         *      AvgFunction fn = new AvgFunction();
         *      double[] values = { 1, 2, 3, 4, 5 };
         *
         *      ProcessValues(fn, values);
         *      Assert.AreEqual(3, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }
         *
         * [Test]
         * public void Avg_Function_Ignores_Initial_Value()
         * {
         *      AvgFunction fn = new AvgFunction();
         *      fn.Initialize(22);
         *      double[] values = { 1, 2, 3, 4, 5 };
         *
         *      ProcessValues(fn, values);
         *      Assert.AreEqual(3, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }
         *
         * [Test]
         * public void Count_Function_Test()
         * {
         *      CountFunction<int> fn = new CountFunction<int>();
         *      int[] values = { 10, 20, 30, 40, 50 };
         *
         *      ProcessValues(fn, values);
         *      Assert.AreEqual( 5, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }
         *
         * [Test]
         * public void Count_Function_Ignores_Initial_Value()
         * {
         *      CountFunction<int> fn = new CountFunction<int>();
         *      fn.Initialize(222);
         *      int[] values = { 10, 20, 30, 40, 50 };
         *
         *      ProcessValues(fn, values);
         *      Assert.AreEqual(5, fn.Result);
         *      Assert.AreEqual(5, fn.ProcessedItemCount);
         * }   */

        private void ProcessValues <T>(IAggregateFunction <T> fn, ICollection <T> values)
        {
            foreach (T value in values)
            {
                fn.ProcessValue(value);
            }
        }
コード例 #2
0
        /// <summary>
        /// Here you can assign an AggregateFunction to the specific column name.
        /// </summary>
        public void AddColumnAggregateFunction(string name, IAggregateFunction func)
        {
            if (_builder.ColumnNamesAggregateFunctions == null)
                _builder.ColumnNamesAggregateFunctions = new Dictionary<string, IAggregateFunction>();

            _builder.ColumnNamesAggregateFunctions.Add(name, func);
        }
コード例 #3
0
        /// <summary>
        /// Here you can assign an AggregateFunction to the specific data type.
        /// ColumnNamesAggregateFunctions has higher priority.
        /// </summary>
        public void AddTypeAggregateFunction(Type type, IAggregateFunction func)
        {
            if (_builder.TypesAggregateFunctions == null)
                _builder.TypesAggregateFunctions = new Dictionary<Type, IAggregateFunction>();

            _builder.TypesAggregateFunctions.Add(type, func);
        }
コード例 #4
0
        /// <summary>
        /// Constructs the statistic definition with the details
        /// </summary>
        /// <param name="name">The name</param>
        /// <param name="title">The title</param>
        /// <param name="query">The query</param>
        /// <param name="function">The aggregate function</param>
        /// <param name="action">The action (optional)</param>
        public StatisticDefinition
        (
            string name,
            string title,
            IQuery query,
            IAggregateFunction function,
            ReportAction action = null
        )
            : base(name, title)
        {
            Validate.IsNotNull(query);
            Validate.IsNotNull(function);

            this.Query    = query;
            this.Function = function;
            this.DefaultParameterValues = new Collection <ParameterValue>();
            this.Action = action;

            var defaultValues = query.CompileDefaultParameters();

            foreach (var value in defaultValues)
            {
                this.DefaultParameterValues.Add(value);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: EmpowerCourse/day_16
 static void Execute(IAggregateFunction function, List <int> numbers)
 {
     foreach (var number in numbers)
     {
         function.Insert(number);
     }
     Console.WriteLine(function.Calculate());
 }
コード例 #6
0
 public void Merge(IAggregateFunction aggregateFunction)
 {
     var function = aggregateFunction as TotalSalarySumAggregateFunction;
     if (function != null)
     {
         this.totalSalary += function.totalSalary;
     }
 }
        /// <summary>
        /// Here you can assign an AggregateFunction to the specific data type.
        /// ColumnNamesAggregateFunctions has higher priority.
        /// </summary>
        public void AddTypeAggregateFunction(Type type, IAggregateFunction func)
        {
            if (_builder.TypesAggregateFunctions == null)
            {
                _builder.TypesAggregateFunctions = new Dictionary <Type, IAggregateFunction>();
            }

            _builder.TypesAggregateFunctions.Add(type, func);
        }
        /// <summary>
        /// Here you can assign an AggregateFunction to the specific column name.
        /// </summary>
        public void AddColumnAggregateFunction(string name, IAggregateFunction func)
        {
            if (_builder.ColumnNamesAggregateFunctions == null)
            {
                _builder.ColumnNamesAggregateFunctions = new Dictionary <string, IAggregateFunction>();
            }

            _builder.ColumnNamesAggregateFunctions.Add(name, func);
        }
コード例 #9
0
 public AggregatingStateDescriptor(
     string name,
     IAggregateFunction <TInput, TAccumulator, TOutput> aggFunction,
     TypeSerializer <TAccumulator> stateType,
     TAccumulator defaultValue = default)
     : base(name, stateType, defaultValue)
 {
     AggregateFunction = aggFunction;
 }
コード例 #10
0
        public void Merge(IAggregateFunction aggregateFunction)
        {
            var function = aggregateFunction as TotalSalarySumAggregateFunction;

            if (function != null)
            {
                this.totalSalary += function.totalSalary;
            }
        }
コード例 #11
0
 public void Merge(IAggregateFunction aggregateFunction)
 {
     var function = aggregateFunction as RegularSalaryDifferenceAggregateFunction;
     if (function != null)
     {
         if (this.minSalary > function.minSalary)
             this.minSalary = function.minSalary;
         if (this.maxSalary < function.maxSalary)
             this.maxSalary = function.maxSalary;
     }
 }
コード例 #12
0
        /// <summary>
        /// Defines a total function for the column
        /// </summary>
        /// <param name="totalAggregator">The total aggregate function</param>
        /// <param name="totalFormat">The total format (optional)</param>
        public virtual void DefineTotal
        (
            IAggregateFunction totalAggregator,
            string totalFormat = null
        )
        {
            Validate.IsNotNull(totalAggregator);

            this.TotalAggregator = totalAggregator;
            this.TotalFormat     = totalFormat;
            this.HasTotal        = true;
        }
コード例 #13
0
 /// <summary>
 /// Defines total aggregator functions for the columns specified
 /// </summary>
 /// <param name="totalAggregator">The total aggregator function</param>
 /// <param name="columnNames">The column names</param>
 public void DefineTotals
 (
     IAggregateFunction totalAggregator,
     params string[] columnNames
 )
 {
     DefineTotals
     (
         totalAggregator,
         null,
         columnNames
     );
 }
コード例 #14
0
        private void initializeFunction(AggregateFunction aggregateFunction)
        {
            switch (aggregateFunction)
            {
            case AggregateFunction.Average:
                ColumnAggregateFunction = new Average {
                    DisplayFormatFormula = DisplayFormatFormula
                };
                break;

            case AggregateFunction.Maximum:
                ColumnAggregateFunction = new Maximum {
                    DisplayFormatFormula = DisplayFormatFormula
                };
                break;

            case AggregateFunction.Minimum:
                ColumnAggregateFunction = new Minimum {
                    DisplayFormatFormula = DisplayFormatFormula
                };
                break;

            case AggregateFunction.StdDev:
                ColumnAggregateFunction = new StdDev {
                    DisplayFormatFormula = DisplayFormatFormula
                };
                break;

            case AggregateFunction.Sum:
                ColumnAggregateFunction = new Sum {
                    DisplayFormatFormula = DisplayFormatFormula
                };
                break;

            case AggregateFunction.Variance:
                ColumnAggregateFunction = new Variance {
                    DisplayFormatFormula = DisplayFormatFormula
                };
                break;

            case AggregateFunction.Empty:
                ColumnAggregateFunction = new Empty {
                    DisplayFormatFormula = DisplayFormatFormula
                };
                break;

            default:
                throw new NotSupportedException("Please select a defined IAggregateFunction.");
            }
        }
コード例 #15
0
        public void Merge(IAggregateFunction aggregateFunction)
        {
            var function = aggregateFunction as RegularSalaryDifferenceAggregateFunction;

            if (function != null)
            {
                if (this.minSalary > function.minSalary)
                {
                    this.minSalary = function.minSalary;
                }
                if (this.maxSalary < function.maxSalary)
                {
                    this.maxSalary = function.maxSalary;
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Defines total aggregator functions for the columns specified
        /// </summary>
        /// <param name="totalAggregator">The total aggregator function</param>
        /// <param name="totalFormat">The total format pattern</param>
        /// <param name="columnNames">The column names</param>
        public void DefineTotals
        (
            IAggregateFunction totalAggregator,
            string totalFormat,
            params string[] columnNames
        )
        {
            Validate.IsNotNull(totalAggregator);
            Validate.IsNotNull(columnNames);

            foreach (var name in columnNames)
            {
                var column = GetColumn(name);

                column.DefineTotal
                (
                    totalAggregator,
                    totalFormat
                );
            }
        }
コード例 #17
0
        /// <summary>
        /// Constructs the column definition with the configuration
        /// </summary>
        /// <param name="name">The column name</param>
        /// <param name="valueBinding">The row value binding</param>
        /// <param name="totalAggregator">The total aggregator (optional)</param>
        /// <param name="totalFormat">The total format (optional)</param>
        public TableColumnDefinition
        (
            string name,
            DataBinding valueBinding,
            IAggregateFunction totalAggregator = null,
            string totalFormat = null
        )
        {
            Validate.IsNotEmpty(name);
            Validate.IsNotNull(valueBinding);

            this.ColumnId     = Guid.NewGuid();
            this.Name         = name;
            this.Title        = name;
            this.ValueBinding = valueBinding;

            if (totalAggregator != null)
            {
                DefineTotal(totalAggregator, totalFormat);
            }
        }
コード例 #18
0
        public FieldObject Terminate()
        {
            if (sideEffectStates.Count == 1)
            {
                Tuple <string, IAggregateFunction> tuple = sideEffectStates[0];
                IAggregateFunction sideEffectState       = tuple.Item2;

                return(sideEffectState.Terminate());
            }
            else
            {
                MapField map = new MapField();

                foreach (Tuple <string, IAggregateFunction> tuple in sideEffectStates)
                {
                    string             key             = tuple.Item1;
                    IAggregateFunction sideEffectState = tuple.Item2;

                    map.Add(new StringField(key), sideEffectState.Terminate());
                }

                return(map);
            }
        }
コード例 #19
0
 /// <summary>
 /// A set of a predefined aggregate functions.
 /// It only works with numbers. If you want to apply it on other data types, you need to create your own AggregateFunction by implementing the IAggregateFunc.
 /// </summary>
 public void NumericAggregateFunction(AggregateFunction aggregateFunction)
 {
     _aggregateFunction = new AggregateProvider(aggregateFunction);
 }
コード例 #20
0
 /// <summary>
 /// Applies the given window function to each window. The window function is called for each evaluation of the window for each key individually.The output of the window function is interpreted as a regular non-windowed stream.
 /// </summary>
 /// <typeparam name="TAccumulator">The type of the AggregateFunction's accumulator</typeparam>
 /// <typeparam name="TValue">The type of AggregateFunction's result, and the WindowFunction's input</typeparam>
 /// <typeparam name="TResult">The type of the elements in the resulting stream, equal to the WindowFunction's result type</typeparam>
 /// <param name="aggFunction">The aggregate function that is used for incremental aggregation.</param>
 /// <param name="windowFunction">The window function.</param>
 /// <returns>The data stream that is the result of applying the window function to the window.</returns>
 public SingleOutputStreamOperator <TResult> Aggregate <TAccumulator, TValue, TResult>(IAggregateFunction <TElement, TAccumulator, TValue> aggFunction, IWindowFunction <TValue, TResult, TKey, TWindow> windowFunction)
 {
     return(null);
 }
コード例 #21
0
 static void AddAggregateFunction(IAggregateFunction aggregateFunction)
 {
     _aggregateFunctionIndexesByName.Add(aggregateFunction.Name, _aggregateFunctionList.Count);
     _aggregateFunctionList.Add(aggregateFunction);
 }
コード例 #22
0
ファイル: Sql.Analytic.cs プロジェクト: softak098/linq2db
 public static INeedOrderByAndMaybeOverWithPartition <TR> KeepLast <TR>(this IAggregateFunction <TR> ext)
 {
     throw new NotImplementedException();
 }
コード例 #23
0
 /// <summary>
 /// Custom Aggregate Function
 /// It can be null.
 /// </summary>
 public void CustomAggregateFunction(IAggregateFunction aggregateFunction)
 {
     _aggregateFunction = aggregateFunction;
 }
コード例 #24
0
 public MetricProcessor(IAggregateFunction aggregateFunction, StreamBinaryEventsWriter writer)
 {
     this.aggregateFunction = aggregateFunction;
     this.writer            = writer;
 }
コード例 #25
0
 public void AddCapatureSideEffectState(string key, IAggregateFunction sideEffectState)
 {
     sideEffectStates.Add(new Tuple <string, IAggregateFunction>(key, sideEffectState));
 }
コード例 #26
0
 /// <summary>
 /// Applies the given aggregation function to each window. The aggregation function is called for each element, aggregating values incrementally and keeping the state to one accumulator per key and window.
 /// </summary>
 /// <typeparam name="TAccumulator">The type of the AggregateFunction's accumulator</typeparam>
 /// <typeparam name="TResult">The type of the elements in the resulting stream, equal to the AggregateFunction's result type</typeparam>
 /// <param name="function">The aggregation function.</param>
 /// <returns>The data stream that is the result of applying the fold function to the window.</returns>
 public SingleOutputStreamOperator <TResult> Aggregate <TAccumulator, TResult>(IAggregateFunction <TElement, TAccumulator, TResult> function)
 {
     return(null);
 }
コード例 #27
0
 /// <summary>
 /// Custom Aggregate Function
 /// It can be null.
 /// </summary>
 public void CustomAggregateFunction(IAggregateFunction aggregateFunction)
 {
     _aggregateFunction = aggregateFunction;
 }
コード例 #28
0
 /// <summary>
 /// A set of a predefined aggregate functions.
 /// It only works with numbers. If you want to apply it on other data types, you need to create your own AggregateFunction by implementing the IAggregateFunc.
 /// </summary>
 public void NumericAggregateFunction(AggregateFunction aggregateFunction)
 {
     _aggregateFunction = new AggregateProvider(aggregateFunction);
 }
コード例 #29
0
        public void Merge(IAggregateFunction aggregateFunction)
        {
            //PageFooterSumUntilNow aggregate = (PageFooterSumUntilNow)aggregateFunction;

            //this.result += aggregate.result;
        }
コード例 #30
0
ファイル: CustomizeViewForm.cs プロジェクト: zjjyyang/ftdr
 public AggregateItem(string displayName, IAggregateFunction function, Image image)
 {
     DisplayName = displayName;
     Function    = function;
     Image       = image;
 }