"""Build a reach-intent benchmark from PLOS ONE supplementary archive S3. The builder reads the source archive without extracting it, joins event logs to the approximately 16 Hz skeleton stream, and writes viewer-friendly CSV files. It intentionally excludes the clinical table and fine-grained demographics. """ from __future__ import annotations import argparse import csv import gzip import hashlib import io import json import re import urllib.request import zipfile from collections import Counter, defaultdict from datetime import date, datetime from pathlib import Path from typing import Iterable, Iterator SOURCE_URL = ( "https://journals.plos.org/plosone/article/file?type=supplementary&" "id=info:doi/10.1371/journal.pone.0170472.s003" ) SOURCE_SHA256 = "21fc2ae8d8bce10b3cecd6416fdda390ba98476c9b9abe95be91857aea07d008" TARGET_NAMES = { 0: "right_low_45", 1: "right_lateral", 2: "right_up_30", 3: "right_up_60", 4: "right_top", 5: "left_low_45", 6: "left_lateral", 7: "left_up_30", 8: "left_up_60", 9: "left_top", } # The two session-level PCA outliers removed in the public analysis workflow. QC_OUTLIER_FEATURE_KEYS = { "1024_2015.03.19_19.19", "1038_2014.12.11_17.45", } EVENT_RE = re.compile( r"\t(?P\d+)\tObject (?P\d+) " r"(?Pappeared|timed out|reached by (?Pright|left) hand)!" ) SESSION_RE = re.compile( r"(?P\d+)_(?P\d{4}\.\d{2}\.\d{2})_" r"(?P