GetHistorianData() 공개 정적인 메소드

Read historian data from server.
public static GetHistorianData ( HistorianValue>.ClientDatabaseBase database, System.DateTime startTime, System.DateTime stopTime, ulong measurementIDs, Resolution resolution, int seriesLimit, bool forceLimit, ICancellationToken cancellationToken = null ) : IEnumerable
database HistorianValue>.ClientDatabaseBase Client database to use for query.
startTime System.DateTime Start time of query.
stopTime System.DateTime Stop time of query.
measurementIDs ulong Measurement IDs to query - or null for all available points.
resolution Resolution Resolution for data query.
seriesLimit int Maximum number of points per series.
forceLimit bool Flag that determines if series limit should be strictly enforced.
cancellationToken ICancellationToken Cancellation token for query.
리턴 IEnumerable
예제 #1
0
        /// <summary>
        /// Read historian data from server.
        /// </summary>
        /// <param name="instanceName">Historian instance name.</param>
        /// <param name="startTime">Start time of query.</param>
        /// <param name="stopTime">Stop time of query.</param>
        /// <param name="measurementIDs">Measurement IDs to query - or <c>null</c> for all available points.</param>
        /// <param name="resolution">Resolution for data query.</param>
        /// <param name="seriesLimit">Maximum number of points per series.</param>
        /// <param name="forceLimit">Flag that determines if series limit should be strictly enforced.</param>
        /// <param name="timestampType">Type of timestamps.</param>
        /// <returns>Enumeration of <see cref="TrendValue"/> instances read for time range.</returns>
        public IEnumerable <TrendValue> GetHistorianData(string instanceName, DateTime startTime, DateTime stopTime, ulong[] measurementIDs, Resolution resolution, int seriesLimit, bool forceLimit, TimestampType timestampType = TimestampType.UnixMilliseconds)
        {
            // Cancel any running operation
            CancellationToken cancellationToken = new CancellationToken();

            Interlocked.Exchange(ref m_readCancellationToken, cancellationToken)?.Cancel();

            SnapServer server = GetServer(instanceName)?.Host;
            IEnumerable <TrendValue> values = TrendValueAPI.GetHistorianData(server, instanceName, startTime, stopTime, measurementIDs, resolution, seriesLimit, forceLimit, cancellationToken);

            switch (timestampType)
            {
            case TimestampType.Ticks:
                return(values.Select(value =>
                {
                    value.Timestamp = value.Timestamp * 10000.0D + 621355968000000000.0D;
                    return value;
                }));

            case TimestampType.UnixSeconds:
                return(values.Select(value =>
                {
                    value.Timestamp = value.Timestamp / 1000.0D;
                    return value;
                }));

            default:
                return(values);
            }
        }
