Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
package_json_file: bead/deployment/jspsych/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -38,7 +38,7 @@ jobs:
cache-dependency-path: bead/deployment/jspsych/pnpm-lock.yaml

- name: Install dependencies
run: pnpm install
run: pnpm install --frozen-lockfile

- name: Run Biome check (lint + format)
run: pnpm check
Expand All @@ -55,7 +55,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
package_json_file: bead/deployment/jspsych/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -65,7 +65,7 @@ jobs:
cache-dependency-path: bead/deployment/jspsych/pnpm-lock.yaml

- name: Install dependencies
run: pnpm install
run: pnpm install --frozen-lockfile

- name: Run type check
run: pnpm typecheck
Expand All @@ -82,7 +82,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
package_json_file: bead/deployment/jspsych/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -92,7 +92,7 @@ jobs:
cache-dependency-path: bead/deployment/jspsych/pnpm-lock.yaml

- name: Install dependencies
run: pnpm install
run: pnpm install --frozen-lockfile

- name: Build TypeScript
run: pnpm build
Expand All @@ -109,7 +109,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
package_json_file: bead/deployment/jspsych/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -119,7 +119,7 @@ jobs:
cache-dependency-path: bead/deployment/jspsych/pnpm-lock.yaml

- name: Install dependencies
run: pnpm install
run: pnpm install --frozen-lockfile

- name: Run tests
run: pnpm test
Expand Down Expand Up @@ -188,7 +188,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
package_json_file: bead/deployment/jspsych/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -199,11 +199,11 @@ jobs:

- name: Install TypeScript dependencies
working-directory: bead/deployment/jspsych
run: pnpm install
run: pnpm install --frozen-lockfile

- name: Build TypeScript
working-directory: bead/deployment/jspsych
run: pnpm build && pnpm build:gallery
run: pnpm build

- name: Set up Python
uses: actions/setup-python@v5
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: bead/deployment/jspsych/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
cache-dependency-path: bead/deployment/jspsych/pnpm-lock.yaml

- name: Build pinned browser assets
working-directory: bead/deployment/jspsych
run: |
pnpm install --frozen-lockfile
pnpm build

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -25,7 +43,11 @@ jobs:
run: pip install build

