@m2c2kit/assessment-color-shapes 0.8.32 → 0.8.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ import { ActivityKeyValueData } from "@m2c2kit/core";
2
+ export declare const data: ActivityKeyValueData[][];
3
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/__tests__/data.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,eAAO,MAAM,IAAI,EAAE,oBAAoB,EAAE,EA2/DxC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const pythonCode = "\nimport numpy as np\nimport pandas as pd\nfrom typing import Dict, Any\n\ndef summarize_common_metadata(x: pd.DataFrame, trials_expected: int) -> Dict[str, Any]:\n \"\"\"\n Extract shared metadata and trial count checks from a grouped DataFrame.\n\n Args:\n x (pd.DataFrame): Grouped trial-level DataFrame.\n trials_expected (int): Expected number of trials.\n\n Returns:\n Dict[str, Any]: Summary metadata and quality flags.\n \"\"\"\n if \"trial_index\" in x.columns:\n n_trials = x[\"trial_index\"].nunique()\n else:\n # warnings.warn(\"No 'trial_index' column found; assuming single-trial task.\")\n # For single-trial tasks (like Trailmaking), treat as one trial\n n_trials = 1\n return {\n \"activity_begin_iso8601_timestamp\": x[\"activity_begin_iso8601_timestamp\"].iloc[\n 0\n ],\n \"n_trials\": n_trials,\n \"flag_trials_match_expected\": n_trials == trials_expected,\n \"flag_trials_lt_expected\": n_trials < trials_expected,\n \"flag_trials_gt_expected\": n_trials > trials_expected,\n }\n\ndef score_shapes(row: pd.Series, method=\"accuracy\"):\n \"\"\"Score a single row of a color shapes task dataframe based on the method given.\n\n Args:\n row (pd.Series):\n A single row of a color shapes task dataframe containing the columns \"user_response\" and \"user_response_correct\".\n method (str, optional):\n The scoring method to use. Defaults to \"accuracy\". Can be \"accuracy\" or \"signal\".\n\n Returns:\n (str | None):\n If method is \"accuracy\", returns \"CR\", \"MISS\", \"HIT\", or \"FA\".\n If method is \"signal\", returns \"SAME\" or \"DIFFERENT\".\n Otherwise, returns None.\n\n Raises:\n Exception:\n If an error occurs while processing the row.\n\n \"\"\"\n\n try:\n user_response_string = row[\"user_response\"]\n user_response_correct = row[\"user_response_correct\"]\n\n if user_response_string == \"same\" and user_response_correct:\n if method == \"accuracy\":\n return \"CR\" # Correct Rejection\n elif method == \"signal\":\n return \"SAME\"\n\n elif user_response_string == \"same\" and not user_response_correct:\n if method == \"accuracy\":\n return \"MISS\"\n elif method == \"signal\":\n return \"DIFFERENT\"\n\n elif user_response_string == \"different\" and user_response_correct:\n if method == \"accuracy\":\n return \"HIT\"\n elif method == \"signal\":\n return \"DIFFERENT\"\n\n elif user_response_string == \"different\" and not user_response_correct:\n if method == \"accuracy\":\n return \"FA\" # False Alarm\n elif method == \"signal\":\n return \"SAME\"\n\n else:\n # Return None on unexpected response combinations\n print(\n f\"Unexpected response combination: user_response='{user_response_string}', user_response_correct='{user_response_correct}'\"\n )\n return None\n\n except Exception as e:\n print(f\"Error processing row: {e}\")\n return None\n\n\ndef score_accuracy(row):\n \"\"\"\n Scores the accuracy of the response for a single trial in the Color Shapes task.\n\n Args:\n row (pd.Series): A single row of the trial-level Color Shapes task dataframe.\n\n Returns:\n (str | None):\n A string indicating the accuracy of the response, such as \"CR\" for Correct Rejection,\n \"MISS\", \"HIT\", or \"FA\" for False Alarm, based on the scoring criteria.\n None is returned if an error occurs while processing the row.\n \"\"\"\n\n return score_shapes(row, method=\"accuracy\")\n\n\ndef score_signal(row):\n \"\"\"\n Scores the signal type of the response for a single trial in the Color Shapes task.\n\n Args:\n row (pd.Series): A single row of the trial-level Color Shapes task dataframe.\n\n Returns:\n (str | None): A string indicating the signal type of the response, either \"SAME\" or \"DIFFERENT\",\n based on the scoring criteria.\n None is returned if an error occurs while processing the row.\n \"\"\"\n\n return score_shapes(row, method=\"signal\")\n\n\ndef summarize(x, trials_expected=10, rt_outlier_low=100, rt_outlier_high=10000):\n \"\"\"\n Summarizes the Color Shapes task data by calculating various statistics.\n\n This function calculates the number of hits, misses, false alarms, and correct rejections\n based on the accuracy of responses in the Color Shapes task. It computes signal detection\n rates and evaluates response times, filtering out null, invalid, and outlier values.\n\n Args:\n x (pd.DataFrame): The trial-level scored dataset for the Color Shapes task.\n trials_expected (int, optional): The expected number of trials. Defaults to 10.\n rt_outlier_low (int, optional): The lower bound for filtering outliers in response times. Defaults to 100.\n rt_outlier_high (int, optional): The upper bound for filtering outliers in response times. Defaults to 10000.\n\n Returns:\n (pd.Series): A Pandas Series containing the summary statistics for the Color Shapes task.\n \"\"\"\n\n d = summarize_common_metadata(x, trials_expected)\n \n # Number of accuracy hits, misses, false alarms, and correct rejections\n for metric in [\"HIT\", \"MISS\", \"FA\", \"CR\"]:\n d[f\"n_trials_{metric}\"] = (x[\"metric_accuracy\"] == metric).sum()\n\n # Number of each trial type\n d[\"n_trials_type_same\"] = (x[\"metric_trial_type\"] == \"SAME\").sum()\n d[\"n_trials_type_different\"] = (x[\"metric_trial_type\"] == \"DIFFERENT\").sum()\n\n # Signal Detection Rates - with safe division for zero trial types\n if d[\"n_trials_type_different\"] > 0:\n d[\"HIT_rate\"] = d[\"n_trials_HIT\"] / d[\"n_trials_type_different\"]\n d[\"MISS_rate\"] = 1 - d[\"HIT_rate\"]\n else:\n d[\"HIT_rate\"] = np.nan\n d[\"MISS_rate\"] = np.nan\n\n if d[\"n_trials_type_same\"] > 0:\n d[\"FA_rate\"] = d[\"n_trials_FA\"] / d[\"n_trials_type_same\"]\n d[\"CR_rate\"] = 1 - d[\"FA_rate\"]\n else:\n d[\"FA_rate\"] = np.nan\n d[\"CR_rate\"] = np.nan\n\n # Response Times - Handle null/invalid response times first\n valid_rt_mask = pd.notna(x[\"response_time_duration_ms\"]) & (\n x[\"response_time_duration_ms\"] > 0\n )\n valid_rt_data = x.loc[valid_rt_mask, \"response_time_duration_ms\"]\n\n # Number of trials that had null/invalid response times\n d[\"n_trials_rt_invalid\"] = (\n x[\"response_time_duration_ms\"].shape[0] - valid_rt_data.shape[0]\n )\n\n # Overall Response Times (nulls/invalid removed only)\n d[\"median_rt_overall_valid\"] = valid_rt_data.median()\n d[\"sd_rt_overall_valid\"] = valid_rt_data.std()\n\n # Response Times by accuracy type (nulls/invalid removed only)\n for metric in [\"HIT\", \"MISS\", \"FA\", \"CR\"]:\n metric_mask = (x[\"metric_accuracy\"] == metric) & valid_rt_mask\n rt_signal = x.loc[metric_mask, \"response_time_duration_ms\"]\n d[f\"median_rt_{metric}_valid\"] = rt_signal.median()\n d[f\"sd_rt_{metric}_valid\"] = rt_signal.std()\n\n # Filtered Overall Response Times (nulls/invalid and outliers removed)\n rt_filtered_overall = x.loc[\n valid_rt_mask\n & (x[\"response_time_duration_ms\"] >= rt_outlier_low)\n & (x[\"response_time_duration_ms\"] <= rt_outlier_high),\n \"response_time_duration_ms\",\n ]\n d[\"median_rt_overall_valid_filtered\"] = rt_filtered_overall.median()\n d[\"sd_rt_overall_valid_filtered\"] = rt_filtered_overall.std()\n\n # Count of outliers filtered out\n d[\"n_outliers_rt_overall_valid\"] = (\n valid_rt_data.shape[0] - rt_filtered_overall.shape[0]\n )\n\n # Filtered Response Times by accuracy type (nulls/invalid and outliers removed)\n for metric in [\"HIT\", \"MISS\", \"FA\", \"CR\"]:\n metric_mask = (x[\"metric_accuracy\"] == metric) & valid_rt_mask\n rt_filtered_signal = x.loc[\n metric_mask\n & (x[\"response_time_duration_ms\"] >= rt_outlier_low)\n & (x[\"response_time_duration_ms\"] <= rt_outlier_high),\n \"response_time_duration_ms\",\n ]\n d[f\"median_rt_{metric}_valid_filtered\"] = rt_filtered_signal.median()\n d[f\"sd_rt_{metric}_valid_filtered\"] = rt_filtered_signal.std()\n\n # Count of outliers filtered out per accuracy type\n metric_rt_data = x.loc[metric_mask, \"response_time_duration_ms\"]\n d[f\"n_outliers_rt_{metric}_valid\"] = (\n metric_rt_data.shape[0] - rt_filtered_signal.shape[0]\n )\n\n return pd.Series(d)\n";
2
+ //# sourceMappingURL=python-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"python-code.d.ts","sourceRoot":"","sources":["../../src/__tests__/python-code.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,m5RAiOtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=scoring.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/scoring.test.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ declare class ColorShapes extends Game implements ScoringProvider {
8
8
  constructor();
