{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                          file_name  log_prob_drop_k1  log_prob_drop_k3  \\\n",
      "0  qwen_hotpot_contextcite_niter_60         -0.358600         -0.756189   \n",
      "1        qwen_hotpot_loo_nsamples_1         -0.881078         -1.106596   \n",
      "2          qwen_hotpot_mab_niter_60         -0.780832         -1.126849   \n",
      "3         qwen_hotpot_shap_niter_60         -0.821914         -1.075006   \n",
      "\n",
      "   log_prob_drop_k5  bertscore_k1  bertscore_k3  bertscore_k5  \n",
      "0         -0.841262      0.805591      0.664302      0.567211  \n",
      "1         -1.198811      0.685671      0.544300      0.589838  \n",
      "2         -1.179380      0.631742      0.526313      0.591273  \n",
      "3         -1.230376      0.702653      0.642099      0.589832  \n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import glob\n",
    "import os\n",
    "\n",
    "# Get all CSV files from results directory\n",
    "csv_files = glob.glob('results/qwen*cnn*.csv')\n",
    "csv_files.sort()\n",
    "\n",
    "# Create an empty list to store results\n",
    "all_means = []\n",
    "\n",
    "# Process each file\n",
    "for file_path in csv_files:\n",
    "    # Read the CSV file\n",
    "    df = pd.read_csv(file_path)\n",
    "    \n",
    "    # Calculate means\n",
    "    means = df.mean()\n",
    "    \n",
    "    # Get file name without path and extension\n",
    "    file_name = os.path.basename(file_path).replace('.csv', '')\n",
    "    \n",
    "    # Add file name to the means series\n",
    "    means['file_name'] = file_name\n",
    "    \n",
    "    # Append to results list\n",
    "    all_means.append(means)\n",
    "\n",
    "# Create a DataFrame from all results\n",
    "summary_df = pd.DataFrame(all_means)\n",
    "\n",
    "# Reorder columns to put file_name first\n",
    "cols = summary_df.columns.tolist()\n",
    "cols.remove('file_name')\n",
    "cols.insert(0, 'file_name')\n",
    "summary_df = summary_df[cols]\n",
    "\n",
    "# Display the summary table\n",
    "print(summary_df)\n",
    "\n",
    "# # Optionally save to CSV\n",
    "summary_df.to_csv('summary_means.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>file_name</th>\n",
       "      <th>log_prob_drop_k1</th>\n",
       "      <th>log_prob_drop_k3</th>\n",
       "      <th>log_prob_drop_k5</th>\n",
       "      <th>bertscore_k1</th>\n",
       "      <th>bertscore_k3</th>\n",
       "      <th>bertscore_k5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>qwen_hotpot_contextcite_niter_60</td>\n",
       "      <td>-0.358600</td>\n",
       "      <td>-0.756189</td>\n",
       "      <td>-0.841262</td>\n",
       "      <td>0.805591</td>\n",
       "      <td>0.664302</td>\n",
       "      <td>0.567211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>qwen_hotpot_loo_nsamples_1</td>\n",
       "      <td>-0.881078</td>\n",
       "      <td>-1.106596</td>\n",
       "      <td>-1.198811</td>\n",
       "      <td>0.685671</td>\n",
       "      <td>0.544300</td>\n",
       "      <td>0.589838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>qwen_hotpot_mab_niter_60</td>\n",
       "      <td>-0.780832</td>\n",
       "      <td>-1.126849</td>\n",
       "      <td>-1.179380</td>\n",
       "      <td>0.631742</td>\n",
       "      <td>0.526313</td>\n",
       "      <td>0.591273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>qwen_hotpot_shap_niter_60</td>\n",
       "      <td>-0.821914</td>\n",
       "      <td>-1.075006</td>\n",
       "      <td>-1.230376</td>\n",
       "      <td>0.702653</td>\n",
       "      <td>0.642099</td>\n",
       "      <td>0.589832</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          file_name  log_prob_drop_k1  log_prob_drop_k3  \\\n",
       "0  qwen_hotpot_contextcite_niter_60         -0.358600         -0.756189   \n",
       "1        qwen_hotpot_loo_nsamples_1         -0.881078         -1.106596   \n",
       "2          qwen_hotpot_mab_niter_60         -0.780832         -1.126849   \n",
       "3         qwen_hotpot_shap_niter_60         -0.821914         -1.075006   \n",
       "\n",
       "   log_prob_drop_k5  bertscore_k1  bertscore_k3  bertscore_k5  \n",
       "0         -0.841262      0.805591      0.664302      0.567211  \n",
       "1         -1.198811      0.685671      0.544300      0.589838  \n",
       "2         -1.179380      0.631742      0.526313      0.591273  \n",
       "3         -1.230376      0.702653      0.642099      0.589832  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "summary_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch",
   "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.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
