{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c728bcb8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "import os\n",
    "\n",
    "# Basic configuration\n",
    "DVs = ['Aes', 'Liking', 'Pawe', 'Tawe', 'PF']\n",
    "\n",
    "num_stimuli = 234\n",
    "stim_ids_master = [f\"WF{i:03d}\" for i in range(1, num_stimuli + 1)]\n",
    "\n",
    "# 3 quantity × 3 size conditions\n",
    "quantities = ['individual', 'medium', 'large']\n",
    "sizes = ['300', '900', '1500']\n",
    "\n",
    "conditions = [\n",
    "    f\"_{q}_{s}\"\n",
    "    for q in quantities\n",
    "    for s in sizes\n",
    "]\n",
    "\n",
    "num_repeats = 20\n",
    "\n",
    "# Create output folder\n",
    "output_folder = \"./moduleStimuli\"\n",
    "os.makedirs(output_folder, exist_ok=True)\n",
    "\n",
    "def generate_modules_all_dvs(repeat_num):\n",
    "    stim_ids = stim_ids_master[:]\n",
    "    random.shuffle(stim_ids)\n",
    "\n",
    "    # 234 / 9 = 26 images per group\n",
    "    groups = [\n",
    "        stim_ids[i * 26:(i + 1) * 26]\n",
    "        for i in range(9)\n",
    "    ]\n",
    "\n",
    "    for dv in DVs:\n",
    "\n",
    "        # 9 modules\n",
    "        for m in range(9):\n",
    "            assignment = []\n",
    "\n",
    "            # rotate condition assignment\n",
    "            for group_idx, group in enumerate(groups):\n",
    "                cond_idx = (group_idx + m) % 9\n",
    "                condition = conditions[cond_idx]\n",
    "\n",
    "                assignment += [\n",
    "                    stim + condition\n",
    "                    for stim in group\n",
    "                ]\n",
    "\n",
    "            filename = os.path.join(\n",
    "                output_folder,\n",
    "                f\"{dv}_Module_{repeat_num}-{m}.txt\"\n",
    "            )\n",
    "\n",
    "            with open(filename, \"w\") as f:\n",
    "                for i, stim in enumerate(assignment):\n",
    "                    if i < len(assignment) - 1:\n",
    "                        f.write(f\"{stim}\\n\")\n",
    "                    else:\n",
    "                        f.write(f\"{stim}\")\n",
    "\n",
    "# Main loop\n",
    "for rep in range(num_repeats):\n",
    "    generate_modules_all_dvs(rep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1bcdddce",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import random\n",
    "\n",
    "input_folder = \"moduleStimuli\"\n",
    "output_file = \"BackEnd_CurrentCount.txt\"\n",
    "\n",
    "filenames = [\n",
    "    f[:-4]\n",
    "    for f in os.listdir(input_folder)\n",
    "    if f.endswith(\".txt\") and f != \"BackEnd_CurrentCount.txt\"\n",
    "]\n",
    "\n",
    "random.shuffle(filenames)\n",
    "\n",
    "with open(output_file, \"w\") as f:\n",
    "    for i, name in enumerate(filenames):\n",
    "        if i < len(filenames) - 1:\n",
    "            f.write(f\"{name} 0\\n\")\n",
    "        else:\n",
    "            f.write(f\"{name} 0\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "dc0047af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved 2083 entries to imageList.txt\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "image_dir = \"images\"\n",
    "output_file = \"imageList.txt\"\n",
    "\n",
    "files = sorted(\n",
    "    [f for f in os.listdir(image_dir)\n",
    "     if f.lower().endswith(\".jpg\")]\n",
    ")\n",
    "\n",
    "with open(output_file, \"w\") as f:\n",
    "    for filename in files:\n",
    "        f.write(f\"{filename} 0\\n\")\n",
    "\n",
    "print(f\"Saved {len(files)} entries to {output_file}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "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.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
