# Nonosynergy — local setup

This README is the experiment's dev mode on your own Mac.

---

## Part 1 — First time install for Mac user (if setup already, jump to Part 2)

You need three things: **Homebrew**, **PHP**, and **MySQL**. 

### 1.1 PHP & MySQL

```bash
brew install php # php -v
brew install mysql # mysql --version
```
verify
```bash
php -v
mysql --version
```

### 1.2 Start MySQL service

```bash
brew services start mysql
```
verify
```bash
brew services list | grep mysql
```

### 1.3 Create the database

```bash
mysql -u root -e "CREATE DATABASE nonosynergy CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
```
verify
```bash
mysql -u root -e "SHOW DATABASES;" | grep nonosynergy
```

### 1.4 Start the PHP dev server

```bash
php -S localhost:8000
```

### 1.5 Initialize the database tables

visit in browser:

```
http://localhost:8000/databasecall.php?action=initializeDB&pass=nono_init_2026
```
Expected response:
```json
{"ok":true,"message":"tables created"}
```

If you see `db_connect_failed`, MySQL isn't running or the password setting
in `databasecall.php` doesn't match. Re-check `brew services list` and
the `$pass` value at `databasecall.php:38`.

### 1.6 Run the experiment

| What to test | URL |
| --- | --- |
| Solo end-to-end | `http://localhost:8000/experiment.html?condition=solo&PROLIFIC_PID=test_solo` |
| Dyad — Player 1 (regular window) | `http://localhost:8000/experiment.html?condition=human_human&PROLIFIC_PID=test_A` |
| Dyad — Player 2 (**incognito window**) | `http://localhost:8000/experiment.html?condition=human_human&PROLIFIC_PID=test_B` |

> Use an private window for Player 2 so the two browser sessions
don't share cookies or local storage.

---

## Part 2 — Coming back after closing the terminal

`brew services` persists across reboots by default, so MySQL usually keeps
itself running. The only thing that stops when you close the terminal is the
PHP dev server. The minimum to get back up:

confirm MySQL is up; 
```bash
brew services list | grep mysql
```

if not up, start wiuth
```bash
brew services start mysql
```

start the PHP dev server
```bash
php -S localhost:8000
```

Then re-open the same URLs from §1.6.

> The database tables created in §1.5 persist across reboots — you do **not**
need to re-run `initializeDB` unless you explicitly want to wipe the data.

---

## Part 3 — Useful dev tips

### Inspect data while you test

```bash
# session-level summary
mysql -u root nonosynergy -e "
  SELECT id, session_id, cond_name, puzzle_id, assigned, completed, task_start, task_end
  FROM nonosynergy_sessions ORDER BY id DESC LIMIT 10;"

# last 20 moves across all sessions
mysql -u root nonosynergy -e "
  SELECT session_id, step, player, role, cell_row, cell_col, value,
         correct, locally_valid, confidence, thinking_time_ms
  FROM nonosynergy_moves ORDER BY id DESC LIMIT 20;"

# full JSON log for one session
mysql -u root nonosynergy -e "
  SELECT log_data FROM nonosynergy_sessions WHERE session_id='<paste_session_id>';" \
  | python3 -m json.tool
```

### Wipe all data and start clean

```bash
curl 'http://localhost:8000/databasecall.php?action=initializeDB&pass=nono_init_2026'
```

This drops and re-creates both tables.

### Stopping everything

- stop the PHP dev server: Ctrl-C in its terminal
- stop MySQL only if you don't want it running on boot:
```bash
brew services stop mysql
```

> If you stop MySQL, you'll need `brew services start mysql` again before
your next experiment session.

---

## Part 4 — Project layout reference

```
nonosynergy/
├── README.md                  # this file — local setup
├── experiment.html            # entry point for participants
├── databasecall.php           # backend API (DB connect, session, move logging)
├── puzzles/
│   └── puzzles.json           # puzzle library (47 puzzles: 2 practice 5×5 + 45 main 10×10)
├── js/
│   ├── solver.js              # deterministic line solver
│   ├── nonogram.js            # grid rendering + interaction
│   ├── sync.js                # AJAX wrapper for databasecall.php
│   └── main.js                # experiment controller
└── css/
    ├── bootstrap.css
    └── ui.css                 # task styling
```
