File size: 6,357 Bytes
9deebf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"""
Process all GotPsi datasets and export to Parquet.

Runs all dataset processors in sequence and generates a complete set of cleaned data files.
"""

import sys
import argparse
import subprocess
from pathlib import Path
from datetime import datetime

# Dataset processors in recommended processing order
PROCESSORS = [
    ('users', 'Users (Survey Responses)'),
    ('card', 'Card (Basic Card Test)'),
    ('cardd', 'CardD (Card Test with Details)'),
    ('cards', 'CardS (Card Test Shuffled)'),
    ('rv', 'RV (Full Remote Viewing)'),
    ('rvq', 'RVQ (Quick Remote Viewing)'),
    ('location', 'Location (RV Coordinates)'),
    ('lottery', 'Lottery'),
]


def main():
    parser = argparse.ArgumentParser(
        description='Process all GotPsi datasets',
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Available datasets:
  users     - User survey responses (users14.dat, questions.dat)
  card      - Basic card test
  cardd     - Card test with details
  cardS     - Card test shuffled
  rv        - Full remote viewing
  rvq       - Quick remote viewing
  location  - Remote viewing coordinates
  lottery   - Lottery data

Examples:
  python scripts/process_all.py                    # Process all datasets
  python scripts/process_all.py --audit            # Process all with audit columns
  python scripts/process_all.py --only users card  # Process only users and card datasets
  python scripts/process_all.py --skip rv rvq     # Process all except rv and rvq
        """
    )
    parser.add_argument('--audit', action='store_true',
                       help='Include source_file and source_row_number columns in output')
    parser.add_argument('--only', nargs='+', metavar='DATASET',
                       help='Process only these datasets')
    parser.add_argument('--skip', nargs='+', metavar='DATASET',
                       help='Skip these datasets')
    parser.add_argument('--continue-on-error', action='store_true',
                       help='Continue processing even if a dataset fails')
    parser.add_argument('--data-dir',
                       help='Override raw data directory (default: data/)')

    args = parser.parse_args()

    # Determine which datasets to process
    datasets_to_process = PROCESSORS.copy()

    if args.only:
        datasets_to_process = [(name, desc) for name, desc in PROCESSORS
                              if name in args.only]
        if not datasets_to_process:
            print(f"✗ No valid datasets specified in --only: {args.only}")
            print(f"  Available: {', '.join([name for name, _ in PROCESSORS])}")
            sys.exit(1)

    if args.skip:
        datasets_to_process = [(name, desc) for name, desc in datasets_to_process
                              if name not in args.skip]
        if not datasets_to_process:
            print(f"✗ All datasets were skipped")
            sys.exit(1)

    # Print header
    print("="*70)
    print("GotPsi Data Processing - All Datasets")
    print("="*70)
    print()
    print(f"Processing {len(datasets_to_process)} dataset(s):")
    for name, desc in datasets_to_process:
        print(f"  - {name:10s} : {desc}")
    print()

    if args.audit:
        print("Audit mode: ENABLED (including source_file and source_row_number columns)")
    else:
        print("Audit mode: DISABLED (excluding audit columns for smaller file size)")
    print()

    # Start processing
    start_time = datetime.now()

    results = []
    scripts_dir = Path(__file__).parent

    for i, (dataset_name, dataset_desc) in enumerate(datasets_to_process, 1):
        print("="*70)
        print(f"[{i}/{len(datasets_to_process)}] Processing {dataset_name}: {dataset_desc}")
        print("="*70)
        print()

        # Build command
        script_path = scripts_dir / f'process_{dataset_name}_full.py'

        if not script_path.exists():
            print(f"✗ Script not found: {script_path}")
            results.append((dataset_name, 'FAILED', 'Script not found'))
            if not args.continue_on_error:
                print("\nAborting due to error. Use --continue-on-error to continue.")
                sys.exit(1)
            continue

        cmd = [sys.executable, str(script_path)]
        if args.audit:
            cmd.append('--audit')
        if args.data_dir:
            cmd.extend(['--data-dir', args.data_dir])

        # Run processor
        dataset_start = datetime.now()
        try:
            result = subprocess.run(cmd, check=True)
            dataset_elapsed = datetime.now() - dataset_start
            results.append((dataset_name, 'SUCCESS', str(dataset_elapsed)))
            print()
        except subprocess.CalledProcessError as e:
            dataset_elapsed = datetime.now() - dataset_start
            results.append((dataset_name, 'FAILED', f'Exit code {e.returncode}'))
            print(f"\n✗ Failed with exit code {e.returncode}")
            if not args.continue_on_error:
                print("\nAborting due to error. Use --continue-on-error to continue.")
                sys.exit(1)
        except KeyboardInterrupt:
            print("\n\n✗ Interrupted by user")
            results.append((dataset_name, 'INTERRUPTED', '-'))
            break

    # Print summary
    total_elapsed = datetime.now() - start_time

    print()
    print("="*70)
    print("Processing Complete!")
    print("="*70)
    print()
    print("Results Summary:")
    print(f"  Total time: {total_elapsed}")
    print()

    success_count = sum(1 for _, status, _ in results if status == 'SUCCESS')
    failed_count = sum(1 for _, status, _ in results if status == 'FAILED')

    print(f"  Datasets processed: {len(results)}")
    print(f"  Successful: {success_count}")
    print(f"  Failed: {failed_count}")
    print()

    # Detailed results
    print("Detailed Results:")
    for dataset_name, status, info in results:
        status_icon = "✓" if status == "SUCCESS" else "✗"
        print(f"  {status_icon} {dataset_name:10s} : {status:12s} {info}")
    print()

    if failed_count > 0:
        print(f"⚠ {failed_count} dataset(s) failed")
        sys.exit(1)
    else:
        print("✓ All datasets processed successfully!")
        print()
        print("Output files are in: output/parquet/")
        print()


if __name__ == '__main__':
    main()