예제 #2
0
            protected override List <TimeSeriesValues> QueryTimeSeriesValues(DateTime startTime, DateTime stopTime, int maxDataPoints, Dictionary <ulong, string> targetMap, CancellationToken cancellationToken)
            {
                Dictionary <ulong, TimeSeriesValues> queriedTimeSeriesValues = new Dictionary <ulong, TimeSeriesValues>();

                if (targetMap.Count > 0)
                {
                    SnapServer server = GetAdapterInstance(InstanceName)?.Server?.Host;

                    if ((object)server != null)
                    {
                        ulong[]    measurementIDs = targetMap.Keys.ToArray();
                        Resolution resolution     = TrendValueAPI.EstimatePlotResolution(InstanceName, startTime, stopTime, measurementIDs);

                        using (SnapClient connection = SnapClient.Connect(server))
                            using (ClientDatabaseBase <HistorianKey, HistorianValue> database = connection.GetDatabase <HistorianKey, HistorianValue>(InstanceName))
                            {
                                foreach (TrendValue trendValue in TrendValueAPI.GetHistorianData(database, startTime, stopTime, measurementIDs, resolution, maxDataPoints, false, (CompatibleCancellationToken)cancellationToken))
                                {
                                    queriedTimeSeriesValues.GetOrAdd((ulong)trendValue.ID, id => new TimeSeriesValues {
                                        target = targetMap[id], datapoints = new List <double[]>()
                                    })
                                    .datapoints.Add(new[] { trendValue.Value, trendValue.Timestamp });
                                }
                            }
                    }
                }

                return(queriedTimeSeriesValues.Values.ToList());
            }
        /// <summary>
        /// Read historian data from server.
        /// </summary>
        /// <param name="instanceName">Historian instance name.</param>
        /// <param name="startTime">Start time of query.</param>
        /// <param name="stopTime">Stop time of query.</param>
        /// <param name="measurementIDs">Measurement IDs to query - or <c>null</c> for all available points.</param>
        /// <param name="resolution">Resolution for data query.</param>
        /// <param name="seriesLimit">Maximum number of points per series.</param>
        /// <param name="forceLimit">Flag that determines if series limit should be strictly enforced.</param>
        /// <returns>Enumeration of <see cref="TrendValue"/> instances read for time range.</returns>
        public IEnumerable <TrendValue> GetHistorianData(string instanceName, DateTime startTime, DateTime stopTime, ulong[] measurementIDs, Resolution resolution, int seriesLimit, bool forceLimit)
        {
            // Cancel any running query
            CancellationToken cancellationToken = new CancellationToken();

            Interlocked.Exchange(ref m_cancellationToken, cancellationToken)?.Cancel();

            return(TrendValueAPI.GetHistorianData(GetDatabase(instanceName), startTime, stopTime, measurementIDs, resolution, seriesLimit, forceLimit, cancellationToken));
        }
        public async Task <IEnumerable <TrendValue> > GetHistorianData(CancellationToken cancellationToken)
        {
            QueryParameters queryParameters;

            using (Stream contentStream = await Request.Content.ReadAsStreamAsync())
                using (StreamReader contentReader = new StreamReader(contentStream))
                    using (JsonTextReader jsonReader = new JsonTextReader(contentReader))
                    {
                        JObject jsonObject = await JObject.LoadAsync(jsonReader);

                        queryParameters = jsonObject.ToObject <QueryParameters>();
                    }

            string   instanceName = queryParameters.instanceName;
            DateTime startTime    = queryParameters.startTime;
            DateTime stopTime     = queryParameters.stopTime;

            ulong[]    measurementIDs = queryParameters.measurementIDs;
            Resolution resolution     = queryParameters.resolution;
            int        seriesLimit    = queryParameters.seriesLimit;
            bool       forceLimit     = queryParameters.forceLimit;

            // Try to ensure another linked cancellation token is not created after dispose,
            // because another call to Dispose() won't clean it up
            if (m_disposed)
            {
                throw new ObjectDisposedException(nameof(HistorianQueryController));
            }

            // Cancel any running operation
            CancellationTokenSource linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

            using (CancellationTokenSource oldTokenSource = Interlocked.Exchange(ref m_linkedTokenSource, linkedTokenSource))
            {
                oldTokenSource?.Cancel();
            }

            SnapServer               server          = GetServer(instanceName)?.Host;
            ICancellationToken       compatibleToken = new CompatibleCancellationToken(linkedTokenSource);
            IEnumerable <TrendValue> values          = TrendValueAPI.GetHistorianData(server, instanceName, startTime, stopTime, measurementIDs, resolution, seriesLimit, forceLimit, compatibleToken);

            switch (queryParameters.timestampType)
            {
            case TimestampType.Ticks:
                return(values.Select(value =>
                {
                    value.Timestamp = value.Timestamp * 10000.0D + 621355968000000000.0D;
                    return value;
                }));

            case TimestampType.UnixSeconds:
                return(values.Select(value =>
                {
                    value.Timestamp = value.Timestamp / 1000.0D;
                    return value;
                }));

            default:
                return(values);
            }
        }