- name: Build package
run: python -m build
run: |
python -m build
python -m venv /tmp/bead-wheel
/tmp/bead-wheel/bin/pip install --no-deps dist/*.whl
/tmp/bead-wheel/bin/python -c 'from importlib.metadata import distribution; import hashlib, json; runtime = distribution("bead").locate_file("bead/deployment/jspsych/dist/runtime"); manifest = json.loads((runtime / "manifest.json").read_text()); assert all(hashlib.sha256((runtime / name).read_bytes()).hexdigest() == entry["sha256"] for name, entry in manifest.items())'

- name: Upload distribution artifacts
uses: actions/upload-artifact@v4
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Deploys named cloze fields with explicit choices and independent display labels.
- Appends consented JSONL session records to JATOS and reads complete or partial
streams into named annotation records while preserving the raw records.
- Allows a study-specific session adapter and a supplied slopit browser bundle
for consent-gated response-control telemetry.

### Fixed

- Ships pinned jsPsych runtime assets and standalone browser bundles in the
Python release. Generated studies load all required assets locally.
- Registers the slopit extension with jsPsych and supplies per-trial parameters
after consent.
- Exports native JATOS study archives with stable component and batch IDs when
the study ID is supplied.


## [0.13.0] - 2026-11-06

### Added
Expand Down
16 changes: 11 additions & 5 deletions bead/config/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from pathlib import Path
from typing import Literal

import didactic.api as dx

Expand Down Expand Up @@ -83,10 +84,12 @@ def _default_paste_config() -> SlopitPasteConfig:

def _default_target_selectors() -> dict[str, str]:
return {
"likert_rating": ".bead-rating-button",
"slider_rating": ".bead-slider",
"likert_rating": ".bead-rating-button, #bead-rating-continue",
"slider_rating": ".bead-slider-input, #bead-slider-continue",
"forced_choice": ".bead-choice-button",
"cloze": ".bead-cloze-field",
"cloze": ".bead-cloze-field, #bead-cloze-continue",
"binary_choice": ".bead-binary-button",
"bead-slider-rating": ".bead-slider-input, #bead-slider-continue",
}


Expand All @@ -104,10 +107,13 @@ class SlopitIntegrationConfig(dx.Model):
paste : SlopitPasteConfig
Paste event capture settings.
target_selectors : dict[str, str]
CSS selectors for capture targets by task type.
CSS selectors for capture targets by task type or plugin name.
profile : Literal["legacy", "response_controls"]
Capture profile applied after affirmative consent.
"""

enabled: bool = False
profile: Literal["legacy", "response_controls"] = "legacy"
keystroke: dx.Embed[SlopitKeystrokeConfig] = dx.field(
default_factory=_default_keystroke_config
)
Expand All @@ -127,7 +133,7 @@ def validate_slopit_integration(config: SlopitIntegrationConfig) -> None:
/ "deployment"
/ "jspsych"
/ "dist"
/ "slopit-bundle.js"
/ "slopit-bundle.global.js"
)
if not bundle_path.exists():
raise ValueError(
Expand Down
9 changes: 8 additions & 1 deletion bead/data_collection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
"""Data collection infrastructure for human experiments."""

from bead.data_collection.jatos import JATOSDataCollector
from bead.data_collection.jatos import JATOSDataCollector, load_jatos_result_archive
from bead.data_collection.merger import DataMerger
from bead.data_collection.prolific import ProlificDataCollector
from bead.data_collection.records import jatos_results_to_annotation_records
from bead.data_collection.result_stream import (
JATOSResultStream,
parse_jatos_result_stream,
)

__all__ = [
"DataMerger",
"JATOSDataCollector",
"JATOSResultStream",
"ProlificDataCollector",
"jatos_results_to_annotation_records",
"load_jatos_result_archive",
"parse_jatos_result_stream",
]
121 changes: 62 additions & 59 deletions bead/data_collection/jatos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,63 @@
from __future__ import annotations

import json
from pathlib import Path
import zipfile
from io import BytesIO
from pathlib import Path, PurePosixPath

from bead.data.base import JsonValue
from bead.data.timestamps import now_iso8601
from bead.deployment.jatos.api import JATOSClient


def load_jatos_result_archive(
source: Path | BytesIO,
) -> list[dict[str, JsonValue]]:
"""Load each component's raw data and metadata from a ZIP export.

JSON arrays are decoded for legacy consumers. Appended JSONL remains text
for sequence-aware parsing, including the last line of interrupted runs.
Components without submitted data are included with a null payload.
"""
results: list[dict[str, JsonValue]] = []
with zipfile.ZipFile(source) as archive:
files = set(archive.namelist())
metadata = json.loads(archive.read("metadata.json"))
for study in metadata["data"]:
for result in study["studyResults"]:
for component in result["componentResults"]:
folder = component.get("path") or (
f"study_result_{result['id']}/comp_result_{component['id']}"
)
path = str(PurePosixPath(folder.lstrip("/")) / "data.txt")
data: JsonValue = None
if path in files:
text = archive.read(path).decode("utf-8")
try:
parsed: JsonValue = json.loads(text)
data = (
text
if isinstance(parsed, dict) and "record_type" in parsed
else parsed
)
except json.JSONDecodeError:
data = text
results.append(
{
"result_id": result["id"],
"component_result_id": component["id"],
"data": data,
"metadata": {
**result,
**component,
"studyId": study["studyId"],
"studyResultId": result["id"],
},
}
)
return results


class JATOSDataCollector:
"""Collects experimental data from JATOS API.

Expand Down Expand Up @@ -108,27 +158,17 @@ def download_results(
worker_type="Prolific"
)
"""
# Get result IDs from JATOS API
result_ids = self.client.get_results(self.study_id)

results: list[dict[str, JsonValue]] = []

# Download each result with metadata
for result_id in result_ids:
result = self._download_single_result(result_id)

# Apply filters
if component_id is not None:
result_component_id = result.get("metadata", {}).get("componentId")
if result_component_id != component_id:
continue

if worker_type is not None:
result_worker_type = result.get("metadata", {}).get("workerType")
if result_worker_type != worker_type:
continue

results.append(result)
archive = self.client.download_result_archive(self.study_id)
results = []
for result in load_jatos_result_archive(BytesIO(archive)):
metadata = result["metadata"]
if not isinstance(metadata, dict):
continue
if component_id is not None and metadata.get("componentId") != component_id:
continue
if worker_type is not None and metadata.get("workerType") != worker_type:
continue
results.append({**result, "download_timestamp": now_iso8601().isoformat()})

# Save to JSONLines file (one result per line)
output_path.parent.mkdir(parents=True, exist_ok=True)
Expand All @@ -138,43 +178,6 @@ def download_results(

return results

def _download_single_result(self, result_id: int) -> dict[str, JsonValue]:
"""Download a single result with metadata.

Parameters
----------
result_id : int
Result ID to download.

Returns
-------
dict[str, JsonValue]
Result data with metadata and download timestamp.

Raises
------
requests.HTTPError
If the API request fails.
"""
# Get result data
data_url = f"{self.client.base_url}/api/v1/results/{result_id}/data"
data_response = self.client.session.get(data_url)
data_response.raise_for_status()

# Get result metadata
meta_url = f"{self.client.base_url}/api/v1/results/{result_id}"
meta_response = self.client.session.get(meta_url)
meta_response.raise_for_status()

metadata = meta_response.json()

return {
"result_id": result_id,
"data": data_response.json(),
"metadata": metadata,
"download_timestamp": now_iso8601().isoformat(),
}

def get_study_info(self) -> dict[str, JsonValue]:
"""Get study information.

Expand Down
Loading
Loading