Esempio n. 1
0
        /// <summary>
        /// Query for all active OPC UA servers in given search span
        /// </summary>
        /// <param name="searchSpan">Date and time span for the query</param>
        /// <returns>List of active servers</returns>
        public async Task <StringDimensionResult> AggregateServers(DateTimeRange searchSpan)
        {
            Aggregate aggregate = new Aggregate(
                Expression.UniqueValues(OpcServerUri, PropertyType.String, opcMaxServerUri));

            AggregatesResult aggregateResults = await RDXQueryClient.GetAggregatesAsync(
                searchSpan,
                null,
                new[] { aggregate },
                _cancellationToken);

            // Since there was 1 top level aggregate in request, there is 1 aggregate result.
            AggregateResult       aggregateResult = aggregateResults[0];
            StringDimensionResult dimension       = aggregateResult.Dimension as StringDimensionResult;

            return(dimension);
        }
Esempio n. 2
0
        /// <summary>
        /// Query for aggregation of count, min, max, sum and average for all active
        /// nodes of the given OPC UA server in the given search span as time histogram
        /// with interval
        /// </summary>
        /// <param name="searchSpan">Date and time span for the query</param>
        /// <param name="appUri">The OPC UA server application Uri</param>
        /// <param name="interval">Interval for Date Time Histogram</param>
        /// <returns>The aggregated nodes</returns>
        public async Task <AggregateResult> GetAllAggregatedNodesWithInterval(DateTimeRange searchSpan, string appUri, string nodeId, TimeSpan interval)
        {
            try
            {
                string id = TimeSpanToId(interval);

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                PredicateStringExpression predicate = new PredicateStringExpression(
                    String.Format(OpcServerNodePredicate, appUri, nodeId));
                Aggregate aggregate = new Aggregate(
                    Expression.UniqueValues(OpcMonitoredItemId, PropertyType.String, opcMaxMonitoredItemId),
                    new Aggregate(Expression.DateHistogram(BuiltInProperty.Timestamp, IntervalSize.FromId(id)),
                                  new Aggregate(
                                      Expression.Count(),
                                      Expression.Min(OpcMonitoredItemValue, PropertyType.Double),
                                      Expression.Max(OpcMonitoredItemValue, PropertyType.Double),
                                      Expression.Average(OpcMonitoredItemValue, PropertyType.Double),
                                      Expression.Sum(OpcMonitoredItemValue, PropertyType.Double)
                                      )));

                AggregatesResult aggregateResults = await RDXQueryClient.GetAggregatesAsync(
                    searchSpan,
                    predicate,
                    new[] { aggregate },
                    _cancellationToken);

                // Since there was 1 top level aggregate in request, there is 1 aggregate result.
                AggregateResult aggregateResult = aggregateResults[0];

                stopwatch.Stop();
                RDXTrace.TraceInformation("GetAllAggregatedNodes query took {0} ms", stopwatch.ElapsedMilliseconds);

                return(aggregateResult);
            }
            catch (Exception e)
            {
                RDXTrace.TraceError("GetAllAggregatedNodes: Exception {0}", e.Message);
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Query for aggregation of count, min, max, sum and average for all active
        /// nodes of all OPC UA servers in the given search span
        /// </summary>
        /// <param name="searchSpan">Date and time span for the query</param>
        /// <returns>The aggregated servers and nodes</returns>
        public async Task <AggregateResult> GetAllAggregatedStationsAndNodes(DateTimeRange searchSpan)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                Aggregate aggregate = new Aggregate(
                    Expression.UniqueValues(OpcServerUri, PropertyType.String, opcMaxServerUri),
                    new Aggregate(
                        Expression.UniqueValues(OpcMonitoredItemId, PropertyType.String, opcMaxMonitoredItemId),
                        new Aggregate(
                            Expression.Count(),
                            Expression.Min(OpcMonitoredItemValue, PropertyType.Double),
                            Expression.Max(OpcMonitoredItemValue, PropertyType.Double),
                            Expression.Average(OpcMonitoredItemValue, PropertyType.Double),
                            Expression.Sum(OpcMonitoredItemValue, PropertyType.Double)
                            )
                        )
                    );

                AggregatesResult aggregateResults = await RDXQueryClient.GetAggregatesAsync(
                    searchSpan,
                    null,
                    new[] { aggregate },
                    _cancellationToken);

                // Since there was 1 top level aggregate in request, there is 1 aggregate result.
                _getAllAggregatedStationsAndNodesResult = aggregateResults[0];

                stopwatch.Stop();
                RDXTrace.TraceInformation("GetAllAggregatedStationsAndNodes query took {0} ms", stopwatch.ElapsedMilliseconds);

                return(_getAllAggregatedStationsAndNodesResult);
            }
            catch (Exception e)
            {
                RDXTrace.TraceError("GetAllAggregatedStationsAndNodes: Exception {0}", e.Message);
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Query for aggregation of a given measure for the
        /// given node and given OPC UA server in the given search span
        /// </summary>
        /// <param name="searchSpan">Date and time span for the query</param>
        /// <param name="appUri">The OPC UA server application Uri</param>
        /// <param name="nodeId">The node id in the OPC UA server namespace</param>
        /// <param name="measure"></param>
        public async Task <double> GetAggregatedNode(DateTimeRange searchSpan, string appUri, string nodeId, AggregateExpression measure)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                PredicateStringExpression predicate = new PredicateStringExpression(
                    String.Format(OpcServerNodePredicate, appUri, nodeId));
                Aggregate aggregate = new Aggregate(
                    measures: new AggregateExpression[] { measure }
                    );

                AggregatesResult aggregateResults = await RDXQueryClient.GetAggregatesAsync(
                    searchSpan,
                    predicate,
                    new[] { aggregate },
                    _cancellationToken);

                // Since there was 1 top level aggregate in request, there is 1 aggregate result.
                AggregateResult aggregateResult = aggregateResults[0];

                stopwatch.Stop();
                RDXTrace.TraceInformation("AggregateQuery query took {0} ms", stopwatch.ElapsedMilliseconds);

                if (aggregateResult.Measures == null)
                {
                    return(0.00);
                }

                return((double)aggregateResult.Measures[0]);
            }
            catch (Exception e)
            {
                RDXTrace.TraceError("AggregateQuery: Exception {0}", e.Message);
                return(0);
            }
        }