|
Download README.md from princessamygdala/TreasureHuntForTwo: direct link, hf CLI and curl.
- Browser
- Download file 7.46 kB
-
https://huggingface.co/spaces/princessamygdala/TreasureHuntForTwo/resolve/main/README.md
- Command line
-
hf download hf://spaces/princessamygdala/TreasureHuntForTwo/README.md
-
curl -L -o README.md https://huggingface.co/spaces/princessamygdala/TreasureHuntForTwo/resolve/main/README.md
7.46 kB
| title: TreasureHuntForTwo | |
| emoji: 🗺️ | |
| colorFrom: green | |
| colorTo: blue | |
| sdk: docker | |
| app_port: 7860 | |
| pinned: false | |
| # TreasureHuntForTwo | |
| A child-friendly (ages ~10–17), Minecraft-styled reimplementation of a **social | |
| reinforcement-learning / decision task**, built on **NiceWebRL** (JAX env + NiceGUI web | |
| app). The player explores a world, enters houses, and opens treasure chests. Each chest | |
| pays coins to **both the player and a "partner"**, another young person from a community | |
| database who does **not** play but earns a real bonus from the player's choices. The task | |
| measures how the player learns to trade off self vs. partner rewards (used in research on | |
| callous–unemotional traits). | |
| > **Codebook:** every output column is documented in **[CODEBOOK.md](CODEBOOK.md)**. | |
| --- | |
| ## The task | |
| - **4 reward profiles**, attached to abstract options **A / B / C / D**: | |
| | Option | You | Partner | | |
| |--------|-----|---------| | |
| | A | good | good | | |
| | B | good | bad | | |
| | C | bad | good | | |
| | D | bad | bad | | |
| *good* profile = **12 gain / 2 loss / 2 neutral** over the 16 trials; *bad* = **2 gain / | |
| 12 loss / 2 neutral**. Counts are **exact** per option, per recipient (not probabilistic). | |
| A gain shows **+10 coins**, a loss **−10**, neutral **0**. | |
| - **12 houses.** The 6 option-pairs (AB, AC, AD, BC, BD, CD) each appear **twice**. Each | |
| house = one pair, presented as **two distinct chests**, repeated for **16 trials**, after | |
| which the player rates which chest they preferred (0–6). Both the self **and** partner | |
| outcome are shown **simultaneously** every trial. | |
| - **Practice:** one extra house (a "forest hut", the AB pair, 5 trials) with rotating | |
| teaching tips, before the main 12. | |
| - **Chests as stimuli.** There are **24** procedurally-drawn chests (+2 practice-only), | |
| unique by **colour × material × lid shape**. Each participant is assigned **4 | |
| distinct-coloured** chests to the profiles A/B/C/D, the look is an arbitrary, randomised | |
| label (like the fractals in the original task). | |
| --- | |
| ## Participant IDs & counterbalancing | |
| The **participant ID encodes the group and *is* the randomisation seed**, everything about | |
| a session is reproducible from the ID. | |
| ``` | |
| ID = <group digit><number> e.g. 0003 -> group 0 (control/healthy), participant 3 | |
| 1007 -> group 1 (CU), participant 7 | |
| ``` | |
| - Group **0 = control/healthy**, **1 = CU**. Target **55 per group**. | |
| - From the ID, `orders.py` deterministically draws: the 4 chest stimuli, which pair→house, | |
| house positions, left/right side per trial, and the exact outcome sequences. Same ID → | |
| identical session, every time. **`next_id.py`** tells you the next ID to assign per group. | |
| - A one-row-per-participant **`randomization_log.csv`** is written to GitLab (see below). | |
| > ⚠️ **Freeze `orders.py` once real data collection begins.** Changing it would change the | |
| > randomisation derived from each ID. (The exported CSV derives box/house assignment from | |
| > the *logged* data, so trial-level records stay correct regardless, but keep it frozen to | |
| > be safe.) | |
| --- | |
| ## Run locally | |
| ```bash | |
| cd TreasureHuntForTwo | |
| export PATH="$HOME/.local/bin:$PATH" # uv | |
| uv sync # first time only | |
| uv run python web_app.py # serves http://localhost:8082 | |
| ``` | |
| Open `http://localhost:8082/?pid=0003` to pre-fill an ID and skip the experimenter screen. | |
| **Controls:** **← / →** choose a chest, **Space** continues past the outcome and the rating. | |
| A floating **"Take a break"** button (main task only) pauses the game. | |
| ### Dev / pilot shortcuts (URL params) | |
| Add `&dev=1` to enable, then skip ahead, sessions get a red **DEV MODE** banner and are | |
| flagged in the data (`dev_mode=1`) so they never pollute the real dataset: | |
| | URL | Jumps to | | |
| |-----|----------| | |
| | `?pid=9001&dev=1&start=main` | straight into the 12 houses (skip intro + practice + quiz) | | |
| | `?pid=9001&dev=1&start=quiz` | the quiz (skip intro + practice) | | |
| | `?pid=9001&dev=1&start=practice` | practice (skip intro) | | |
| | `?pid=9001&dev=1&trials=3` | 3 trials per house instead of 20 (fast playthroughs) | | |
| ### Recruitment (Prolific etc.) | |
| If the link carries `?PROLIFIC_PID=…&STUDY_ID=…&SESSION_ID=…`, those are captured and saved. | |
| Set a `PROLIFIC_COMPLETION_URL` secret to show a "Finish & return to Prolific" button at the end. | |
| Every session also records the exact **`git_commit`** it ran (data provenance), so you can | |
| always reproduce what a participant saw. | |
| Headless checks (no browser): | |
| ```bash | |
| uv run python smoke_test.py # env logic | |
| uv run python orders.py # counterbalancing self-tests | |
| uv run python make_demo_data.py # simulate a full playthrough -> data/*.msgpack | |
| uv run python export_csv.py # msgpack -> combined *_data.csv | |
| ``` | |
| --- | |
| ## Data | |
| The app writes msgpack (one record per keypress + custom event records) to | |
| `data/user_data_<seed>.msgpack`, and exports **one combined CSV per participant** via | |
| `export_csv.py`. The CSV is **long format**: filter by **`row_type`** | |
| (`trial`, `quiz`, `rating`, `break`, `slide`, `click`, `summary`). See **CODEBOOK.md**. | |
| Recorded per session: every choice + its reaction time and the key used, both outcomes | |
| (as ±1 and as shown ±10), per-option outcomes, which option was "better" and whether it | |
| was chosen, end-of-house ratings, the full quiz (question text, answer, attempts), the | |
| complete randomisation, breaks, per-slide dwell times, every click, and device/browser/ | |
| framerate technical info. Start/end timestamps and duration are in the summary row. | |
| ### Where data goes (GitLab) | |
| Configured in `.env` (git-ignored; never commit tokens): | |
| ``` | |
| GITLAB_TOKEN=glpat-... # scope: api | |
| GITLAB_PROJECT=princessamygdala/treasurehuntfortwo | |
| GITLAB_URL=https://gitlab.com | |
| GITLAB_BRANCH=main | |
| ``` | |
| On finish **and** every ~2 min (so a mid-quit isn't lost), the app pushes | |
| `data/<pid>/user_data_*_data.csv` (+ the raw msgpack) and appends the participant's row to | |
| `randomization_log.csv`. Pull everything back with **`download_data.py`**. | |
| --- | |
| ## Deploy (Hugging Face Spaces) | |
| Free CPU tier, no card. The Space runs the Docker SDK (`app_port: 7860`). Put the same | |
| `GITLAB_*` values in the Space **Secrets** (not committed). Push to deploy: | |
| ```bash | |
| git push hf main --force | |
| ``` | |
| Full steps are in **[DEPLOY.md](DEPLOY.md)**. | |
| --- | |
| ## File map | |
| | File | Role | | |
| |------|------| | |
| | `experiment_structure.py` | The JAX env (`TreasureEnv`), rendering, stages, instructions, quiz, `custom_data_fn` | | |
| | `sprites.py` | All procedural PIL art: chests, houses, rooms, characters, splashes | | |
| | `orders.py` | Deterministic per-participant counterbalancing (the "order file" for each ID) | | |
| | `web_app.py` | NiceGUI shell: intro, stage loop, break button, telemetry, saving | | |
| | `export_csv.py` | msgpack → one combined long-format CSV (see CODEBOOK.md) | | |
| | `gitlab_save.py` | Push data + append the randomisation log to GitLab | | |
| | `next_id.py` / `download_data.py` | Assign the next ID / pull all data back | | |
| | `make_demo_data.py` / `smoke_test.py` | Simulate a playthrough / test env logic, no browser | | |
| | `render_slides.py` | Save reference JPGs of every screen + a chest/avatar sheet | | |
| | `consent.md` / `DEPLOY.md` | Consent text (placeholders) / deployment guide | | |
| ## Provenance | |
| Original task: `/Users/md1864/Documents/GitHub/task_sl-cu` (PsychoPy/Pavlovia). | |
| Framework: [NiceWebRL](https://github.com/KempnerInstitute/nicewebrl). | |