Ejemplo n.º 1
0
 /// <summary>
 /// Registers an aggregate factory.
 /// </summary>
 /// <param name="aggregateId">The id of the aggregate function.</param>
 /// <param name="aggregateName">The id of the aggregate name.</param>
 /// <param name="factory">The factory used to create calculators.</param>
 public void RegisterFactory(NodeId aggregateId, string aggregateName, AggregatorFactory factory)
 {
     lock (m_lock)
     {
         m_factories[aggregateId] = factory;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Registers an aggregate factory.
 /// </summary>
 /// <param name="aggregateId">The id of the aggregate function.</param>
 /// <param name="aggregateName">The id of the aggregate name.</param>
 /// <param name="factory">The factory used to create calculators.</param>
 public void RegisterFactory(NodeId aggregateId, string aggregateName, AggregatorFactory factory)
 {
     System.Diagnostics.Contracts.Contract.Assume(aggregateName != null);
     lock (_lock) {
         _factories[aggregateId] = factory;
     }
 }
Ejemplo n.º 3
0
        private async Task <GremlinResponse <T> > ReceiveAsync <T>()
        {
            ResponseStatus status;
            IAggregator    aggregator = null;
            var            isAggregatingSideEffects = false;
            var            result      = new List <T>();
            List <int>     statusCodes = new List <int>();
            List <Dictionary <string, object> > attributes = new List <Dictionary <string, object> >();

            do
            {
                var received = await _webSocketConnection.ReceiveMessageAsync().ConfigureAwait(false);

                var receivedMsg = _messageSerializer.DeserializeMessage <ResponseMessage <JToken> >(received);

                status = receivedMsg.Status;
                status.ThrowIfStatusIndicatesError();

                if (status.Code == ResponseStatusCode.Authenticate)
                {
                    await AuthenticateAsync().ConfigureAwait(false);
                }
                else
                {
                    statusCodes.Add((int)status.Code);
                    attributes.Add(status.Attributes);
                    if (status.Code != ResponseStatusCode.NoContent)
                    {
                        var receivedData = _graphSONReader.ToObject(receivedMsg.Result.Data);
                        foreach (var d in receivedData)
                        {
                            if (receivedMsg.Result.Meta.ContainsKey(Tokens.ArgsSideEffectKey))
                            {
                                if (aggregator == null)
                                {
                                    aggregator =
                                        new AggregatorFactory().GetAggregatorFor(
                                            (string)receivedMsg.Result.Meta[Tokens.ArgsAggregateTo]);
                                }
                                aggregator.Add(d);
                                isAggregatingSideEffects = true;
                            }
                            else
                            {
                                result.Add(d);
                            }
                        }
                    }
                }
            } while (status.Code == ResponseStatusCode.PartialContent || status.Code == ResponseStatusCode.Authenticate);

            List <T> resultsToReturn = isAggregatingSideEffects
                ? new List <T> {
                (T)aggregator.GetAggregatedResult()
            }
                : result;

            return(new GremlinResponse <T>(resultsToReturn, attributes, statusCodes));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers an aggregate factory.
        /// </summary>
        /// <param name="aggregateId">The id of the aggregate function.</param>
        /// <param name="aggregateName">The id of the aggregate name.</param>
        /// <param name="factory">The factory used to create calculators.</param>
        public void RegisterFactory(NodeId aggregateId, string aggregateName, AggregatorFactory factory)
        {
            lock (m_lock) {
                m_factories[aggregateId] = factory;
            }

            if (m_server != null)
            {
                m_server.DiagnosticsNodeManager.AddAggregateFunction(aggregateId, aggregateName, true);
            }
        }
Ejemplo n.º 5
0
        private async Task <IReadOnlyCollection <T> > ReceiveAsync <T>()
        {
            ResponseStatus status;
            IAggregator    aggregator = null;
            var            isAggregatingSideEffects = false;
            var            result = new List <T>();

            do
            {
                var received = await _webSocketConnection.ReceiveMessageAsync().ConfigureAwait(false);

                var receivedMsg = _messageSerializer.DeserializeMessage <ResponseMessage <JToken> >(received);

                status = receivedMsg.Status;
                status.ThrowIfStatusIndicatesError();

                if (status.Code == ResponseStatusCode.Authenticate)
                {
                    await AuthenticateAsync().ConfigureAwait(false);
                }
                else if (status.Code != ResponseStatusCode.NoContent)
                {
                    var receivedData = _graphSONReader.ToObject(receivedMsg.Result.Data);
                    foreach (var d in receivedData)
                    {
                        if (receivedMsg.Result.Meta.ContainsKey(Tokens.ArgsSideEffectKey))
                        {
                            if (aggregator == null)
                            {
                                aggregator =
                                    new AggregatorFactory().GetAggregatorFor(
                                        (string)receivedMsg.Result.Meta[Tokens.ArgsAggregateTo]);
                            }
                            aggregator.Add(d);
                            isAggregatingSideEffects = true;
                        }
                        else
                        {
                            result.Add(d);
                        }
                    }
                }
            } while (status.Code == ResponseStatusCode.PartialContent || status.Code == ResponseStatusCode.Authenticate);

            if (isAggregatingSideEffects)
            {
                return new List <T> {
                           (T)aggregator.GetAggregatedResult()
                }
            }
            ;
            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create and AggregateCalculator for a ReadProcessed service call.
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="steppedVariable"></param>
        /// <returns></returns>
        public static AggregateCalculatorImpl CreateAggregator(NewAggregateFilter filter, bool steppedVariable)
        {
            AggregatorFactory aci = null;

            if (Lookup.TryGetValue(filter.AggregateType, out aci))
            {
                AggregateCalculatorImpl retval = aci();
                retval.StartTime          = filter.StartTime;
                retval.EndTime            = filter.EndTime;
                retval.ProcessingInterval = filter.ProcessingInterval;
                retval.Configuration      = filter.AggregateConfiguration;
                retval.SteppedVariable    = steppedVariable;
                return(retval);
            }
            return(null);
        }
Ejemplo n.º 7
0
        public CompareDefinition DeserializeCompareDefinition(XElement xCompareDef)
        {
            try
            {
                var compareDef = new CompareDefinition();

                if (xCompareDef == null)
                {
                    return(compareDef);
                }

                // CompareFields
                foreach (XElement xField in xCompareDef.Element("comparefields").Elements())
                {
                    // Name
                    CompareField compareField = new CompareField();
                    compareField.Name1 = xField.Attribute(XName.Get("name1")).Value;

                    // Weight
                    compareField.Weight = (float)xField.Attribute(XName.Get("weight"));

                    // Comparer
                    string comparerName = xField.Attribute(XName.Get("comparer")).Value;

                    if (!string.IsNullOrEmpty(comparerName))
                    {
                        compareField.FuzzyComparer = StringFuzzyComparerFactory.GetInstance(comparerName);
                    }

                    compareDef.CompareFields.Add(compareField);
                }

                // Aggregator
                string aggregatorName = xCompareDef.Element("aggregator")
                                        .Attribute(XName.Get("name"))
                                        .Value;

                compareDef.Aggregator = AggregatorFactory.GetInstance(aggregatorName);

                return(compareDef);
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Fehler in " + this.GetType().FullName + " Method: [" + System.Reflection.MethodBase.GetCurrentMethod() + "] Data: " + xCompareDef.ToString(), ex);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Restores PivotData from specified state object.
        /// </summary>
        /// <remarks>This method assumes that PivotData configuration (dimensions, aggregator factory) matches specified state object.</remarks>
        /// <param name="state">state object</param>
        public void SetState(PivotDataState state)
        {
            if (state.DimCount != Dimensions.Length)
            {
                throw new ArgumentException("Incompatible number of dimensions", "state");
            }

            Clear();
            values = new Dictionary <object[], IAggregator>(state.Values.Length, new ValueKeyEqualityComparer());

            var revKeyIdx = new object[state.KeyValues.Length];

            for (var i = 0; i < revKeyIdx.Length; i++)
            {
                revKeyIdx[i] = state.KeyValues[i];
            }

            var         dimLen = Dimensions.Length;
            uint        d;
            IAggregator aggr;

            for (var i = 0; i < state.ValueKeys.Length; i++)
            {
                var vkIdx     = state.ValueKeys[i];
                var vkDimKeys = new object[dimLen];

                for (d = 0; d < dimLen; d++)
                {
                    vkDimKeys[d] = revKeyIdx[vkIdx[d]];
                }
                if (values.TryGetValue(vkDimKeys, out aggr))
                {
                    aggr.Merge(AggregatorFactory.Create(state.Values[i]));
                }
                else
                {
                    values[vkDimKeys] = AggregatorFactory.Create(state.Values[i]);
                }
            }
            if (!lazyTotals)
            {
                BatchCalcTotals();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Modifies the current <see cref="PivotData"/> object to merge values from itself and specified <see cref="PivotData"/>.
        /// </summary>
        /// <remarks>
        /// Only compatible <see cref="PivotData"/> objects could be merged: they should have the same AggregatorFactory and Dimensions configuration.
        /// This method is also useful for organizing parallel data aggregation algorithm.
        /// </remarks>
        /// <param name="pvtData">multidimensional dataset to merge</param>
        public virtual void Merge(IPivotData pvtData)
        {
            if (!AggregatorFactory.Equals(pvtData.AggregatorFactory))
            {
                throw new ArgumentException("AggregatorFactory mismatch");
            }
            if (Dimensions.Length != pvtData.Dimensions.Length)
            {
                throw new ArgumentException("Dimensions mismatch");
            }
            for (int i = 0; i < Dimensions.Length; i++)
            {
                if (!Dimensions[i].SequenceEqual(pvtData.Dimensions[i]))
                {
                    throw new ArgumentException(String.Format("Dimension {0} elements mismatch", i));
                }
            }

            // remove all totals
            totalValues.Clear();
            valuesArr = null;

            IAggregator aggr;

            foreach (var dp in pvtData)
            {
                if (!values.TryGetValue(dp.Key, out aggr))
                {
                    aggr           = aggregatorFactory.Create();
                    values[dp.Key] = aggr;
                }
                aggr.Merge(dp.Value);
            }
            if (!lazyTotals)
            {
                BatchCalcTotals();
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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="configuration">The configuaration to use.</param>
        /// <returns></returns>
        public IAggregateCalculator CreateCalculator(
            NodeId aggregateId,
            DateTime startTime,
            DateTime endTime,
            double processingInterval,
            AggregateConfiguration configuration)
        {
            if (NodeId.IsNull(aggregateId))
            {
                return(null);
            }

            AggregatorFactory factory = null;

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

            AggregateCalculatorImpl calculator = factory();

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

            calculator.StartTime          = startTime;
            calculator.EndTime            = endTime;
            calculator.ProcessingInterval = processingInterval;
            calculator.Configuration      = configuration;
            calculator.SteppedVariable    = configuration.UseSlopedExtrapolation;

            return(calculator);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Registers an aggregate factory.
        /// </summary>
        /// <param name="aggregateId">The id of the aggregate function.</param>
        /// <param name="aggregateName">The id of the aggregate name.</param>
        /// <param name="factory">The factory used to create calculators.</param>
        public void RegisterFactory(NodeId aggregateId, string aggregateName, AggregatorFactory factory)
        {
            lock (m_lock)
            {
                m_factories[aggregateId] = factory;
            }

            if (m_server != null)
            {
                m_server.DiagnosticsNodeManager.AddAggregateFunction(aggregateId, aggregateName, true);
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Use this to register the AggregatorFactory for a custom or vendor-defined
 /// Aggregator. This method assumes that the AggregateType node has been created
 /// and placed in the appropriate place in the namespace already.
 /// </summary>
 /// <param name="key">NodeId of the Aggregatetype node</param>
 /// <param name="factory">AggregatorFactory delegate</param>
 public static void RegisterAggregatorFactory(NodeId key, AggregatorFactory factory)
 {
     Lookup[key] = factory;
 }
Ejemplo n.º 14
0
 public OlapCube Count <T>(Func <IOlapDataVector, bool> aggregatePred = null, string title = "Count")
 {
     Aggregators.Add(AggregatorFactory.CreateCount <T>(aggregatePred));
     ValueTitles.Add(title);
     return(this);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Use this to register the AggregatorFactory for a custom or vendor-defined
 /// Aggregator. This method assumes that the AggregateType node has been created
 /// and placed in the appropriate place in the namespace already.
 /// </summary>
 /// <param name="key">NodeId of the Aggregatetype node</param>
 /// <param name="factory">AggregatorFactory delegate</param>
 public static void RegisterAggregatorFactory(NodeId key, AggregatorFactory factory)
 {
     Lookup[key] = factory;
 }
Ejemplo n.º 16
0
 public OlapCube Min <T>(Func <IOlapDataVector, object> valueSelector, Func <IOlapDataVector, bool> aggregatePred = null, string title = "Min")
 {
     Aggregators.Add(AggregatorFactory.CreateMin <T>(valueSelector, aggregatePred));
     ValueTitles.Add(title);
     return(this);
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Registers an aggregate factory.
        /// </summary>
        /// <param name="aggregateId">The id of the aggregate function.</param>
        /// <param name="aggregateName">The id of the aggregate name.</param>
        /// <param name="factory">The factory used to create calculators.</param>
        public void RegisterFactory(NodeId aggregateId, string aggregateName, AggregatorFactory factory)
        {
            lock (m_lock)
            {
                m_factories[aggregateId] = factory;
            }

        }