GotPsi / scripts /process_all.py
ebrinz's picture
Flatten history: re-sanitized (128-bit hash) GotPsi public dataset
9deebf2
Raw
History Blame Contribute Delete
6.36 kB
"""
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()