follows_reference¶
- typhoon.test.signals.follows_reference(signal, ref_signal, tol, during=None, strictness=1, time_tol=0, report_plot=None)¶
Checks if signal follows a reference signal within given tolerances.
Note
The reference signal needs not to be on the same sampling rate of the signal to be compared, as they will be normalized in a single dataframe using pandas interpolate https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.interpolate.html function.
- Parameters:
signal (pandas.Series) – Signal to be tested for.
ref_signal (pandas.Series) – Reference signal the tested signal should follow.
tol (float) – Tolerance around which the signal can stay with respect to reference signal when determining if analyis result is
True
orFalse
.during (tuple) – Time period (as a range) to be considered for analysis.
strictness (float) – Number between 0.0 and 1.0 that determines percentage of time signal should be inside the defined range for test to pass.
time_tol (float or timedelta) – Time tolerance - argument which allows that signal is leading or lagging up to specified time in seconds, compared to created reference.
report_plot (dict) –
Dictionary which overrides default allure report plot attachment behaviour. It also overrides behaviour specified for whole test run with command line arguments
--analysis-plot-type
and--analysis-plot-on-fail-only
. Dictionary has two keys to be specified:type
: specifies which kind of allure plot should be used. Valid values:static
- only matplotlib plot attached as .png picture is attachedinteractive
- only interactive html plot created with bokeh library is attached. Advantage of this plot it has options to zoom in/zoom out. Disadvantage is that it consumes significantly more memory.none
- none of the plots will be attachedall
- all plots will be added. Currently supported ones are matplotlib plot(static) and bokeh plot(interactive)
when
: specifies when to add plots that are specified with previous key to report. Available options:always
- always adds specified plotson-fail
- adds plots only if comparison of reference and measured signal fails. This is good way to decrease size of allure plots.
Note
If
report_plot
argument is not provided, and command line arguments--analysis-plot-type
andanalysis-plot-on-fail-only
are not specified, default behaviour is static plot, attached always. If command line arguments are specified, they define new default behaviour for whole test run.
- Returns:
result – Result of the analysis.
- Return type:
AnalysisResult
Notes
The reference signal needs not to be on the same sampling rate of the signal to be compared, as they will be normalized in a single dataframe using pandas’ interpolate <https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.interpolate.html> function.
Examples
Considering
signal
as part of a captured dataframe>>> signal = capture["channel"]
Implementing a
typhoon.test.signals.is_constant
function, comparing if the signal is always around 10 ± 0.5>>> import pandas as pd >>> from typhoon.test.signals import follows_reference >>> >>> ref = 10 >>> tol = .5 >>> >>> ref_signal = pd.Series({ >>> signal.index[0]: ref, >>> signal.index[-1]: ref >>> }) >>> >>> result = follows_reference(signal, ref_signal, tol)
Implementing a
typhoon.test.signals.is_ramp
function with a slope of one unit per second (slope = 1
)>>> from typhoon.types.timedelta import Timedelta as td >>> >>> dt = signal.index[-1] - signal.index[0] >>> >>> initial_value = signal.values[0] >>> # Equivalent to dt * (slope/dtbase) e.g. slope with 100 units per microsecond y = 10 + (1us * 100/1us) = 110 >>> vf = initial_value + dt/td("1s")*slope >>> >>> # Build signal with two points, providing ramp >>> ref_signal = pd.Series({ >>> signal.index[0]:initial_value, >>> signal.index[-1]:vf >>> }) >>> result = follows_reference(signal, ref_signal, tol=0.5)
See also
typhoon.test.signals.AnalysisResult
,typhoon.test.signals.assert_follows_reference
,typhoon.test.signals.is_ramp
,typhoon.test.signals.is_constant