Skip to content

Commit

Permalink
Create reports.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 3, 2024
1 parent a2299a9 commit bdfefa0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/analytics/reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// analytics/reports.js
const Analytics = require('./analytics');

class Reports {
constructor(analytics) {
this.analytics = analytics;
}

generateEventReport() {
const events = this.analytics.getEvents();
const report = events.map(event => ({
name: event.name,
data: event.data,
timestamp: event.timestamp.toISOString(),
}));

return {
totalEvents: events.length,
events: report,
};
}

generateSummaryReport() {
const events = this.analytics.getEvents();
const summary = {};

events.forEach(event => {
if (!summary[event.name]) {
summary[event.name] = 0;
}
summary[event.name]++;
});

return {
totalEvents: events.length,
summary: summary,
};
}
}

module.exports = Reports;

0 comments on commit bdfefa0

Please sign in to comment.