{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "245 valid participants\n",
      "{'control': 61, 'dashboard': 61, 'chatxai': 62, 'chatxaiboost': 61, 'chatxaiAuto': 0}\n",
      "91 participants blindly rely on AI advice\n",
      "{'control': 8, 'dashboard': 27, 'chatxai': 32, 'chatxaiboost': 24, 'chatxaiAuto': 0}\n",
      "61 valid participants\n",
      "{'control': 0, 'dashboard': 0, 'chatxai': 0, 'chatxaiboost': 0, 'chatxaiAuto': 61}\n",
      "25 participants blindly rely on AI advice\n",
      "{'control': 0, 'dashboard': 0, 'chatxai': 0, 'chatxaiboost': 0, 'chatxaiAuto': 25}\n",
      "(306, 4)\n"
     ]
    }
   ],
   "source": [
    "from util import load_user_data\n",
    "import pandas as pd\n",
    "import sys\n",
    "import numpy as np\n",
    "\n",
    "valid_users, tp_data, _ = load_user_data(filename=\"../data/xailabdata_all.csv\")\n",
    "valid_users_2, tp_data_2, _ = load_user_data(filename=\"../data/xailabdata_llm_agent.csv\")\n",
    "\n",
    "valid_users = valid_users | valid_users_2\n",
    "tp_data.update(tp_data_2)\n",
    "variable_dict = {}\n",
    "variable_dict[\"condition\"] = []\n",
    "dimensions = [\"Reliability/Competence\", \"Understandability/Predictability\", \"Trust in Automation\"]\n",
    "for dimension in dimensions:\n",
    "    variable_dict[dimension] = []\n",
    "for user in valid_users:\n",
    "    tp_condition = tp_data[user][\"condition\"]\n",
    "    trust = tp_data[user][\"Trust_in_automation\"]\n",
    "    variable_dict[\"condition\"].append(tp_condition)\n",
    "    for dimension in dimensions:\n",
    "        variable_dict[dimension].append(trust[dimension])\n",
    "\n",
    "df = pd.DataFrame(variable_dict)\n",
    "print(df.shape)\n",
    "\n",
    "condition_map = {\n",
    "    \"control\": \"Control\",\n",
    "    \"dashboard\": \"Dashboard\",\n",
    "    \"chatxai\": \"CXAI\",\n",
    "    \"chatxaiboost\": \"ECXAI\",\n",
    "    \"chatxaiAuto\": \"LLM Agent\"\n",
    "}\n",
    "df[\"condition\"] = df[\"condition\"].map(condition_map)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/dabest/plotter.py:473: FutureWarning: Passing `palette` without assigning `hue` is deprecated.\n",
      "  rawdata_plot = sns.swarmplot(data=plot_data, x=xvar, y=yvar,\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/dabest/plotter.py:563: UserWarning: FixedFormatter should only be used together with FixedLocator\n",
      "  rawdata_axes.set_xticklabels(ticks_with_counts)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/dabest/plotter.py:473: FutureWarning: Passing `palette` without assigning `hue` is deprecated.\n",
      "  rawdata_plot = sns.swarmplot(data=plot_data, x=xvar, y=yvar,\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 12.9% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/dabest/plotter.py:563: UserWarning: FixedFormatter should only be used together with FixedLocator\n",
      "  rawdata_axes.set_xticklabels(ticks_with_counts)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/dabest/plotter.py:473: FutureWarning: Passing `palette` without assigning `hue` is deprecated.\n",
      "  rawdata_plot = sns.swarmplot(data=plot_data, x=xvar, y=yvar,\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 6.6% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 14.8% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 25.8% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 18.0% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 9.8% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/dabest/plotter.py:563: UserWarning: FixedFormatter should only be used together with FixedLocator\n",
      "  rawdata_axes.set_xticklabels(ticks_with_counts)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 90692 characters]",
      "text/plain": [
       "<Figure size 750x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 16.1% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 86024 characters]",
      "text/plain": [
       "<Figure size 750x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 14.8% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 18.0% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 29.0% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n",
      "/Users/ghe/opt/anaconda3/envs/agreement_phi/lib/python3.8/site-packages/seaborn/categorical.py:3544: UserWarning: 21.3% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.\n",
      "  warnings.warn(msg, UserWarning)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 76040 characters]",
      "text/plain": [
       "<Figure size 750x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import dabest\n",
    "# df[\"condition\"].unique()\n",
    "for dimension in dimensions:\n",
    "    four_groups_unpaired = dabest.load(df, x=\"condition\", idx=[\"Control\", \"Dashboard\", \"CXAI\", \"ECXAI\", \"LLM Agent\"], y=dimension, resamples=5000, ci=95, x1_level=[\"Control\", \"Dashboard\", \"CXAI\", \"PCXAI\"])\n",
    "    four_groups_unpaired.mean_diff.plot();"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "agreement_phi",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
