/// <summary> /// Parses source definitions for an annotation query. /// </summary> /// <param name="request">Grafana annotation request.</param> /// <param name="type">Annotation type.</param> /// <param name="source">Metadata of source definitions.</param> /// <param name="useFilterExpression">Determines if query is using a filter expression.</param> /// <returns>Parsed source definitions from annotation <paramref name="request"/>.</returns> public static Dictionary <string, DataRow> ParseSourceDefinitions(this AnnotationRequest request, AnnotationType type, DataSet source, bool useFilterExpression) { if ((object)request == null) { throw new ArgumentNullException(nameof(request)); } return(request.annotation.ParseSourceDefinitions(type, source, useFilterExpression)); }
/// <summary> /// Parses query expression from annotation request for annotation type. /// </summary> /// <param name="request">Grafana annotation request.</param> /// <param name="useFilterExpression">Determines if query is using a filter expression.</param> /// <returns>Parsed annotation type for query expression from annotation <paramref name="request"/>.</returns> public static AnnotationType ParseQueryType(this AnnotationRequest request, out bool useFilterExpression) { if ((object)request == null) { throw new ArgumentNullException(nameof(request)); } return(request.annotation.ParseQueryType(out useFilterExpression)); }
/// <summary> /// Queries openHistorian for annotations in a time-range (e.g., Alarms). /// </summary> /// <param name="request">Annotation request.</param> public async Task <List <AnnotationResponse> > Annotations(AnnotationRequest request) { // Abort if services are not enabled if (!Enabled || Archive is null) { return(null); } return(await m_dataSource.Annotations(request, m_cancellationSource.Token)); }
/// <summary> /// Queries openHistorian for annotations in a time-range (e.g., Alarms). /// </summary> /// <param name="request">Annotation request.</param> public List <AnnotationResponse> Annotations(AnnotationRequest request) { // Abort if services are not enabled if (!Enabled || (object)Archive == null) { return(null); } return(m_dataSource.Annotations(request, m_cancellationSource.Token).Result); }
/// <summary> /// Extracts a Grafana <see cref="QueryRequest"/> from an <see cref="AnnotationRequest"/>. /// </summary> /// <param name="request">Annotation request.</param> /// <param name="targets">List of desired targets.</param> /// <param name="maxDataPoints">Maximum points to return.</param> /// <returns>Grafana query request object from an annotation <paramref name="request"/>.</returns> public static QueryRequest ExtractQueryRequest(this AnnotationRequest request, IEnumerable <string> targets, int maxDataPoints) { if ((object)targets == null) { throw new ArgumentNullException(nameof(targets)); } return(new QueryRequest { range = request.range, rangeRaw = request.rangeRaw, interval = "*", targets = targets.Select((target, index) => new Target { refId = $"ID{index}", target = target }).ToList(), format = "json", maxDataPoints = maxDataPoints }); }
/// <summary> /// Extracts a Grafana <see cref="QueryRequest"/> from an <see cref="AnnotationRequest"/>. /// </summary> /// <param name="request">Annotation request.</param> /// <param name="targets">List of desired targets.</param> /// <param name="maxDataPoints">Maximum points to return.</param> /// <returns>Grafana query request object from an annotation <paramref name="request"/>.</returns> public static QueryRequest ExtractQueryRequest(this AnnotationRequest request, IEnumerable <string> targets, int maxDataPoints) { if (targets == null) { throw new ArgumentNullException(nameof(targets)); } // Create annotation query request for full resolution data using "Interval(0, {target})" // function so that any encountered alarms not will not be down-sampled return(new QueryRequest { range = request.range, rangeRaw = request.rangeRaw, interval = "*", targets = targets.Select((target, index) => new Target { refId = $"ID{index}", target = $"Interval(0, {target})" }).ToList(), format = "json", maxDataPoints = maxDataPoints }); }
/// <summary> /// Queries openHistorian for annotations in a time-range (e.g., Alarms). /// </summary> /// <param name="request">Annotation request.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns>Queried annotations from data source.</returns> public async Task<List<AnnotationResponse>> Annotations(AnnotationRequest request, CancellationToken cancellationToken) { bool useFilterExpression; AnnotationType type = request.ParseQueryType(out useFilterExpression); Dictionary<string, DataRow> definitions = request.ParseSourceDefinitions(type, Metadata, useFilterExpression); List<TimeSeriesValues> annotationData = await Query(request.ExtractQueryRequest(definitions.Keys, MaximumAnnotationsPerRequest), cancellationToken); List<AnnotationResponse> responses = new List<AnnotationResponse>(); foreach (TimeSeriesValues values in annotationData) { string target = values.target; DataRow definition = definitions[target]; foreach (double[] datapoint in values.datapoints) { if (type.IsApplicable(datapoint)) { AnnotationResponse response = new AnnotationResponse { annotation = request.annotation, time = datapoint[TimeSeriesValues.Time] }; type.PopulateResponse(response, target, definition, datapoint, Metadata); responses.Add(response); } } } return responses; }
/// <summary> /// Queries openHistorian for annotations in a time-range (e.g., Alarms). /// </summary> /// <param name="request">Annotation request.</param> public async Task<List<AnnotationResponse>> Annotations(AnnotationRequest request) { // Abort if services are not enabled if (!Enabled || (object)Archive == null) return null; return await m_dataSource.Annotations(request, m_cancellationSource.Token); }