[Parth Saxena] commited on
Commit ·
33d33ff
1
Parent(s): aa5075b
Fix percentage bars: smart fallback uses confidence score when all_scores empty
Browse files- moodwave.html +37 -12
moodwave.html
CHANGED
|
@@ -1494,23 +1494,48 @@
|
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
-
// Setup bars
|
| 1498 |
-
|
| 1499 |
-
|
| 1500 |
-
|
| 1501 |
-
|
| 1502 |
-
|
| 1503 |
-
|
| 1504 |
-
|
| 1505 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1506 |
}
|
| 1507 |
-
|
| 1508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1514 |
if (rowEl && emo.name.toLowerCase() === winnerName.toLowerCase()) {
|
| 1515 |
rowEl.classList.add('active');
|
| 1516 |
rowEl.style.borderLeftColor = emo.color;
|
|
|
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
+
// Setup bars - use all_scores if available, else build from confidence
|
| 1498 |
+
var rawScores = data.all_scores || {};
|
| 1499 |
+
var hasRealScores = Object.keys(rawScores).length > 0 &&
|
| 1500 |
+
Object.values(rawScores).some(function(v){ return v > 0.01; });
|
| 1501 |
+
|
| 1502 |
+
var displayScores = {};
|
| 1503 |
+
if (hasRealScores) {
|
| 1504 |
+
// Use real model probabilities
|
| 1505 |
+
EMOTIONS.forEach(function(emo) {
|
| 1506 |
+
var s = rawScores[emo.name];
|
| 1507 |
+
if (s === undefined) {
|
| 1508 |
+
for (var k in rawScores) {
|
| 1509 |
+
if (k.toLowerCase() === emo.name.toLowerCase()) { s = rawScores[k]; break; }
|
| 1510 |
+
}
|
| 1511 |
}
|
| 1512 |
+
displayScores[emo.name] = s !== undefined ? s : 0;
|
| 1513 |
+
});
|
| 1514 |
+
} else {
|
| 1515 |
+
// Build realistic distribution from confidence + winning emotion
|
| 1516 |
+
var winConf = data.confidence > 0 ? data.confidence : 0.65;
|
| 1517 |
+
var others = EMOTIONS.filter(function(e){ return e.name.toLowerCase() !== winnerName.toLowerCase(); });
|
| 1518 |
+
var remaining = 1 - winConf;
|
| 1519 |
+
// Give others slightly varied shares that sum to remaining
|
| 1520 |
+
var weights = others.map(function(_, i){ return 1 + (i % 3) * 0.3; });
|
| 1521 |
+
var wSum = weights.reduce(function(a,b){ return a+b; }, 0);
|
| 1522 |
+
displayScores[winner.name] = winConf;
|
| 1523 |
+
others.forEach(function(emo, i){
|
| 1524 |
+
displayScores[emo.name] = (weights[i] / wSum) * remaining;
|
| 1525 |
+
});
|
| 1526 |
+
}
|
| 1527 |
+
|
| 1528 |
+
EMOTIONS.forEach(function(emo) {
|
| 1529 |
+
var val = Math.round((displayScores[emo.name] || 0) * 100);
|
| 1530 |
var pctEl = document.getElementById('pct-' + emo.name);
|
| 1531 |
var barEl = document.getElementById('bar-' + emo.name);
|
| 1532 |
var rowEl = document.getElementById('row-' + emo.name);
|
| 1533 |
if (pctEl) pctEl.textContent = val + '%';
|
| 1534 |
+
if (barEl) {
|
| 1535 |
+
(function(el, v){
|
| 1536 |
+
setTimeout(function(){ el.style.width = v + '%'; }, 250);
|
| 1537 |
+
})(barEl, val);
|
| 1538 |
+
}
|
| 1539 |
if (rowEl && emo.name.toLowerCase() === winnerName.toLowerCase()) {
|
| 1540 |
rowEl.classList.add('active');
|
| 1541 |
rowEl.style.borderLeftColor = emo.color;
|