9
9
  initialize(): Promise<void>;
10
10
  calculateScores(data: ActivityKeyValueData[], extras: {
11
+ rtLowerBound: number;
12
+ rtUpperBound: number;
11
13
  numberOfTrials: number;
12
14
  }): import("@m2c2kit/data-calc").Observation[];
13
15
  private makeShapes;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAmBJ,eAAe,EACf,oBAAoB,EAErB,MAAM,eAAe,CAAC;AAWvB;;;;GAIG;AACH,cAAM,WAAY,SAAQ,IAAK,YAAW,eAAe;;IAibxC,UAAU;IAioBzB,eAAe,CACb,IAAI,EAAE,oBAAoB,EAAE,EAC5B,MAAM,EAAE;QACN,cAAc,EAAE,MAAM,CAAC;KACxB;IA6BH,OAAO,CAAC,UAAU;CA+EnB;AAaD,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAmBJ,eAAe,EACf,oBAAoB,EAErB,MAAM,eAAe,CAAC;AAmBvB;;;;GAIG;AACH,cAAM,WAAY,SAAQ,IAAK,YAAW,eAAe;;IAmoBxC,UAAU;IA6oBzB,eAAe,CACb,IAAI,EAAE,oBAAoB,EAAE,EAC5B,MAAM,EAAE;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;KACxB;IAsUH,OAAO,CAAC,UAAU;CA+EnB;AAaD,OAAO,EAAE,WAAW,EAAE,CAAC"}