Skip to content

Commit 2e9bc94

Browse files
Adds participant metadata and slopit analytics support.
1 parent 5b0585d commit 2e9bc94

17 files changed

Lines changed: 4746 additions & 39 deletions

File tree

bead/behavioral/__init__.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"""Behavioral analytics for bead.
2+
3+
This module provides tools for extracting, storing, and analyzing
4+
behavioral data captured during experiments via slopit integration.
5+
6+
The main components are:
7+
8+
- **Analytics Models**: `JudgmentAnalytics`, `ParticipantBehavioralSummary`,
9+
`AnalyticsCollection` for storing per-judgment behavioral metrics
10+
- **Extraction**: Functions to extract analytics from slopit sessions
11+
- **Merging**: Utilities to merge analytics with judgment DataFrames
12+
13+
Examples
14+
--------
15+
Extract analytics from JATOS export:
16+
17+
>>> from bead.behavioral import extract_with_analysis, AnalyticsCollection
18+
>>> collection = extract_with_analysis("data/jatos_export/")
19+
>>> print(f"Extracted {len(collection)} analytics records")
20+
21+
Get participant summaries:
22+
23+
>>> summaries = collection.get_participant_summaries()
24+
>>> for s in summaries:
25+
... if s.flag_rate > 0.1:
26+
... print(f"Participant {s.participant_id}: {s.flag_rate:.1%} flagged")
27+
28+
Merge with judgment data:
29+
30+
>>> from bead.behavioral import merge_behavioral_analytics
31+
>>> merged_df = merge_behavioral_analytics(judgments_df, collection)
32+
33+
Filter out flagged judgments:
34+
35+
>>> from bead.behavioral import filter_flagged_judgments
36+
>>> clean_df = filter_flagged_judgments(judgments_df, collection, exclude_flagged=True)
37+
38+
Save and load analytics:
39+
40+
>>> collection.to_jsonl("analytics.jsonl")
41+
>>> loaded = AnalyticsCollection.from_jsonl("analytics.jsonl", name="study_001")
42+
"""
43+
44+
from bead.behavioral.analytics import (
45+
AnalyticsCollection,
46+
JudgmentAnalytics,
47+
ParticipantBehavioralSummary,
48+
)
49+
from bead.behavioral.extraction import (
50+
analyze_sessions,
51+
extract_from_directory,
52+
extract_from_file,
53+
extract_from_session,
54+
extract_from_trial,
55+
extract_with_analysis,
56+
)
57+
from bead.behavioral.merging import (
58+
create_analysis_dataframe_with_behavior,
59+
filter_flagged_judgments,
60+
get_exclusion_list,
61+
merge_behavioral_analytics,
62+
)
63+
64+
# Re-export key slopit types for convenience
65+
from slopit.behavioral import (
66+
Analyzer,
67+
FocusAnalyzer,
68+
KeystrokeAnalyzer,
69+
PasteAnalyzer,
70+
TimingAnalyzer,
71+
)
72+
from slopit.schemas import (
73+
AnalysisFlag,
74+
BehavioralData,
75+
BehavioralMetrics,
76+
FocusMetrics,
77+
KeystrokeMetrics,
78+
Severity,
79+
SlopitSession,
80+
SlopitTrial,
81+
TimingMetrics,
82+
)
83+
84+
__all__ = [
85+
# Bead models
86+
"JudgmentAnalytics",
87+
"ParticipantBehavioralSummary",
88+
"AnalyticsCollection",
89+
# Extraction
90+
"extract_from_trial",
91+
"extract_from_session",
92+
"extract_from_file",
93+
"extract_from_directory",
94+
"extract_with_analysis",
95+
"analyze_sessions",
96+
# Merging
97+
"merge_behavioral_analytics",
98+
"filter_flagged_judgments",
99+
"create_analysis_dataframe_with_behavior",
100+
"get_exclusion_list",
101+
# Slopit re-exports
102+
"SlopitSession",
103+
"SlopitTrial",
104+
"BehavioralData",
105+
"BehavioralMetrics",
106+
"KeystrokeMetrics",
107+
"FocusMetrics",
108+
"TimingMetrics",
109+
"AnalysisFlag",
110+
"Severity",
111+
"Analyzer",
112+
"KeystrokeAnalyzer",
113+
"FocusAnalyzer",
114+
"PasteAnalyzer",
115+
"TimingAnalyzer",
116+
]

0 commit comments

Comments
 (0)