示例#1
0
        public string GetOeeKpiData(string key, ContosoTopologyNode.AggregationView view, ContosoPerformanceRelevance relevance)
        {
            AggregatedTimeSeriesResult timeSeries;
            ContosoTopologyNode        node = (ContosoTopologyNode)Startup.Topology[key];

            if (node == null)
            {
                return(JsonConvert.SerializeObject("Error"));
            }
            else
            {
                timeSeries = node.AggregatedOeeKpiTimeSeries(view, relevance, TimeSpan.FromHours(1));
            }
            return(JsonConvert.SerializeObject(timeSeries));
        }
示例#2
0
        public string GetDataForOpcUaNode(string key, string nodeId, ContosoTopologyNode.AggregationView view)
        {
            AggregatedTimeSeriesResult timeSeries;
            ContosoOpcUaNode           contosoOpcUaNode = Startup.Topology.GetOpcUaNode(key, nodeId);
            Station station = Startup.Topology.GetStation(key);

            string[] data = new string[3];

            if ((contosoOpcUaNode == null) || (station == null))
            {
                data[0] = "Error";
                return(JsonConvert.SerializeObject(data));
            }

            if (!(RDXUtils.IsAggregatedOperator(contosoOpcUaNode.OpCode)))
            {
                data[0] = "NoTimeSeries";
                // Non aggregating opcodes are not updated unless they have a relevance
                data[1] = contosoOpcUaNode.Last.Value.ToString("0.###", CultureInfo.InvariantCulture);

                if (contosoOpcUaNode.Units != null)
                {
                    data[2] = contosoOpcUaNode.Units.ToString();
                }
                else
                {
                    data[2] = "";
                }
                return(JsonConvert.SerializeObject(data));
            }

            Task <AggregatedTimeSeriesResult> task = Task.Run(() => RDXUtils.AggregatedNodeId(station, contosoOpcUaNode, view));

            // Will block until the task is completed...
            timeSeries = task.Result;

            return(JsonConvert.SerializeObject(timeSeries));
        }
示例#3
0
        public string RDXLink(string key, ContosoTopologyNode.AggregationView view)
        {
            string   url     = null;
            Station  station = Startup.Topology.GetStation(key);
            DateTime now     = DateTime.UtcNow;
            DateTime past;

            switch (view)
            {
            case ContosoTopologyNode.AggregationView.Hour:
                past = now.Subtract(TimeSpan.FromHours(1));
                break;

            case ContosoTopologyNode.AggregationView.Day:
                past = now.Subtract(TimeSpan.FromDays(1));
                break;

            case ContosoTopologyNode.AggregationView.Week:
                past = now.Subtract(TimeSpan.FromDays(7));
                break;

            default:
                past = now.Subtract(TimeSpan.FromDays(1));
                break;
            }

            if (station != null)
            {
                url = RDXExplorer.GetExplorerStationView(past, now, key, true, false);
            }
            else
            {
                url = RDXExplorer.GetExplorerDefaultView(past, now, false);
            }

            return(url);
        }
        /// <summary>
        /// Return the time series for a given OPC UA server and a given node
        /// </summary>
        /// <param name="station">The OPC UA server</param>
        /// <param name="node">The OPC UA node Id</param>
        /// <param name="aggregationView">The hourly, daily or weekly view</param>
        /// <param name="getCount">Get event Count aggregate</param>
        public static async Task <AggregatedTimeSeriesResult> AggregatedNodeId(
            Station station,
            ContosoOpcUaNode node,
            ContosoTopologyNode.AggregationView aggregationView,
            bool getCount = false)
        {
            int             aggregateIndex = (int)aggregationView;
            RDXOpcUaQueries opcUaQuery     = new RDXOpcUaQueries(CancellationToken.None);
            ContosoAggregatedOeeKpiHistogram aggregatedTimeSpan = station[aggregateIndex];
            DateTimeRange searchSpan    = RDXUtils.TotalSearchRangeFromNow(aggregatedTimeSpan);
            DateTimeRange aggregateSpan = new DateTimeRange(
                searchSpan.To.Subtract(aggregatedTimeSpan.TotalTimeSpan),
                searchSpan.To
                );
            double roundFactor = 100.0;

            int index = (int)RDXOpcUaQueries.AggregateIndex.Count;

            if (!getCount)
            {
                if (!IsAggregatedOperator(node.OpCode))
                {
                    throw new Exception("Unsupported Operator for aggregation");
                }

                // handle special case for SubMaxMin, result is derived by substraction
                if (node.OpCode == ContosoOpcNodeOpCode.SubMaxMin)
                {
                    index = (int)RDXOpcUaQueries.AggregateIndex.Max;
                }
                else
                {
                    index = AggregatedOperatorIndex(node.OpCode);
                }
            }

            int resultDimension = aggregatedTimeSpan.Intervals.Count;

            DateTime [] dateTimeResult = CreateAggregateDateTimeArray(aggregateSpan.From, aggregatedTimeSpan.IntervalTimeSpan, resultDimension);

            AggregateResult queryResult = await opcUaQuery.GetAllAggregatedNodesWithInterval(
                aggregateSpan,
                station.Key,
                node.NodeId,
                aggregatedTimeSpan.IntervalTimeSpan
                );

            int count = queryResult.Aggregate.Dimension.Count;
            AggregatedTimeSeriesResult result = new AggregatedTimeSeriesResult(resultDimension, aggregateSpan.To, aggregatedTimeSpan.IntervalTimeSpan, node.Units);

            if (queryResult != null)
            {
                for (int i = 0; i < count; i++)
                {
                    double?value = queryResult.Aggregate.Aggregate.Measures.TryGetPropertyMeasure <double?>(new int[] { 0, i, index });
                    if (value != null)
                    {
                        // find matching date/time slot for value
                        var dateTime    = queryResult.Aggregate.Dimension[i];
                        int resultIndex = Array.IndexOf(dateTimeResult, dateTime);
                        if (resultIndex >= 0)
                        {
                            result.YValues[resultIndex] = roundFactor * (double)value;
                            if (node.OpCode == ContosoOpcNodeOpCode.SubMaxMin)
                            {
                                value = queryResult.Aggregate.Aggregate.Measures.TryGetPropertyMeasure <double?>(new int[] { 0, i, (int)RDXOpcUaQueries.AggregateIndex.Min });
                                if (value != null)
                                {
                                    result.YValues[resultIndex] -= roundFactor * (double)value;
                                }
                            }
                            result.YValues[resultIndex] = Math.Round(result.YValues[resultIndex]) / roundFactor;
                        }
                        else
                        {
                            throw new Exception("DateTime not found in aggregated query array");
                        }
                    }
                }
            }
            return(result);
        }