[Parth Saxena] commited on
Commit
aa5075b
·
1 Parent(s): e282990

Fix bars: robust EMOTIONS.forEach update + console.log debug

Browse files
Files changed (1) hide show
  1. moodwave.html +19 -32
moodwave.html CHANGED
@@ -1495,40 +1495,27 @@
1495
 
1496
 
1497
  // Setup bars based on API result
1498
-
1499
- const confidences = data.all_scores;
1500
-
1501
- for (let emoName in confidences) {
1502
-
1503
- const emo = EMOTIONS.find(e => e.name.toLowerCase() === emoName.toLowerCase());
1504
-
1505
- if (emo) {
1506
-
1507
- const val = Math.round(confidences[emoName] * 100);
1508
-
1509
- const row = document.getElementById(`row-${emo.name}`);
1510
-
1511
- document.getElementById(`pct-${emo.name}`).textContent = `${val}%`;
1512
-
1513
-
1514
-
1515
- setTimeout(() => { document.getElementById(`bar-${emo.name}`).style.width = `${val}%`; }, 100);
1516
-
1517
-
1518
-
1519
- if (emo.name.toLowerCase() === winnerName.toLowerCase()) {
1520
-
1521
- row.classList.add('active');
1522
-
1523
- row.style.borderLeftColor = emo.color;
1524
-
1525
  }
1526
-
1527
  }
1528
-
1529
- }
1530
-
1531
-
 
 
 
 
 
 
 
1532
 
1533
  // Setup advice
1534
 
 
1495
 
1496
 
1497
  // Setup bars based on API result
1498
+ console.log('[DEBUG] all_scores:', JSON.stringify(data.all_scores));
1499
+ const confidences = data.all_scores || {};
1500
+ EMOTIONS.forEach(function(emo) {
1501
+ var score = confidences[emo.name];
1502
+ if (score === undefined) {
1503
+ // Try case-insensitive match
1504
+ for (var k in confidences) {
1505
+ if (k.toLowerCase() === emo.name.toLowerCase()) { score = confidences[k]; break; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1506
  }
 
1507
  }
1508
+ var val = score !== undefined ? Math.round(score * 100) : 0;
1509
+ var pctEl = document.getElementById('pct-' + emo.name);
1510
+ var barEl = document.getElementById('bar-' + emo.name);
1511
+ var rowEl = document.getElementById('row-' + emo.name);
1512
+ if (pctEl) pctEl.textContent = val + '%';
1513
+ if (barEl) setTimeout(function(b, v){ return function(){ b.style.width = v + '%'; }; }(barEl, val), 200);
1514
+ if (rowEl && emo.name.toLowerCase() === winnerName.toLowerCase()) {
1515
+ rowEl.classList.add('active');
1516
+ rowEl.style.borderLeftColor = emo.color;
1517
+ }
1518
+ });
1519
 
1520
  // Setup advice
1521