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
50* [Interval](#interval)50* [Interval](#interval)
51* [IncludeRange](#includerange)51* [IncludeRange](#includerange)
52* [ExcludeRange](#excluderange)52* [ExcludeRange](#excluderange)
53* [FilterNaN](#filternan)
53* [UnwrapAngle](#unwrapangle)54* [UnwrapAngle](#unwrapangle)
54* [WrapAngle](#wrapangle)55* [WrapAngle](#wrapangle)
55* [Label](#label)56* [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
342* Variants: `ExcludeRange`, `Exclude`343* Variants: `ExcludeRange`, `Exclude`
343* Execution: Deferred enumeration344* Execution: Deferred enumeration
344 345
346## FilterNaN
347
348Returns 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
345## UnwrapAngle355## UnwrapAngle
346 356
347Returns 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.357Returns 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
378 /// </remarks>378 /// </remarks>
379 ExcludeRange,379 ExcludeRange,
380 /// <summary>380 /// <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>
381 /// Returns a series of values that represent an adjusted set of angles that are unwrapped, per specified angle units, so that a comparable mathematical392 /// Returns a series of values that represent an adjusted set of angles that are unwrapped, per specified angle units, so that a comparable mathematical
382 /// operation can be executed. For example, for angles that wrap between -180 and +180 degrees, this algorithm unwraps the values to make the values393 /// operation can be executed. For example, for angles that wrap between -180 and +180 degrees, this algorithm unwraps the values to make the values
383 /// mathematically comparable. The units parameter, optional, specifies the type of angle units and must be one of the following: Degrees, Radians, Grads,394 /// 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
876 private static readonly Regex s_intervalExpression;887 private static readonly Regex s_intervalExpression;
877 private static readonly Regex s_includeRangeExpression;888 private static readonly Regex s_includeRangeExpression;
878 private static readonly Regex s_excludeRangeExpression;889 private static readonly Regex s_excludeRangeExpression;
890 private static readonly Regex s_filterNaNExpression;
879 private static readonly Regex s_unwrapAngleExpression;891 private static readonly Regex s_unwrapAngleExpression;
880 private static readonly Regex s_wrapAngleExpression;892 private static readonly Regex s_wrapAngleExpression;
881 private static readonly Regex s_labelExpression;893 private static readonly Regex s_labelExpression;
@@ -923,6 +935,7 @@ namespace GrafanaAdapters · 41 unmodified lines
923 s_intervalExpression = new Regex(string.Format(GetExpression, "Interval"), RegexOptions.Compiled | RegexOptions.IgnoreCase);935 s_intervalExpression = new Regex(string.Format(GetExpression, "Interval"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
924 s_includeRangeExpression = new Regex(string.Format(GetExpression, "(IncludeRange|Include)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);936 s_includeRangeExpression = new Regex(string.Format(GetExpression, "(IncludeRange|Include)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
925 s_excludeRangeExpression = new Regex(string.Format(GetExpression, "(ExcludeRange|Exclude)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);937 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);
926 s_unwrapAngleExpression = new Regex(string.Format(GetExpression, "(UnwrapAngle|Unwrap)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);939 s_unwrapAngleExpression = new Regex(string.Format(GetExpression, "(UnwrapAngle|Unwrap)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
927 s_wrapAngleExpression = new Regex(string.Format(GetExpression, "(WrapAngle|Wrap)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);940 s_wrapAngleExpression = new Regex(string.Format(GetExpression, "(WrapAngle|Wrap)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
928 s_labelExpression = new Regex(string.Format(GetExpression, "(Label|Name)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);941 s_labelExpression = new Regex(string.Format(GetExpression, "(Label|Name)"), RegexOptions.Compiled | RegexOptions.IgnoreCase);
@@ -960,6 +973,7 @@ namespace GrafanaAdapters · 31 unmodified lines
960 [SeriesFunction.Interval] = 1,973 [SeriesFunction.Interval] = 1,
961 [SeriesFunction.IncludeRange] = 2,974 [SeriesFunction.IncludeRange] = 2,
962 [SeriesFunction.ExcludeRange] = 2,975 [SeriesFunction.ExcludeRange] = 2,
976 [SeriesFunction.FilterNaN] = 0,
963 [SeriesFunction.UnwrapAngle] = 0,977 [SeriesFunction.UnwrapAngle] = 0,
964 [SeriesFunction.WrapAngle] = 0,978 [SeriesFunction.WrapAngle] = 0,
965 [SeriesFunction.Label] = 1979 [SeriesFunction.Label] = 1
@@ -998,6 +1012,7 @@ namespace GrafanaAdapters · 32 unmodified lines
998 [SeriesFunction.Interval] = 0,1012 [SeriesFunction.Interval] = 0,
999 [SeriesFunction.IncludeRange] = 2,1013 [SeriesFunction.IncludeRange] = 2,
1000 [SeriesFunction.ExcludeRange] = 2,1014 [SeriesFunction.ExcludeRange] = 2,
1015 [SeriesFunction.FilterNaN] = 1,
1001 [SeriesFunction.UnwrapAngle] = 1,1016 [SeriesFunction.UnwrapAngle] = 1,
1002 [SeriesFunction.WrapAngle] = 1,1017 [SeriesFunction.WrapAngle] = 1,
1003 [SeriesFunction.Label] = 01018 [SeriesFunction.Label] = 0
@@ -1235,6 +1250,13 @@ namespace GrafanaAdapters · 231 unmodified lines
1235 if (filterMatch.Success)1250 if (filterMatch.Success)
1236 return new Tuple<SeriesFunction, string, GroupOperation>(SeriesFunction.ExcludeRange, filterMatch.Result("${Expression}").Trim(), groupOperation);1251 return new Tuple<SeriesFunction, string, GroupOperation>(SeriesFunction.ExcludeRange, filterMatch.Result("${Expression}").Trim(), groupOperation);
1237 1252
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
1238 // Look for unwrap angle function1260 // Look for unwrap angle function
1239 lock (s_unwrapAngleExpression)1261 lock (s_unwrapAngleExpression)
1240 filterMatch = s_unwrapAngleExpression.Match(expression);1262 filterMatch = s_unwrapAngleExpression.Match(expression);
@@ -1644,6 +1666,13 @@ namespace GrafanaAdapters · 403 unmodified lines
1644 foreach (DataSourceValue dataValue in source.Where(dataValue => (lowInclusive ? dataValue.Value <= low : dataValue.Value < low) || (highInclusive ? dataValue.Value >= high : dataValue.Value > high)))1666 foreach (DataSourceValue dataValue in source.Where(dataValue => (lowInclusive ? dataValue.Value <= low : dataValue.Value < low) || (highInclusive ? dataValue.Value >= high : dataValue.Value > high)))
1645 yield return dataValue;1667 yield return dataValue;
1646 1668
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
1647 break;1676 break;
1648 case SeriesFunction.UnwrapAngle:1677 case SeriesFunction.UnwrapAngle:
1649 if (parameters.Length == 0 || !Enum.TryParse(parameters[0], true, out angleUnits))1678 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