File size: 3,080 Bytes
712579e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
# Process only first 10 questions
python auto_pipe.py questions.csv --samples 10

# Process 50 questions with custom output file
python auto_pipe.py questions.csv --samples 50 --output results.csv

# Create sample CSV with 20 questions and process all
python auto_pipe.py --create-sample --sample-size 20

# Process 5 questions from custom column
python auto_pipe.py questions.csv --column "user_question" --samples 5

# Process all questions (no limit)
python auto_pipe.py questions.csv
"""

import os
import sys
import pandas as pd
from datetime import datetime

# Add the project directory to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

# Import the CSV test runner
from test_runner import run_csv_test, create_sample_csv

def main():
    print("πŸ€– Wisal CSV Test Runner")
    print("=" * 40)
    
    # Check if CSV file is provided as argument
    if len(sys.argv) > 1:
        csv_file = sys.argv[1]
        if not os.path.exists(csv_file):
            print(f"❌ Error: File '{csv_file}' not found")
            return
    else:
        # Create a sample CSV file
        print("πŸ“ No CSV file provided. Creating sample questions...")
        csv_file = create_sample_csv("assets/qa_data.csv")
        print(f"βœ… Sample CSV created: {csv_file}")
    
    # Determine output file
    if len(sys.argv) > 3 and sys.argv[2] == "-o":
        output_file = sys.argv[3]
    else:
        base_name = os.path.splitext(csv_file)[0]
        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        output_file = f"{base_name}_results_{timestamp}.csv"
    
    print(f"πŸ“₯ Input file: {csv_file}")
    print(f"πŸ“€ Output file: {output_file}")
    print("πŸš€ Starting test run...\n")
    
    try:
        # Run the test
        result_file = run_csv_test(csv_file, output_file)
        
        # Show preview of results
        print("\nπŸ“Š Results Preview:")
        print("-" * 40)
        df = pd.read_csv(result_file)
        
        for idx, row in df.iterrows():
            status_emoji = "βœ…" if row['status'] == 'success' else "❌"
            print(f"{status_emoji} Q{idx+1}: {row['question'][:60]}...")
            print(f"   ⏱️  Time: {row['total_time_seconds']:.2f}s")
            if row['status'] == 'success':
                print(f"   πŸ’¬ Answer: {row['clean_answer'][:100]}...")
            else:
                print(f"   ❌ Error: {row['error_message']}")
            print()
        
        # Summary
        successful = len(df[df['status'] == 'success'])
        total = len(df)
        avg_time = df[df['status'] == 'success']['total_time_seconds'].mean()
        
        print("πŸ“ˆ Summary:")
        print(f"   Total Questions: {total}")
        print(f"   Successful: {successful}")
        print(f"   Failed: {total - successful}")
        print(f"   Average Time: {avg_time:.2f} seconds")
        print(f"   Results saved to: {result_file}")
        
    except Exception as e:
        print(f"❌ Error running test: {e}")
        return


if __name__ == "__main__":
    main()