widget_intelligence 2.0.0

A Rust library for intelligent Kyma widget suggestion and learning
Documentation
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
use colored::*;
use std::collections::HashMap;
use widget_intelligence::*;

fn create_kyma_widget(label: &str, min: f64, max: f64, current: f64) -> Widget {
    Widget {
        label: Some(label.to_string()),
        minimum: Some(min),
        maximum: Some(max),
        current_value: Some(current),
        is_generated: Some(false),
        display_type: Some("slider".to_string()),
        event_id: None,
        values: vec![current],
    }
}

fn create_preset_data(name: &str, widget_values: HashMap<String, f64>) -> Preset {
    let widget_values: Vec<WidgetValue> = widget_values
        .into_iter()
        .map(|(id, value)| WidgetValue {
            widget_id: id,
            label: None,
            value,
            confidence: 1.0,
        })
        .collect();

    Preset {
        name: name.to_string(),
        description: None,
        widget_values,
        created_by: None,
        usage_count: 1,
        last_used: std::time::SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .unwrap()
            .as_secs(),
    }
}

#[test]
fn test_kyma_style_widgets() {
    colored::control::set_override(true);

    println!("\n{}", "KYMA STYLE WIDGETS TEST".bold().underline());

    let mut engine = WidgetSuggestionEngine::new();

    // Common Kyma-style widgets
    let widgets = vec![
        create_kyma_widget("Amp_01", 0.0, 1.0, 0.75),
        create_kyma_widget("Amp_02", -1.0, 1.0, 0.2),
        create_kyma_widget("sw_00", 0.0, 1.0, 0.9),
        create_kyma_widget("Gate", 0.0, 1.0, 0.5),
        create_kyma_widget("cutoff", -24.0, 24.0, 5.0),
        create_kyma_widget("rate", 0.0, 1.0, 0.3),
        create_kyma_widget("morph", -1.0, 1.0, -0.4),
        create_kyma_widget("Amp_03", 0.0, 1.0, 0.8),
        create_kyma_widget("sw_01", 0.0, 1.0, 0.1),
        create_kyma_widget("morph2", -1.0, 1.0, 0.6),
    ];

    print_separator();
    println!(
        "{} {}",
        "".green(),
        "Storing Kyma-style widgets...".yellow()
    );

    for widget in widgets {
        engine.store_widget(widget);
    }

    println!(
        "{} {}",
        "".green(),
        format!("Stored {} widget records", engine.records.len()).cyan()
    );

    // Test suggestions for similar widgets
    let test_widget = Widget {
        label: Some("Amp_04".to_string()),
        minimum: Some(0.0),
        maximum: Some(1.0),
        ..Default::default()
    };

    let suggestions = engine.get_suggestions(&test_widget, 3);
    println!(
        "{} {}",
        "".green(),
        format!("Got {} suggestions for 'Amp_04'", suggestions.len()).cyan()
    );

    for suggestion in &suggestions {
        println!(
            "{} (confidence: {:.4})",
            suggestion
                .widget
                .label
                .as_deref()
                .unwrap_or("Unknown")
                .cyan(),
            suggestion.confidence.to_string().yellow()
        );
    }

    assert!(!suggestions.is_empty());
    println!("\n{}", "TEST PASSED".bold().green());
}

