-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDEMO_SIMPLE.rs
More file actions
151 lines (127 loc) · 6.3 KB
/
Copy pathDEMO_SIMPLE.rs
File metadata and controls
151 lines (127 loc) · 6.3 KB
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
// Simple working demo of Xplainit Framework (AS IS - January 2026)
// This shows EXACTLY what works right now
use xplainit_core::*;
use chrono::Utc;
use uuid::Uuid;
use std::collections::HashMap;
fn main() {
println!("╔══════════════════════════════════════════════════════════╗");
println!("║ XPLAINIT FRAMEWORK - WORKING DEMO (v0.1.0) ║");
println!("╚══════════════════════════════════════════════════════════╝\n");
// ========================================
// DEMO 1: Basic Event Explanation
// ========================================
println!("📋 DEMO 1: Basic Event Explanation\n");
let event = ExecutionEvent::FunctionEnter {
id: Uuid::new_v4(),
name: "calculate_discount".to_string(),
args: {
let mut args = HashMap::new();
args.insert("price".to_string(), Value::Float(99.99));
args.insert("discount_percent".to_string(), Value::Integer(20));
args
},
location: SourceLocation::new("shop.py".to_string(), 42, 0),
timestamp: Utc::now(),
};
// Create explainer
let explainer = ExplanationGenerator::new(VerbosityLevel::Normal);
println!(" {}\n", explainer.explain(&event));
// ========================================
// DEMO 2: Multiple Verbosity Levels
// ========================================
println!("📋 DEMO 2: Multiple Verbosity Levels\n");
let brief = ExplanationGenerator::new(VerbosityLevel::Brief);
println!(" Brief: {}", brief.explain(&event));
let normal = ExplanationGenerator::new(VerbosityLevel::Normal);
println!(" Normal: {}", normal.explain(&event));
let detailed = ExplanationGenerator::new(VerbosityLevel::Detailed);
println!(" Detailed: {}\n", detailed.explain(&event));
// ========================================
// DEMO 3: Error Analysis
// ========================================
println!("📋 DEMO 3: Error Analysis with Fix Suggestions\n");
let error = ExecutionEvent::DivisionByZero {
id: Uuid::new_v4(),
numerator: Value::Integer(100),
denominator_var: Some("quantity".to_string()),
location: SourceLocation::new("calculator.py".to_string(), 15, 8),
timestamp: Utc::now(),
};
let error_explainer = ErrorExplainer::new();
if let Some(analysis) = error_explainer.analyze(&error) {
println!(" 🔴 Severity: {:?}", analysis.severity);
println!(" 📍 Category: {:?}", analysis.category);
println!("\n 💡 Root Cause:");
println!(" {}", analysis.root_cause);
println!("\n 🔧 Fix Suggestions:");
for (i, fix) in analysis.fix_suggestions.iter().take(2).enumerate() {
println!(" {}. {}", i + 1, fix);
}
println!();
}
// ========================================
// DEMO 4: Event Storage & Statistics
// ========================================
println!("📋 DEMO 4: Event Storage & Statistics\n");
let config = Config::new(Language::Python);
let engine = RuntimeEngine::new(config);
// Simulate recording 5 events
for i in 1..=5 {
let event = ExecutionEvent::FunctionEnter {
id: Uuid::new_v4(),
name: format!("function_{}", i),
args: HashMap::new(),
location: SourceLocation::new("test.py".to_string(), i * 10, 0),
timestamp: Utc::now(),
};
engine.event_store().record(event);
}
let stats = engine.event_stats();
println!(" 📊 Total Events Recorded: {}", stats.total_recorded);
println!(" ✅ Current Events in Store: {}", stats.current_count);
println!(" ❌ Total Errors: {}", stats.total_errors);
println!();
// ========================================
// DEMO 5: Event Filtering
// ========================================
println!("📋 DEMO 5: Smart Event Filtering\n");
let filter = FunctionFilter::new()
.include("calculate_*")
.exclude("*_internal");
let event1 = ExecutionEvent::FunctionEnter {
id: Uuid::new_v4(),
name: "calculate_total".to_string(),
args: HashMap::new(),
location: SourceLocation::unknown(),
timestamp: Utc::now(),
};
let event2 = ExecutionEvent::FunctionEnter {
id: Uuid::new_v4(),
name: "process_internal".to_string(),
args: HashMap::new(),
location: SourceLocation::unknown(),
timestamp: Utc::now(),
};
println!(" Filter rules: include 'calculate_*', exclude '*_internal'");
println!(" ✅ calculate_total: {}", if filter.should_capture(&event1, &config) { "CAPTURED" } else { "FILTERED" });
println!(" ❌ process_internal: {}", if filter.should_capture(&event2, &config) { "CAPTURED" } else { "FILTERED" });
println!();
// ========================================
// DEMO 6: JSON Output Format
// ========================================
println!("📋 DEMO 6: JSON Output Format\n");
let json_formatter = JsonFormatter::new(true); // pretty print
let json_output = json_formatter.format_event(&event1);
println!(" {}\n", json_output.lines().take(5).collect::<Vec<_>>().join("\n "));
println!(" ... (truncated)\n");
// ========================================
// Summary
// ========================================
println!("╔══════════════════════════════════════════════════════════╗");
println!("║ ✅ DEMO COMPLETE ║");
println!("╚══════════════════════════════════════════════════════════╝");
println!("\n✨ All features demonstrated above work perfectly!");
println!("📝 Missing: Automatic runtime tracing (see PRODUCTION_READINESS_PLAN.md)");
println!("🎯 Next step: Execute Phase 1 of the production plan\n");
}