Ejemplo n.º 1
0
 public IEnumerable<Measurement> Aggregate(IGrouper grouper,
     IAggregateCalculator calculator)
 {
     var partitions = grouper.Group(_measurements);
     foreach (var partition in partitions)
     {
         yield return calculator.Aggregate(partition);
     }
 }
Ejemplo n.º 2
0
        public IEnumerable <Measurement> Aggregate(IGrouper grouper,
                                                   IAggregateCalculator calculator)
        {
            var partitions = grouper.Group(_measurements);

            foreach (var partition in partitions)
            {
                yield return(calculator.Aggregate(partition));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new aggregate calculator.
        /// </summary>
        /// <param name="aggregateId">The id of the aggregate function.</param>
        /// <param name="startTime">When to start processing.</param>
        /// <param name="endTime">When to stop processing.</param>
        /// <param name="processingInterval">The processing interval.</param>
        /// <param name="stepped">Whether stepped interpolation should be used.</param>
        /// <param name="configuration">The configuaration to use.</param>
        /// <returns></returns>
        public IAggregateCalculator CreateCalculator(
            NodeId aggregateId,
            DateTime startTime,
            DateTime endTime,
            double processingInterval,
            bool stepped,
            AggregateConfiguration configuration)
        {
            if (NodeId.IsNull(aggregateId))
            {
                return(null);
            }

            AggregatorFactory factory = null;

            lock (m_lock)
            {
                if (!m_factories.TryGetValue(aggregateId, out factory))
                {
                    return(null);
                }
            }

            if (configuration.UseServerCapabilitiesDefaults)
            {
                // ensure the configuration is initialized
                configuration = GetDefaultConfiguration(null);
            }

            IAggregateCalculator calculator = factory(aggregateId, startTime, endTime, processingInterval, stepped, configuration);

            if (calculator == null)
            {
                return(null);
            }

            return(calculator);
        }
        /// <summary>
        /// Extracts and queues any processed values.
        /// </summary>
        private void QueueProcessedValues(
            ServerSystemContext context, 
            IAggregateCalculator calculator, 
            NumericRange indexRange,
            QualifiedName dataEncoding,
            bool applyIndexRangeOrEncoding,
            bool returnPartial,
            LinkedList<DataValue> values)
        {
            DataValue proccessedValue = calculator.GetProcessedValue(returnPartial);

            while (proccessedValue != null)
            {
                // apply any index range or encoding.
                if (applyIndexRangeOrEncoding)
                {
                    object rawValue = proccessedValue.Value;
                    ServiceResult result = BaseVariableState.ApplyIndexRangeAndDataEncoding(context, indexRange, dataEncoding, ref rawValue);

                    if (ServiceResult.IsBad(result))
                    {
                        proccessedValue.Value = rawValue;
                    }
                    else
                    {
                        proccessedValue.Value = null;
                        proccessedValue.StatusCode = result.StatusCode;
                    }
                }

                // queue the result.
                values.AddLast(proccessedValue);
                proccessedValue = calculator.GetProcessedValue(returnPartial);
            }
        }