promato_analyse/run_analysis.py
2025-04-18 22:34:10 +02:00

68 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""
Working Time Analysis - Complete Workflow
This script runs all three steps of the analysis in sequence:
1. Import the data
2. Transform the data
3. Generate analysis reports
"""
import os
import sys
import subprocess
import time
def run_step(script_name, step_desc):
"""Run a step in the analysis and handle errors"""
print(f"\n{'='*60}")
print(f"STEP: {step_desc}")
print(f"{'='*60}")
try:
# Run the script and capture output
result = subprocess.run(
[sys.executable, script_name],
capture_output=True,
text=True,
check=True
)
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"ERROR in {script_name}:")
print(e.stderr)
return False
def main():
# Check if the CSV file exists
csv_file = 'data/lawi-2025-04-01-2025-04-30-2025-04-17.csv'
if not os.path.exists(csv_file):
print(f"Error: CSV file not found at {csv_file}")
return False
# Step 1: Import Data
if not run_step('import_data.py', 'IMPORTING DATA'):
return False
# Wait a moment to ensure any file locks are released
time.sleep(1)
# Step 2: Transform Data
if not run_step('transform_data.py', 'TRANSFORMING DATA'):
return False
# Wait a moment to ensure any file locks are released
time.sleep(1)
# Step 3: Analyze Data
if not run_step('analyze_data.py', 'ANALYZING DATA'):
return False
print("\n" + "="*60)
print("ANALYSIS COMPLETE")
print("="*60)
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)