-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.js
More file actions
269 lines (242 loc) · 8.9 KB
/
Copy pathanalytics.js
File metadata and controls
269 lines (242 loc) · 8.9 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
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
// Project: Surveillance Video Dataset
// Author: Molla Samser
// Website: https://rskworld.in/
// Contact: help@rskworld.in
// Phone: +91 93305 39277
// Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
// Analytics Dashboard JavaScript
let detectionsChart, anomalyChart, activityChart, processingChart;
// Initialize dashboard
document.addEventListener('DOMContentLoaded', function() {
loadAnalyticsData();
initializeCharts();
startRealTimeUpdates();
});
function loadAnalyticsData() {
// Load data from API or local files
fetch('api/analytics')
.then(response => response.json())
.then(data => {
updateStatistics(data);
updateCharts(data);
updateTimeline(data.events);
})
.catch(() => {
// Fallback to sample data
const sampleData = getSampleAnalyticsData();
updateStatistics(sampleData);
updateCharts(sampleData);
updateTimeline(sampleData.events);
});
}
function getSampleAnalyticsData() {
return {
totalVideos: 2,
totalDetections: 156,
totalAnomalies: 2,
totalHours: 0.5,
detections: [45, 52, 38, 21],
anomalies: { 'unusual_movement': 2, 'rapid_change': 0 },
activities: { 'walking': 45, 'standing': 38, 'running': 12 },
events: [
{ time: '10:30:15', type: 'detection', message: 'Person detected in frame', video: 'sample.mp4' },
{ time: '10:30:45', type: 'anomaly', message: 'Anomaly detected - rapid movement', video: 'sample2.mp4' },
{ time: '10:31:20', type: 'detection', message: 'Multiple persons detected', video: 'sample2.mp4' }
]
};
}
function updateStatistics(data) {
document.getElementById('totalVideos').textContent = data.totalVideos || 0;
document.getElementById('totalDetections').textContent = data.totalDetections || 0;
document.getElementById('totalAnomalies').textContent = data.totalAnomalies || 0;
document.getElementById('totalHours').textContent = data.totalHours || 0;
}
function initializeCharts() {
// Detections Chart
const detectionsCtx = document.getElementById('detectionsChart').getContext('2d');
detectionsChart = new Chart(detectionsCtx, {
type: 'line',
data: {
labels: ['00:00', '00:05', '00:10', '00:15'],
datasets: [{
label: 'Person Detections',
data: [45, 52, 38, 21],
borderColor: '#667eea',
backgroundColor: 'rgba(102, 126, 234, 0.1)',
tension: 0.4
}]
},
options: {
responsive: true,
maintainAspectRatio: true
}
});
// Anomaly Chart
const anomalyCtx = document.getElementById('anomalyChart').getContext('2d');
anomalyChart = new Chart(anomalyCtx, {
type: 'doughnut',
data: {
labels: ['Unusual Movement', 'Rapid Change', 'Normal'],
datasets: [{
data: [2, 0, 154],
backgroundColor: ['#dc3545', '#ffc107', '#28a745']
}]
},
options: {
responsive: true,
maintainAspectRatio: true
}
});
// Activity Chart
const activityCtx = document.getElementById('activityChart').getContext('2d');
activityChart = new Chart(activityCtx, {
type: 'bar',
data: {
labels: ['Walking', 'Standing', 'Running', 'Other'],
datasets: [{
label: 'Activities',
data: [45, 38, 12, 8],
backgroundColor: '#667eea'
}]
},
options: {
responsive: true,
maintainAspectRatio: true
}
});
// Processing Chart
const processingCtx = document.getElementById('processingChart').getContext('2d');
processingChart = new Chart(processingCtx, {
type: 'bar',
data: {
labels: ['Processed', 'Pending', 'Failed'],
datasets: [{
label: 'Videos',
data: [2, 0, 0],
backgroundColor: ['#28a745', '#ffc107', '#dc3545']
}]
},
options: {
responsive: true,
maintainAspectRatio: true
}
});
}
function updateCharts(data) {
if (detectionsChart && data.detections) {
detectionsChart.data.datasets[0].data = data.detections;
detectionsChart.update();
}
if (anomalyChart && data.anomalies) {
const values = Object.values(data.anomalies);
anomalyChart.data.datasets[0].data = [...values, data.totalDetections - values.reduce((a, b) => a + b, 0)];
anomalyChart.update();
}
if (activityChart && data.activities) {
activityChart.data.datasets[0].data = Object.values(data.activities);
activityChart.update();
}
}
function updateTimeline(events) {
const timeline = document.getElementById('eventsTimeline');
timeline.innerHTML = '';
if (!events || events.length === 0) {
timeline.innerHTML = '<p>No recent events</p>';
return;
}
events.forEach(event => {
const item = document.createElement('div');
item.className = 'timeline-item';
const icon = event.type === 'anomaly' ? 'fa-exclamation-triangle' : 'fa-user';
const color = event.type === 'anomaly' ? '#dc3545' : '#667eea';
item.innerHTML = `
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<i class="fas ${icon}" style="color: ${color}; margin-right: 10px;"></i>
<strong>${event.message}</strong>
<span style="color: #666; margin-left: 10px;">${event.video}</span>
</div>
<span style="color: #666;">${event.time}</span>
</div>
`;
timeline.appendChild(item);
});
}
function applyFilters() {
const dateFilter = document.getElementById('dateFilter').value;
const videoFilter = document.getElementById('videoFilter').value;
const anomalyFilter = document.getElementById('anomalyFilter').value;
// Apply filters and reload data
loadAnalyticsData();
console.log('Filters applied:', { dateFilter, videoFilter, anomalyFilter });
}
function exportData(format) {
const data = getSampleAnalyticsData();
switch(format) {
case 'json':
downloadJSON(data, 'analytics_data.json');
break;
case 'csv':
downloadCSV(data, 'analytics_data.csv');
break;
case 'pdf':
window.print();
break;
}
}
function downloadJSON(data, filename) {
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
function downloadCSV(data, filename) {
let csv = 'Metric,Value\n';
csv += `Total Videos,${data.totalVideos}\n`;
csv += `Total Detections,${data.totalDetections}\n`;
csv += `Total Anomalies,${data.totalAnomalies}\n`;
csv += `Total Hours,${data.totalHours}\n`;
const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
function startRealTimeUpdates() {
// Simulate real-time updates every 5 seconds
setInterval(() => {
// In production, this would fetch from API
const newEvent = {
time: new Date().toLocaleTimeString(),
type: Math.random() > 0.8 ? 'anomaly' : 'detection',
message: 'New event detected',
video: 'sample.mp4'
};
// Add to timeline
const timeline = document.getElementById('eventsTimeline');
const item = document.createElement('div');
item.className = 'timeline-item';
const icon = newEvent.type === 'anomaly' ? 'fa-exclamation-triangle' : 'fa-user';
const color = newEvent.type === 'anomaly' ? '#dc3545' : '#667eea';
item.innerHTML = `
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<i class="fas ${icon}" style="color: ${color}; margin-right: 10px;"></i>
<strong>${newEvent.message}</strong>
<span style="color: #666; margin-left: 10px;">${newEvent.video}</span>
</div>
<span style="color: #666;">${newEvent.time}</span>
</div>
`;
timeline.insertBefore(item, timeline.firstChild);
// Keep only last 10 events
while (timeline.children.length > 10) {
timeline.removeChild(timeline.lastChild);
}
}, 5000);
}