-
Notifications
You must be signed in to change notification settings - Fork 2
Data Collection
Dae Houlihan edited this page Nov 11, 2024
·
2 revisions
Warning
This section is under construction. Some of this information is out of date with the latest release of the template. Use with caution.
This guide covers integrating with Prolific and retrieving experimental data.
- Create study on Prolific
- Configure URL parameters in Prolific:
- PROLIFIC_PID
- STUDY_ID
- SESSION_ID
- Add completion code in
creds.ts
:
const prolificCompletionCode = "YOUR-CODE";
- Verify URL parameter handling in your code:
const urlParams = new URLSearchParams(window.location.search);
const prolificPID = urlParams.get('PROLIFIC_PID');
const studyID = urlParams.get('STUDY_ID');
const sessionID = urlParams.get('SESSION_ID');
The template uses three Firestore collections:
-
exptData
: Main experimental data{ uid: string, trials: Array<{ currentTrial: number, response: string|number, // ... other trial data }>, // ... metadata }
-
userData
: User-specific data -
sharedData
: Shared experiment configuration
Default Firestore rules:
match /expData/{uid} {
allow read: if true;
allow write: if request.auth.uid == uid;
}
-
Generate Firebase Admin credentials:
- Go to Firebase Console
- Project Settings > Service Accounts
- Generate New Private Key
- Save JSON file securely
-
Run retrieval script:
python retrieve_data.py \
--cred "path/to/firebase-adminsdk.json" \
--out "path/to/output" \
--collection 'exptData' 'sharedData'
Retrieved data structure:
{
"participant_id": {
"trials": [
{
"currentTrial": 0,
"response": "value",
"timestamp": "2024-01-01T12:00:00Z"
}
// ... more trials
],
"metadata": {
"prolificPID": "...",
"studyID": "...",
"sessionID": "...",
"version": "1.0.0",
"commitHash": "abc123"
}
}
// ... more participants
}
-
Secure credential storage:
- Never commit credentials to git
- Use encrypted storage for admin SDK key
- Limit access to production data
-
Data backup:
- Regular exports
- Version control for analysis scripts
- Secure backup storage
-
Data cleanup:
- Remove debug data regularly
- Archive completed studies
- Maintain audit trail
import pandas as pd
import firebase_admin
from firebase_admin import credentials, firestore
def load_experiment_data(cred_path):
cred = credentials.Certificate(cred_path)
firebase_admin.initialize_app(cred)
db = firestore.client()
# Get all documents from exptData collection
docs = db.collection('exptData').stream()
# Convert to pandas DataFrame
data = []
for doc in docs:
participant_data = doc.to_dict()
# Flatten trial data
for trial in participant_data['trials']:
trial_data = {
'participant_id': doc.id,
**participant_data['metadata'],
**trial
}
data.append(trial_data)
return pd.DataFrame(data)
- Return to Development Workflow
- Review Deployment Guide