education-module-ai
Version:
AI Education Module using Agent Framework
192 lines (191 loc) • 6.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnalyticsPlugin = void 0;
/**
* Analytics Plugin for the Education Module
* Tracks and analyzes user interactions, content usage, and learning patterns
*/
class AnalyticsPlugin {
constructor() {
this.isInitialized = false;
this.sessionEvents = [];
this.contentEvents = [];
this.profileEvents = [];
this.learningPathEvents = [];
}
/**
* Initialize the analytics plugin
*/
async initialize() {
// In a real implementation, this would connect to an analytics service
console.log("Analytics Plugin: Initializing...");
this.isInitialized = true;
console.log("Analytics Plugin: Initialized successfully");
return Promise.resolve();
}
/**
* Track an analytics event
*/
async trackEvent(category, action, data) {
if (!this.isInitialized) {
console.warn("Analytics Plugin: Not initialized. Event not tracked.");
return;
}
const event = {
category,
action,
timestamp: new Date(),
data,
};
console.log(`Analytics Plugin: Tracked event - ${category}:${action}`);
// In a real implementation, this would send the event to an analytics service
// For demo purposes, we'll just store it in memory
switch (category) {
case "session":
this.sessionEvents.push(event);
break;
case "content":
this.contentEvents.push(event);
break;
case "profile":
this.profileEvents.push(event);
break;
case "learning_path":
this.learningPathEvents.push(event);
break;
default:
console.warn(`Analytics Plugin: Unknown category ${category}`);
}
}
/**
* Get analytics data for a specific category
*/
async getAnalytics(category) {
switch (category) {
case "session":
return this.sessionEvents;
case "content":
return this.contentEvents;
case "profile":
return this.profileEvents;
case "learning_path":
return this.learningPathEvents;
default:
throw new Error(`Unknown analytics category: ${category}`);
}
}
/**
* Generate a summary of analytics data
*/
async generateSummary() {
return {
sessionCount: this.sessionEvents.length,
contentCount: this.contentEvents.length,
profileCount: this.profileEvents.length,
learningPathCount: this.learningPathEvents.length,
lastUpdated: new Date(),
};
}
// Content event handlers
async onContentCreated(content) {
await this.trackEvent("content", "created", {
contentId: content.id,
subject: content.subject,
level: content.level,
type: content.type,
});
}
async onContentUpdated(content) {
await this.trackEvent("content", "updated", {
contentId: content.id,
subject: content.subject,
level: content.level,
});
}
async onContentDeleted(contentId) {
await this.trackEvent("content", "deleted", {
contentId,
});
}
// Session event handlers
async onSessionStarted(session) {
await this.trackEvent("session", "started", {
sessionId: session.id,
userId: session.userId,
subject: session.subject,
level: session.level,
});
}
async onSessionEnded(session) {
// Calculate session duration
const duration = session.endTime && session.startTime
? (session.endTime.getTime() - session.startTime.getTime()) / 1000 // in seconds
: 0;
await this.trackEvent("session", "ended", {
sessionId: session.id,
userId: session.userId,
subject: session.subject,
duration,
messageCount: session.messages.length,
feedback: session.feedback,
});
}
async onSessionMessageSent(session, message) {
await this.trackEvent("session", "message_sent", {
sessionId: session.id,
userId: session.userId,
messageRole: message.role,
interactionType: message.interactionType,
contentLength: message.content.length,
});
}
// Profile event handlers
async onProfileCreated(profile) {
await this.trackEvent("profile", "created", {
profileId: profile.id,
subjectCount: Object.keys(profile.subjectProgress).length,
learningStyles: profile.learningStyles,
});
}
async onProfileUpdated(profile) {
await this.trackEvent("profile", "updated", {
profileId: profile.id,
subjectCount: Object.keys(profile.subjectProgress).length,
learningStyles: profile.learningStyles,
});
}
// Learning path event handlers
async onLearningPathGenerated(path) {
await this.trackEvent("learning_path", "generated", {
pathId: path.id,
userId: path.userId,
topic: path.topic,
subject: path.subject,
difficultyLevel: path.difficultyLevel,
estimatedCompletionTime: path.estimatedCompletionTime,
stepCount: path.steps.length,
});
}
async onLearningPathCompleted(path) {
await this.trackEvent("learning_path", "completed", {
pathId: path.id,
userId: path.userId,
topic: path.topic,
subject: path.subject,
difficultyLevel: path.difficultyLevel,
});
}
/**
* Track learning path step completion
*/
async trackStepCompletion(userId, pathId, stepIndex, timeSpent // in seconds
) {
await this.trackEvent("learning_path", "step_completed", {
userId,
pathId,
stepIndex,
timeSpent,
});
}
}
exports.AnalyticsPlugin = AnalyticsPlugin;