#[test]
fn test_realistic_presets() {
    colored::control::set_override(true);

    println!("\n{}", "REALISTIC PRESETS TEST".bold().underline());

    let mut engine = WidgetSuggestionEngine::new();

    // Store some widgets first
    engine.store_widget(create_kyma_widget("Amp_01", 0.0, 1.0, 0.8));
    engine.store_widget(create_kyma_widget("cutoff", 0.0, 3_500.0, 630.0));
    engine.store_widget(create_kyma_widget("Gate", 0.0, 1.0, 0.7));
    engine.store_widget(create_kyma_widget("rate", 0.0, 1.0, 0.4));
    engine.store_widget(create_kyma_widget("index", 0.0, 1.0, 0.22));
    engine.store_widget(create_kyma_widget("index", 0.0, 1.0, 0.82));

    // Create realistic presets
    let presets = vec![
        create_preset_data("FuzzySparks", {
            let mut values = HashMap::new();
            values.insert("13755".to_string(), 0.85);
            values.insert("13756".to_string(), 18.0);
            values.insert("13757".to_string(), 0.9);
            values
        }),
        create_preset_data("Default", {
            let mut values = HashMap::new();
            values.insert("13755".to_string(), 0.5);
            values.insert("13756".to_string(), 0.0);
            values.insert("13757".to_string(), 0.5);
            values
        }),
        create_preset_data("Default01", {
            let mut values = HashMap::new();
            values.insert("13755".to_string(), 0.6);
            values.insert("13756".to_string(), 2.0);
            values.insert("13757".to_string(), 0.4);
            values
        }),
        create_preset_data("SizzlingDrips", {
            let mut values = HashMap::new();
            values.insert("13755".to_string(), 0.95);
            values.insert("13756".to_string(), -8.0);
            values.insert("13757".to_string(), 0.1);
            values.insert("13758".to_string(), 0.75);
            values
        }),
    ];

    print_separator();
    println!(
        "{} {}",
        "".green(),
        "Storing realistic presets...".yellow()
    );

    for preset in presets {
        engine.store_preset(preset);
    }

    println!(
        "{} {}",
        "".green(),
        format!("Stored {} presets", engine.presets.len()).cyan()
    );

    // Test preset insights
    let test_widget = Widget {
        label: Some("Amp_01".to_string()),
        ..Default::default()
    };

    if let Some(insight) = engine.get_preset_insights(&test_widget) {
        println!(
            "{} {}",
            "".green(),
            format!("Preset insight: {}", insight).cyan()
        );
    }

    let stats = engine.get_stats();
    println!(
        "{} {}",
        "".green(),
        format!("Final stats: {:?}", stats).cyan()
    );

    assert_eq!(stats.get("total_presets"), Some(&4));
    println!("\n{}", "TEST PASSED".bold().green());
}

#[test]
fn test_value_ranges() {
    colored::control::set_override(true);

    println!("\n{}", "VALUE RANGES TEST".bold().underline());

    let mut engine = WidgetSuggestionEngine::new();

    // Test different common ranges
    let range_tests = vec![
        ("sw_00", 0.0, 1.0, 1.0),
        ("sw_01", 0.0, 1.0, 0.0),
        ("cutoff", 0.0, 8_000.0, 650.0),
        ("rate", -1.0, 1.0, 0.666),
        ("morph", 0.0, 1.0, 0.3),
        ("Gate", 0.0, 1.0, 1.0),
        ("Amp_01", 0.0, 1.0, 0.7),
        ("Amp_02", -1.0, 1.0, -0.4),
    ];

    print_separator();
    println!(
        "{} {}",
        "".green(),
        "Testing various value ranges...".yellow()
    );

    for (label, min, max, current) in range_tests {
        let widget = create_kyma_widget(label, min, max, current);
        engine.store_widget(widget);

        println!(
            "{} [{:.1}, {:.1}] = {:.1}",
            label.cyan(),
            min,
            max,
            current
        );
    }

    // Test similarity within the same ranges
    let test_widget = Widget {
        label: Some("index".to_string()),
        minimum: Some(0.0),
        maximum: Some(1.0),
        ..Default::default()
    };

    let suggestions = engine.get_suggestions(&test_widget, 3);
    println!(
        "\n{} {}",
        "".green(),
        format!(
            "Suggestions for {}",
            test_widget.label.as_deref().unwrap_or("Unknown")
        )
        .cyan()
    );

    for suggestion in &suggestions {
        println!(
            "{} (confidence: {:.4})",
            suggestion
                .widget
                .label
                .as_deref()
                .unwrap_or("Unknown")
                .cyan(),
            suggestion.confidence.to_string().yellow()
        );
    }

    assert!(!suggestions.is_empty());
    println!("\n{}", "TEST PASSED".bold().green());
}

