Subh775 commited on
Commit
d04eb83
·
1 Parent(s): e0d9763

multi-feature optimization

Browse files
Files changed (1) hide show
  1. frontend/vehicles.html +47 -6
frontend/vehicles.html CHANGED
@@ -1292,15 +1292,32 @@
1292
  flowChart.update();
1293
  }
1294
 
 
 
1295
  function updateCongestion(congestion, stride) {
1296
- const len = congestion.length;
 
 
 
 
 
 
 
 
 
 
 
1297
  if (len <= 200) {
1298
- congChart.data.labels = congestion.map((_, i) => i * stride);
1299
- congChart.data.datasets[0].data = congestion;
1300
  } else {
1301
- const step = 10;
 
1302
  const sampled = [], labels = [];
1303
- for (let i = 0; i < len; i += step) { labels.push(i * stride); sampled.push(congestion[i]); }
 
 
 
1304
  congChart.data.labels = labels;
1305
  congChart.data.datasets[0].data = sampled;
1306
  }
@@ -1348,6 +1365,7 @@
1348
  const stride = parseInt(document.getElementById('sv-stride').textContent);
1349
  const reportFmt = document.getElementById('sv-report').value;
1350
  const annotated = document.getElementById('sv-annotated').classList.contains('active');
 
1351
 
1352
  // Annotation Options
1353
  const annotated_options = {
@@ -1481,7 +1499,30 @@
1481
  infoRow('Throughput (FPS)', d.actual_fps, 'Measured frame throughput during processing.', ' <span class="text-xs text-slate-400 font-normal">fps</span>') +
1482
  infoRow('Real-time Ratio', d.speed_vs_realtime + 'x', 'Processing speed relative to video playback rate.');
1483
 
1484
- if (d.video_id) loadReports(d.video_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1485
 
1486
  // Show New Analysis button in Settings
1487
  const newWrap = document.getElementById('new-analysis-wrap');
 
1292
  flowChart.update();
1293
  }
1294
 
1295
+ let _alpha = 0.25;
1296
+
1297
  function updateCongestion(congestion, stride) {
1298
+ let data = congestion;
1299
+ // Apply EMA smoothing if alpha is less than 1 (1 = no smoothing)
1300
+ if (_alpha < 0.99) {
1301
+ data = [];
1302
+ let s = congestion[0] || 0;
1303
+ for (let v of congestion) {
1304
+ s = _alpha * v + (1 - _alpha) * s;
1305
+ data.push(s);
1306
+ }
1307
+ }
1308
+
1309
+ const len = data.length;
1310
  if (len <= 200) {
1311
+ congChart.data.labels = data.map((_, i) => i * stride);
1312
+ congChart.data.datasets[0].data = data;
1313
  } else {
1314
+ // Dynamic sampling to keep chart performance high
1315
+ const step = Math.ceil(len / 200);
1316
  const sampled = [], labels = [];
1317
+ for (let i = 0; i < len; i += step) {
1318
+ labels.push(i * stride);
1319
+ sampled.push(data[i]);
1320
+ }
1321
  congChart.data.labels = labels;
1322
  congChart.data.datasets[0].data = sampled;
1323
  }
 
1365
  const stride = parseInt(document.getElementById('sv-stride').textContent);
1366
  const reportFmt = document.getElementById('sv-report').value;
1367
  const annotated = document.getElementById('sv-annotated').classList.contains('active');
1368
+ _alpha = parseFloat(document.getElementById('sv-smoothing').textContent) || 0.25;
1369
 
1370
  // Annotation Options
1371
  const annotated_options = {
 
1499
  infoRow('Throughput (FPS)', d.actual_fps, 'Measured frame throughput during processing.', ' <span class="text-xs text-slate-400 font-normal">fps</span>') +
1500
  infoRow('Real-time Ratio', d.speed_vs_realtime + 'x', 'Processing speed relative to video playback rate.');
1501
 
1502
+ if (d.video_id) {
1503
+ loadReports(d.video_id);
1504
+
1505
+ // Auto-Download Logic
1506
+ if (document.getElementById('sv-auto-download').classList.contains('active')) {
1507
+ console.log('[UrbanFlow] Auto-download triggered...');
1508
+ setTimeout(() => {
1509
+ fetch(`/reports_list/${d.video_id}`)
1510
+ .then(r => r.json())
1511
+ .then(res => {
1512
+ const pdf = res.files.find(f => f.endsWith('.pdf'));
1513
+ if (pdf) {
1514
+ const link = document.createElement('a');
1515
+ link.href = `/reports/${d.video_id}/${pdf}`;
1516
+ link.download = pdf;
1517
+ document.body.appendChild(link);
1518
+ link.click();
1519
+ document.body.removeChild(link);
1520
+ }
1521
+ })
1522
+ .catch(err => console.error('[UrbanFlow] Auto-download failed:', err));
1523
+ }, 2500); // 2.5s buffer for PDF generation
1524
+ }
1525
+ }
1526
 
1527
  // Show New Analysis button in Settings
1528
  const newWrap = document.getElementById('new-analysis-wrap');