-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsights-engine-demo.ts
More file actions
73 lines (61 loc) · 2.54 KB
/
insights-engine-demo.ts
File metadata and controls
73 lines (61 loc) · 2.54 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
/**
* Insights Engine Demo
*
* Demonstrates the automated insights generation from multiple related datasets.
*/
import { EAVStore, jsonEntityFacts } from '../src/eav-engine.js';
import { InsightsEngine } from '../src/analytics/insights-engine.js';
import { readFileSync } from 'fs';
async function runDemo() {
console.log('🔍 Starting Insights Engine Demo');
console.log('-------------------------------');
// Load datasets
const postsData = JSON.parse(readFileSync('./data/real-posts.json', 'utf-8'));
const usersData = JSON.parse(readFileSync('./data/real-users.json', 'utf-8'));
// Create EAV stores
const postsStore = new EAVStore();
const usersStore = new EAVStore();
console.log('📊 Loading Posts dataset...');
// Convert posts to EAV facts
postsData.forEach((post: any, index: number) => {
const postId = `post:${post.id || index}`;
const facts = jsonEntityFacts(postId, post, 'post');
postsStore.addFacts(facts);
});
console.log('👤 Loading Users dataset...');
// Convert users to EAV facts
usersData.forEach((user: any, index: number) => {
const userId = `user:${user.id || index}`;
const facts = jsonEntityFacts(userId, user, 'user');
usersStore.addFacts(facts);
});
// Create insights engine
const insightsEngine = new InsightsEngine({
confidenceThreshold: 0.5,
maxInsights: 10,
verbose: true
});
// Register datasets
console.log('🔄 Registering datasets with the insights engine...');
insightsEngine.registerDataset('posts', postsStore);
insightsEngine.registerDataset('users', usersStore);
// Generate insights
console.log('✨ Generating insights...');
const insights = insightsEngine.generateInsights();
// Display insights
console.log(`\n📈 Generated ${insights.length} insights:\n`);
insights.forEach((insight, index) => {
console.log(`Insight ${index + 1}: ${insight.title}`);
console.log(`Type: ${insight.type}`);
console.log(`Confidence: ${(insight.confidence * 100).toFixed(1)}%`);
console.log(`Description: ${insight.description}`);
console.log(`Query: ${insight.query}`);
console.log(`Datasets: ${insight.datasets.join(', ')}`);
console.log(`Entity Types: ${insight.entityTypes.join(', ')}`);
console.log(`Attributes: ${insight.attributes.join(', ')}`);
console.log('-------------------------------');
});
}
runDemo().catch(err => {
console.error('Error in insights demo:', err);
});