History

GrafanaAdapters: Added FilterNaN function to exclude NaN values and optionally to exclude infinite values also.

J. Ritchie Carroll committed 9 years ago

Commit 91d631d1 parent 74cc0d02 files · +39 −0Browse files

Unified · Split

2 files
  1. Source/Documentation/GrafanaFunctions.md +10 −0
  2. Source/Libraries/Adapters/GrafanaAdapters/GrafanaDataSourceBase.cs +29 −0
Source/Documentation/GrafanaFunctions.md+10−0
@@ -50,6 +50,7 @@ Series functions can operate over the set of defined series, producing a single · 49 unmodified lines
5050 * [Interval](#interval)
5151 * [IncludeRange](#includerange)
5252 * [ExcludeRange](#excluderange)
53+* [FilterNaN](#filternan)
5354 * [UnwrapAngle](#unwrapangle)
5455 * [WrapAngle](#wrapangle)
5556 * [Label](#label)
@@ -342,6 +343,15 @@ Returns a series of values that represent a filtered set of the values in the so · 286 unmodified lines
342343 * Variants: `ExcludeRange`, `Exclude`
343344 * Execution: Deferred enumeration
344345
346+## FilterNaN
347+
348+Returns a series of values that represent a filtered set of the values in the source series where each value is a real number, i.e., value is not NaN. First parameter, optional, is a boolean flag that determines if infinite values should also be excluded - defaults to true.
349+
350+* Signature: `FilterNaN([alsoFilterInfinity], expression)`
351+* Example: `FilterNaN(FILTER ActiveMeasurements WHERE SignalType='VPHM')`
352+* Variants: `FilterNaN`
353+* Execution: Deferred enumeration
354+
345355 ## UnwrapAngle
346356
347357 Returns a series of values that represent an adjusted set of angles that are unwrapped, per specified angle units, so that a comparable mathematical operation can be executed. For example, for angles that wrap between -180 and +180 degrees, this algorithm unwraps the values to make the values mathematically comparable. The units parameter, optional, specifies the type of angle units and must be one of the following: Degrees, Radians, Grads, ArcMinutes, ArcSeconds or AngularMil - defaults to Degrees.
Source/Libraries/Adapters/GrafanaAdapters/GrafanaDataSourceBase.cs+29−0
@@ -378,6 +378,17 @@ namespace GrafanaAdapters · 377 unmodified lines
378378 /// </remarks>
379379 ExcludeRange,
380380 /// <summary>
381+ /// Returns a series of values that represent a filtered set of the values in the source series where each value is a real number, i.e., value is not NaN.
382+ /// First parameter, optional, is a boolean flag that determines if infinite values should also be excluded - defaults to true.
383+ /// </summary>
384+ /// <remarks>
385+ /// Signature: <c>FilterNaN([alsoFilterInfinity], expression)</c><br/>
386+ /// Example: <c>FilterNaN(FILTER ActiveMeasurements WHERE SignalType='VPHM')</c><br/>
387+ /// Variants: FilterNaN<br/>
388+ /// Execution: Deferred enumeration.
389+ /// </remarks>
390+ FilterNaN,
391+ /// <summary>
381392 /// Returns a series of values that represent an adjusted set of angles that are unwrapped, per specified angle units, so that a comparable mathematical
382393 /// operation can be executed. For example, for angles that wrap between -180 and +180 degrees, this algorithm unwraps the values to make the values
383394 /// mathematically comparable. The units parameter, optional, specifies the type of angle units and must be one of the following: Degrees, Radians, Grads,
@@ -876,6 +887,7 @@ namespace GrafanaAdapters · 492 unmodified lines
876887 private static readonly Regex s_intervalExpression;
877888 private static readonly Regex s_includeRangeExpression;
878889 private static readonly Regex s_excludeRangeExpression;
890+ private static readonly Regex s_filterNaNExpression;
879891 private static readonly Regex s_unwrapAngleExpression;
880892 private static readonly Regex s_wrapAngleExpression;
881893 private static readonly Regex s_labelExpression;
@@ -923,6 +935,7 @@ namespace GrafanaAdapters · 41 unmodified lines
923935 s_intervalExpression = new Regex(string.Format(GetExpression, "Interval"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
924936 s_includeRangeExpression = new Regex(string.Format(GetExpression, "(IncludeRange|Include)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
925937 s_excludeRangeExpression = new Regex(string.Format(GetExpression, "(ExcludeRange|Exclude)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
938+ s_filterNaNExpression = new Regex(string.Format(GetExpression, "FilterNaN"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
926939 s_unwrapAngleExpression = new Regex(string.Format(GetExpression, "(UnwrapAngle|Unwrap)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
927940 s_wrapAngleExpression = new Regex(string.Format(GetExpression, "(WrapAngle|Wrap)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
928941 s_labelExpression = new Regex(string.Format(GetExpression, "(Label|Name)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
@@ -960,6 +973,7 @@ namespace GrafanaAdapters · 31 unmodified lines
960973 [SeriesFunction.Interval] = 1,
961974 [SeriesFunction.IncludeRange] = 2,
962975 [SeriesFunction.ExcludeRange] = 2,
976+ [SeriesFunction.FilterNaN] = 0,
963977 [SeriesFunction.UnwrapAngle] = 0,
964978 [SeriesFunction.WrapAngle] = 0,
965979 [SeriesFunction.Label] = 1
@@ -998,6 +1012,7 @@ namespace GrafanaAdapters · 32 unmodified lines
9981012 [SeriesFunction.Interval] = 0,
9991013 [SeriesFunction.IncludeRange] = 2,
10001014 [SeriesFunction.ExcludeRange] = 2,
1015+ [SeriesFunction.FilterNaN] = 1,
10011016 [SeriesFunction.UnwrapAngle] = 1,
10021017 [SeriesFunction.WrapAngle] = 1,
10031018 [SeriesFunction.Label] = 0
@@ -1235,6 +1250,13 @@ namespace GrafanaAdapters · 231 unmodified lines
12351250 if (filterMatch.Success)
12361251 return new Tuple<SeriesFunction, string, GroupOperation>(SeriesFunction.ExcludeRange, filterMatch.Result("${Expression}").Trim(), groupOperation);
12371252
1253+ // Look for filter NaN function
1254+ lock (s_filterNaNExpression)
1255+ filterMatch = s_filterNaNExpression.Match(expression);
1256+
1257+ if (filterMatch.Success)
1258+ return new Tuple<SeriesFunction, string, GroupOperation>(SeriesFunction.FilterNaN, filterMatch.Result("${Expression}").Trim(), groupOperation);
1259+
12381260 // Look for unwrap angle function
12391261 lock (s_unwrapAngleExpression)
12401262 filterMatch = s_unwrapAngleExpression.Match(expression);
@@ -1644,6 +1666,13 @@ namespace GrafanaAdapters · 403 unmodified lines
16441666 foreach (DataSourceValue dataValue in source.Where(dataValue => (lowInclusive ? dataValue.Value <= low : dataValue.Value < low) || (highInclusive ? dataValue.Value >= high : dataValue.Value > high)))
16451667 yield return dataValue;
16461668
1669+ break;
1670+ case SeriesFunction.FilterNaN:
1671+ bool alsoFilterInifinity = parameters.Length == 0 || parameters[0].Trim().ParseBoolean();
1672+
1673+ foreach (DataSourceValue dataValue in source.Where(dataValue => !(double.IsNaN(dataValue.Value) || (alsoFilterInifinity && double.IsInfinity(dataValue.Value)))))
1674+ yield return dataValue;
1675+
16471676 break;
16481677 case SeriesFunction.UnwrapAngle:
16491678 if (parameters.Length == 0 || !Enum.TryParse(parameters[0], true, out angleUnits))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t