File size: 4,541 Bytes
a093ba2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"""
ASSISTments 2012-2013 Processing Script for DIF Analysis
=========================================================
The 2012-2013 "School Data with Affect" version is the ONLY ASSISTments
release with both demographics (gender, ELL, IEP, economically_disadvantaged)
AND school_id. NO ASSISTments version has question text.

MANUAL DOWNLOAD REQUIRED:
1. Go to: https://sites.google.com/site/assistmentsdata/datasets/2012-13-school-data-with-affect
2. Click the Google Drive link to download the CSV
3. Save as 'assist2012.csv' in the same directory as this script
4. Run: python process_assistments_2012.py

Expected columns in 2012-2013:
  student_id, problem_id, skill_id, skill_name, correct, attempt_count,
  hint_count, ms_first_response, school_id, teacher_id, gender,
  economically_disadvantaged, ELL, IEP
  
NO question text in any column.
"""
import os, sys, json
import pandas as pd

# Find the CSV
candidates = [
    "assist2012.csv",
    "2012-2013-data-with-predictions-4-students.csv",
    "ASSISTments2012-13.csv",
]

csv_path = None
for c in candidates:
    if os.path.exists(c):
        csv_path = c
        break

if csv_path is None:
    # Try any CSV in current dir
    csvs = [f for f in os.listdir('.') if f.endswith('.csv') and 'assist' in f.lower()]
    if csvs:
        csv_path = csvs[0]

if csv_path is None:
    print("ERROR: No ASSISTments CSV found.")
    print("Download from: https://sites.google.com/site/assistmentsdata/datasets/2012-13-school-data-with-affect")
    print("Save as 'assist2012.csv' and re-run.")
    sys.exit(1)

OUT = "assistments_2012_processed"
os.makedirs(OUT, exist_ok=True)

# Load
print(f"Loading {csv_path}...")
df = pd.read_csv(csv_path, low_memory=False)
print(f"Shape: {df.shape}")
print(f"Columns: {list(df.columns)}")

# Check demographics
demo_cols = ['gender', 'school_id', 'economically_disadvantaged', 'ELL', 'IEP']
for col in demo_cols:
    matches = [c for c in df.columns if col.lower() in c.lower()]
    if matches:
        c = matches[0]
        print(f"\n{c}:")
        print(f"  Distribution: {df[c].value_counts().head(5).to_dict()}")
        print(f"  Missing: {df[c].isna().sum()} ({df[c].isna().mean()*100:.1f}%)")
    else:
        print(f"\n{col}: NOT FOUND")

# Save as parquet
print(f"\nSaving to {OUT}/...")
df.to_parquet(os.path.join(OUT, "assist2012_full.parquet"), index=False)

# Item stats by skill
if 'correct' in df.columns:
    skill_col = [c for c in df.columns if 'skill' in c.lower() and 'name' in c.lower()]
    if not skill_col:
        skill_col = [c for c in df.columns if 'skill' in c.lower() and 'id' in c.lower()]
    
    if skill_col:
        item_stats = df.groupby(skill_col[0]).agg(
            n_responses=('correct', 'count'),
            p_value=('correct', 'mean'),
        ).reset_index().sort_values('n_responses', ascending=False)
        item_stats.to_parquet(os.path.join(OUT, "item_stats.parquet"), index=False)
        print(f"\nItem stats: {len(item_stats)} skills")
        print(item_stats.head(10).to_string())

# Student stats
if 'student_id' in [c.lower() for c in df.columns]:
    sid_col = [c for c in df.columns if c.lower() == 'student_id' or c.lower() == 'user_id'][0]
    stu = df.groupby(sid_col).agg(
        n_items=('correct', 'count'),
        accuracy=('correct', 'mean'),
    ).reset_index()
    stu.to_parquet(os.path.join(OUT, "student_stats.parquet"), index=False)
    print(f"\nStudents: {len(stu)}")

# DIF-ready export: gender × item response
gender_col = [c for c in df.columns if 'gender' in c.lower()]
if gender_col:
    g = gender_col[0]
    print(f"\nGender column '{g}': {df[g].value_counts().to_dict()}")
    print(f"Missing gender: {df[g].isna().sum()} ({df[g].isna().mean()*100:.1f}%)")
    
    # Filter to rows with valid gender
    dif_data = df[df[g].notna()].copy()
    dif_data.to_parquet(os.path.join(OUT, "dif_ready_with_gender.parquet"), index=False)
    print(f"DIF-ready rows (with gender): {len(dif_data):,}")

summary = {
    "dataset": "ASSISTments 2012-2013 (School Data with Affect)",
    "rows": len(df),
    "columns": list(df.columns),
    "has_question_text": False,
    "question_text_note": "NO question text in any public ASSISTments release. Only skill_name available.",
}
with open(os.path.join(OUT, "summary.json"), "w") as f:
    json.dump(summary, f, indent=2, default=str)

print(f"\nDone! Files in: {OUT}/")
for f in sorted(os.listdir(OUT)):
    size = os.path.getsize(os.path.join(OUT, f)) / 1e6
    print(f"  {f}: {size:.1f} MB")