feat(h5): calculate integer total from weighted dimensions across reports and admin
This commit is contained in:
+16
-2
@@ -63,6 +63,18 @@
|
||||
}
|
||||
function round2(x) { return Math.round((x + 1e-9) * 100) / 100; } // 1e-9 修正 9.445 类浮点
|
||||
function sRaw(P) { return 7 + 3 * P / 100; }
|
||||
// One shared 100-point total for H5, saved reports and admin. Never use the
|
||||
// upstream total or reweight an incomplete set of dimensions.
|
||||
function weightedTotal(dims) {
|
||||
if (!dims) return null;
|
||||
var keys = ['firm', 'vita', 'stab'], weights = [4, 3, 3], total = 0;
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var score = dims[keys[i]] && dims[keys[i]].S;
|
||||
if (!isNum(score) || score < 0 || score > 10) return null;
|
||||
total += score * weights[i];
|
||||
}
|
||||
return Math.round(total + 1e-9);
|
||||
}
|
||||
function sShow(P) { // 展示层钳制:P 可为负(肤色扣分/大面积敏感),S 会 <7,与文档「S 7.0–10.0」口径矛盾;
|
||||
if (P == null) return null; // 仅钳展示值,推荐边界比较仍用未舍入维度 S 原值
|
||||
var s = sRaw(P);
|
||||
@@ -814,7 +826,8 @@
|
||||
careAdvice.push({ tag: '生活方式', text: worst ? LIFESTYLE[worst.catKey] : '' });
|
||||
|
||||
return {
|
||||
total: pick(r, 'total_score'),
|
||||
total: weightedTotal(dims),
|
||||
totalRule: 'dimensions-433-v1',
|
||||
skinAgeRaw: skinAge,
|
||||
skinAgeDisplay: skinAgeDisplay,
|
||||
ageClampNote: ageClampNote,
|
||||
@@ -902,6 +915,7 @@
|
||||
return val(result && result.skin_age);
|
||||
}
|
||||
return {
|
||||
weightedTotal: weightedTotal,
|
||||
reportSkinAge: reportSkinAge,
|
||||
buildViewModel: buildViewModel,
|
||||
recommendProduct: recommendProduct,
|
||||
@@ -952,7 +966,7 @@ if (typeof require === 'function' && typeof module !== 'undefined' && require.ma
|
||||
ok(vm.avgS === 9.32, '六分类S均分 9.32');
|
||||
ok(vm.worst.catKey === 'wrinkles' && vm.worst.P === 23, '最差分类 = 皱纹');
|
||||
ok(vm.focus.name === '紧塑力', '近期优先关注 = 最差维度紧塑力');
|
||||
ok(vm.total === 79, '综合评分 = score_info.total_score');
|
||||
ok(vm.total === 88, '综合得分 = round(7.69×4+9.45×3+9.55×3) = 88,不使用接口总分79');
|
||||
ok(vm.summary.indexOf('【综合】') === 0 && vm.summary.indexOf('25+束紧精华') > 0, '综合文案生成');
|
||||
ok(vm.cats.smooth.text.indexOf('粗大毛孔296颗、黑头39颗') >= 0 && vm.cats.smooth.text.indexOf('纹理分87') >= 0,
|
||||
'光滑话术含粗大毛孔/黑头/纹理分变量(分区计数 4 区求和 296)');
|
||||
|
||||
Reference in New Issue
Block a user