Пример #1
0
        protected virtual void ComputeAverage(StatisticsSet statistics)
        {
            foreach (IStatistics field in statistics.Fields)
            {
                IAverageStatistics average = field.NewAverageStatistics();

                if (average == null)
                {
                    continue;
                }

                object key = StatisticsHelper.ResolveID(average);
                if (this[key] != null)
                {
                    average = this[key] as IAverageStatistics;
                    Debug.Assert(average != null);
                }
                else
                {
                    AddField(average);
                }

                if (field is Statistics <int> )
                {
                    average.AddSample(((Statistics <int>)field).Value);
                }
                else if (field is Statistics <uint> )
                {
                    average.AddSample(((Statistics <uint>)field).Value);
                }
                else if (field is Statistics <long> )
                {
                    //sum += ((Statistics<long>)field).Value;
                    average.AddSample(((Statistics <long>)field).Value);
                }
                else if (field is Statistics <ulong> )
                {
                    average.AddSample(((Statistics <ulong>)field).Value);
                }
                else if (field is Statistics <double> )
                {
                    average.AddSample(((Statistics <double>)field).Value);
                }
                else if (field is TimeSpanStatistics)
                {
                    TimeSpanStatistics stat = field as TimeSpanStatistics;
                    if (stat.IsSet)
                    {
                        average.AddSample(((TimeSpanStatistics)field).Value);
                    }
                }
            }
        }