#[test]
fn test_morph_variants() {
    colored::control::set_override(true);

    println!("\n{}", "MORPH VARIANTS TEST".bold().underline());

    let mut engine = WidgetSuggestionEngine::new();

    // Test various morph-style widgets
    let morph_widgets = vec![
        create_kyma_widget("morph", -1.0, 1.0, 0.3),
        create_kyma_widget("morph2", -1.0, 1.0, -0.7),
        create_kyma_widget("morph3", -1.0, 1.0, 0.1),
        create_kyma_widget("morph_x", -1.0, 1.0, 0.8),
        create_kyma_widget("morph_y", -1.0, 1.0, -0.2),
    ];

    print_separator();
    println!(
        "{} {}",
        "".green(),
        "Testing morph-style widgets...".yellow()
    );

    for widget in morph_widgets {
        engine.store_widget(widget);
    }

    // Test suggestions for new morph widget
    let test_widget = Widget {
        label: Some("morph4".to_string()),
        minimum: Some(-1.0),
        maximum: Some(1.0),
        ..Default::default()
    };

    let suggestions = engine.get_suggestions(&test_widget, 5);
    println!(
        "{} {}",
        "".green(),
        format!("Got {} suggestions for 'morph4'", suggestions.len()).cyan()
    );

    for suggestion in &suggestions {
        println!(
            "{} (confidence: {:.4})",
            suggestion
                .widget
                .label
                .as_deref()
                .unwrap_or("Unknown")
                .cyan(),
            suggestion.confidence.to_string().yellow()
        );
    }

    // Should find high similarity with other morph widgets
    assert!(suggestions.len() >= 3);
    assert!(suggestions[0].confidence > 0.7);

    println!("\n{}", "TEST PASSED".bold().green());
}

#[test]
fn test_amp_series() {
    colored::control::set_override(true);

    println!("\n{}", "AMP SERIES TEST".bold().underline());

    let mut engine = WidgetSuggestionEngine::new();

    // Test Amp series widgets
    let amp_widgets = vec![
        create_kyma_widget("Amp_01", 0.0, 1.0, 0.8),
        create_kyma_widget("Amp_02", 0.0, 1.0, 0.6),
        create_kyma_widget("Amp_03", 0.0, 1.0, 0.9),
        create_kyma_widget("Amp_04", 0.0, 1.0, 0.7),
        create_kyma_widget("Amp_05", 0.0, 1.0, 0.5),
    ];

    print_separator();
    println!(
        "{} {}",
        "".green(),
        "Testing Amp series widgets...".yellow()
    );

    for widget in amp_widgets {
        engine.store_widget(widget);
    }

    // Test suggestions for new Amp widget
    let test_widget = Widget {
        label: Some("Amp_06".to_string()),
        minimum: Some(0.0),
        maximum: Some(1.0),
        ..Default::default()
    };

    let suggestions = engine.get_suggestions(&test_widget, 5);
    println!(
        "{} {}",
        "".green(),
        format!("Got {} suggestions for 'Amp_06'", suggestions.len()).cyan()
    );

    for suggestion in &suggestions {
        println!(
            "{} (confidence: {:.4})",
            suggestion
                .widget
                .label
                .as_deref()
                .unwrap_or("Unknown")
                .cyan(),
            suggestion.confidence.to_string().yellow()
        );
    }

    // Should find high similarity with other Amp widgets
    assert!(!suggestions.is_empty());
    assert!(suggestions[0].confidence > 0.6);

    println!("\n{}", "TEST PASSED".bold().green());
}

fn print_separator() {
    println!("{}", "".repeat(80).blue());
}