dispel.providers.generic.tasks.cps.utils module#

A module containing functionality to process cps reaction time.

dispel.providers.generic.tasks.cps.utils.AV_REACTION_TIME = reaction time (rt)#

Abbreviation for the reaction time.

dispel.providers.generic.tasks.cps.utils.CPS_AGGREGATION_LIST: List[str] = ['mean', 'std', 'median', 'min', 'max', 'q95', 'q05', 'iqr', 'skew', 'kurtosis']#

The CPS aggregation in a single list format.

dispel.providers.generic.tasks.cps.utils.CPS_BASIC_AGGREGATION: List[Tuple[str, str]] = [('mean', 'mean'), ('std', 'standard deviation'), ('median', 'median'), ('min', 'minimum'), ('max', 'maximum'), ('q95', '95th percentile'), ('q05', '5th percentile'), ('iqr', 'iqr')]#

The basic aggregations that are used in the test.

dispel.providers.generic.tasks.cps.utils.CPS_EXTENDED_AGGREGATION: List[Tuple[str, str]] = [('mean', 'mean'), ('std', 'standard deviation'), ('median', 'median'), ('min', 'minimum'), ('max', 'maximum'), ('q95', '95th percentile'), ('q05', '5th percentile'), ('iqr', 'iqr'), ('skew', 'skewness'), ('kurtosis', 'kurtosis')]#

The extended aggregations that are used in the test.

dispel.providers.generic.tasks.cps.utils.CPS_SYMBOL_SPECIFIC_AGGREGATION: List[Tuple[str, str]] = [('mean', 'mean'), ('std', 'standard deviation'), ('median', 'median'), ('min', 'minimum'), ('max', 'maximum')]#

Symbol specific aggregation.

dispel.providers.generic.tasks.cps.utils.EXPECTED_DURATION_D2D = 20#

The expected duration of the digit-to-digit part.

dispel.providers.generic.tasks.cps.utils.EXPECTED_DURATION_S2D = 90#

The expected duration of the symbol-to-digit part.

dispel.providers.generic.tasks.cps.utils.EXTRA_MODALITY_LIST = ['unique', 'pair', 'l5', 'f5', '5lvs5f', 'third3third1']#

The modality to aggregate when merging key1 and key2.

dispel.providers.generic.tasks.cps.utils.LEVEL_DURATION_DEF = <ValueDefinition: levelDuration (expected level duration, s)>#

Expected level duration context value.

dispel.providers.generic.tasks.cps.utils.MINIMAL_N_DATA_POINTS = 3#

The # of data points for a measure below which we create flag.

dispel.providers.generic.tasks.cps.utils.agg_reaction_time(data, agg, key, lower=0, upper=None)[source]#

Aggregate reactionTime returned by correct_data_selection.

Parameters:
  • data (DataFrame) – A pandas.DataFrame obtained from a reading raw data set keys-analysis.

  • agg (str | AbbreviatedValue) – reaction time Aggregation

  • key (List[Any] | AbbreviatedValue | None) – key selection

  • lower (int | None) – The lower index to select of the data frame.

  • upper (int | None) – The upper index to select of the data frame.

Returns:

The aggregate reaction time wrapped into a WrappedResult class that contains flags generated during the computation.

Return type:

WrappedResult

dispel.providers.generic.tasks.cps.utils.compute_confusion_error_rate(data, val1, val2)[source]#

Compute the confusion rate.

The confusion rate is computed with respect to the two symbols or digits from the confusion matrix.

Parameters:
Returns:

Confusion error rate between the first and the second symbol/digit.

Return type:

numpy.float64

dispel.providers.generic.tasks.cps.utils.compute_confusion_matrix(data)[source]#

Compute the confusion matrix for each symbols/digits.

Parameters:

data (DataFrame) – A pandas data frame coming from dispel.providers.generic.tasks.cps.steps.TransformKeysAnalysisData.

