File size: 3,973 Bytes
c69ba8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Auto Demo - Run Enhanced Data Explorer
=====================================

This script automatically demonstrates the enhanced data explorer
"""

from upload import EnhancedDataExplorer, load_and_explore_data
import os

def auto_demo():
    """Automatically run the enhanced data explorer demo"""
    print("πŸš€ STARTING AUTO DEMO - ENHANCED DATA EXPLORER")
    print("=" * 50)
    
    # First check if CSV file exists
    csv_path = "C:/Users/Cosmo/Desktop/NTU Peak Singtel/outsystems_sample_logs_6months.csv"
    
    if not os.path.exists(csv_path):
        print(f"❌ CSV file not found at: {csv_path}")
        print("πŸ“ Using demo data instead...")
        
        # Create some demo data
        import pandas as pd
        import numpy as np
        
        demo_data = pd.DataFrame({
            'timestamp': pd.date_range('2024-01-01', periods=1000, freq='H'),
            'response_time': np.random.exponential(0.5, 1000),
            'status_code': np.random.choice([200, 404, 500], 1000, p=[0.8, 0.15, 0.05]),
            'user_count': np.random.poisson(10, 1000),
            'error_rate': np.random.beta(2, 20, 1000),
            'server_id': np.random.choice(['server1', 'server2', 'server3'], 1000)
        })
        
        demo_csv_path = "demo_data.csv"
        demo_data.to_csv(demo_csv_path, index=False)
        print(f"βœ… Demo data created: {demo_csv_path}")
        
        # Update the path for the explorer
        csv_path = demo_csv_path
    
    # Initialize the enhanced explorer
    print("\nπŸ€– Initializing Enhanced Data Explorer...")
    explorer = EnhancedDataExplorer(csv_path)
    
    # Check AI status
    if explorer.agent:
        print("βœ… AI Agent: Configured and ready!")
        ai_status = "Available"
    else:
        print("⚠️  AI Agent: Not configured (non-AI features still available)")
        ai_status = "Not Available"
    
    print(f"\nπŸ“Š DATA ANALYSIS DEMO")
    print("=" * 30)
    
    # Step 1: Load data
    print("\n1️⃣ Loading and exploring data...")
    df = explorer.load_data()
    
    if df is not None:
        print(f"βœ… Data loaded successfully!")
        
        # Step 2: Data quality analysis
        print("\n2️⃣ Analyzing data quality...")
        quality_report = explorer.analyze_data_quality()
        
        # Step 3: Create visualizations
        print("\n3️⃣ Creating visualizations...")
        try:
            explorer.create_visualizations()
        except Exception as e:
            print(f"⚠️  Visualization skipped: {e}")
        
        # Step 4: AI Analysis (if available)
        if explorer.agent:
            print("\n4️⃣ Running AI analysis...")
            queries = [
                "Describe the main characteristics of this dataset",
                "What patterns do you see in the data?",
                "Are there any data quality issues I should be aware of?"
            ]
            
            for i, query in enumerate(queries, 1):
                print(f"\nπŸ€– AI Query {i}: {query}")
                try:
                    response = explorer.ai_analysis(query)
                    if response:
                        print("βœ… AI analysis completed")
                    else:
                        print("⚠️  AI analysis returned no response")
                except Exception as e:
                    print(f"❌ AI analysis failed: {e}")
                    break
        else:
            print("\n4️⃣ AI Analysis: Skipped (no AI model configured)")
    
    print(f"\nπŸŽ‰ DEMO COMPLETE!")
    print("=" * 20)
    print(f"πŸ“Š Data Status: {'Loaded' if df is not None else 'Failed'}")
    print(f"πŸ€– AI Status: {ai_status}")
    print(f"πŸ“ˆ Visualizations: {'Created' if df is not None else 'Skipped'}")
    
    print(f"\nπŸ’‘ To run interactively:")
    print(f"   python upload.py")
    print(f"   Choose option 2 for enhanced mode")

if __name__ == "__main__":
    auto_demo()