Returns:

The confusion matrix for the current level.

Return type:

pandas.DataFrame

dispel.providers.generic.tasks.cps.utils.compute_correct_third_from_paired(data, subset, level, is_left)[source]#

Compute the number of correct responses for a specific third.

Parameters:
Return type:

int

dispel.providers.generic.tasks.cps.utils.compute_response_time_linear_regression(data, to_drop)[source]#

Compute a linear regression and extract slope coefficient and r2 score.

The linear regression is made on the reactionTime pandas.Series.

Parameters:
  • data (DataFrame) – The keys-analysis raw data frame.

  • to_drop (int) – The number of responses to drop at the beginning of the test.

Returns:

The slope coefficient and the r2 score of the model.

Return type:

Tuple[float, float]

dispel.providers.generic.tasks.cps.utils.compute_streak(frame)[source]#

Compute the longest streak of incorrect and correct responses.

Parameters:

frame (DataFrame) – A pandas.DataFrame obtained from a reading raw data set userInput.

Returns:

The longest streak of correct responses for a given level. And the longest streak of incorrect responses for a given level.

Return type:

Tuple[numpy.int64, numpy.int64]

dispel.providers.generic.tasks.cps.utils.correct_data_selection(data, lower=0, upper=None)[source]#

Select correct responses between two indexes of data.

Parameters:
  • data (DataFrame) – A pandas.DataFrame obtained from a reading raw data set keys-analysis.

  • lower (int | None) – The lower index to select of the data frame.

  • upper (int | None) – The upper index to select of the data frame.

Returns:

A pandas data frame containing only correct responses.

Return type:

pandas.DataFrame

dispel.providers.generic.tasks.cps.utils.get_subset_from_ts(data, lower, upper)[source]#

Select a subset of keys-analysis dataset based on timestamps.

Parameters:
Returns:

The filtered version of the input

Return type:

pd.DataFrame

dispel.providers.generic.tasks.cps.utils.get_third_data(data, subset, level)[source]#

Get the data for a particular third.

Parameters:
  • data (DataFrame) – The input key analysis dataset

  • subset (ThirdsModality) – The third modality

  • level (Level) – The current level to get the duration

Returns:

The filtered version of the input

Return type:

pd.DataFrame

dispel.providers.generic.tasks.cps.utils.linear_regression(data)[source]#

Compute a linear regression on a pandas.Series based on its index.

Parameters:

data (Series) – The pandas Series on which we desire to compute a linear regression.

Returns:

The model object resulting of the sklearn API.

Return type:

LinearRegression

dispel.providers.generic.tasks.cps.utils.reaction_time(data)[source]#

Compute the reaction time.

Parameters:

data (DataFrame) – The userInput data frame from the CPS task.

Returns:

A pandas Series containing the computed reaction time based on the difference between display time (tsDisplay) and response time (tsAnswer).

Return type:

pandas.Series

dispel.providers.generic.tasks.cps.utils.study2and3back(data)[source]#

Extract 1Back, 2Back and 3Back reaction time for correct responses only.

Parameters:

data (DataFrame) – A pandas data frame obtained from dispel.providers.generic.tasks.cps.steps.TransformKeysAnalysisData.

Returns:

a pandas data frame containing 1,2 and 3 back and current reaction time when each 1,2 or 3 back is displayed for a given level.

Return type:

pandas.DataFrame

dispel.providers.generic.tasks.cps.utils.transform_user_input(data, level)[source]#

Create a uniform data frame from user responses to perform analyses.

Parameters:
  • data (DataFrame) – A pandas data frame obtained from a reading raw data set userInput

  • level (Level) – The level to be processed

Raises:

ValueError – Make sure length between input data and transformed dataset are consistent

Returns:

The proper pandas data frame containing expect, actual ,``reactionTime`` and tsAnswer pandas.Series to perform the digits or symbols analyses.

Return type:

pandas.DataFrame