Browse Source

身高体重评分

master
王泽彦 10 months ago
parent
commit
fc6db6110c
  1. 67
      niucloud/app/common.php

67
niucloud/app/common.php

@ -1151,4 +1151,71 @@ function decryptWechatPayNotify($ciphertext, $nonce, $associatedData, $key)
function isPhone($mobile) function isPhone($mobile)
{ {
return preg_match('/^1[3456789]\d{9}$/', $mobile); return preg_match('/^1[3456789]\d{9}$/', $mobile);
}
/**
* 体测评分
* @param int $age年龄
* @param int $gender性别( 1:男,2:女)
* @param int $height身高
* @param int $weight体重
*/
function calculateChildHealthScore($age, $gender, $height, $weight) {
// WHO 标准数据(简化版)——单位:cm/kg
// 示例使用中位数及上下限估算(实际可使用更精确的Z-score或百分位表)
$reference = [
'1' => [
3 => ['height_median' => 96.5, 'height_low' => 91.5, 'height_high' => 101.5, 'weight_median' => 14.2, 'weight_low' => 12.3, 'weight_high' => 16.5],
5 => ['height_median' => 110.0, 'height_low' => 104.5, 'height_high' => 115.5, 'weight_median' => 18.0, 'weight_low' => 15.6, 'weight_high' => 21.0],
7 => ['height_median' => 123.0, 'height_low' => 117.0, 'height_high' => 129.0, 'weight_median' => 22.5, 'weight_low' => 19.5, 'weight_high' => 26.0],
10 => ['height_median' => 138.0, 'height_low' => 131.0, 'height_high' => 145.0, 'weight_median' => 29.5, 'weight_low' => 25.5, 'weight_high' => 34.0],
12 => ['height_median' => 148.5, 'height_low' => 141.0, 'height_high' => 156.0, 'weight_median' => 36.0, 'weight_low' => 31.0, 'weight_high' => 42.0],
15 => ['height_median' => 164.0, 'height_low' => 155.0, 'height_high' => 173.0, 'weight_median' => 50.0, 'weight_low' => 43.0, 'weight_high' => 58.0],
18 => ['height_median' => 170.0, 'height_low' => 161.0, 'height_high' => 179.0, 'weight_median' => 58.0, 'weight_low' => 50.0, 'weight_high' => 67.0],
],
'2' => [
3 => ['height_median' => 95.5, 'height_low' => 90.5, 'height_high' => 100.5, 'weight_median' => 13.8, 'weight_low' => 12.0, 'weight_high' => 16.0],
5 => ['height_median' => 109.0, 'height_low' => 103.5, 'height_high' => 114.5, 'weight_median' => 17.8, 'weight_low' => 15.3, 'weight_high' => 20.5],
7 => ['height_median' => 122.0, 'height_low' => 116.0, 'height_high' => 128.0, 'weight_median' => 22.0, 'weight_low' => 19.0, 'weight_high' => 25.5],
10 => ['height_median' => 137.0, 'height_low' => 130.0, 'height_high' => 144.0, 'weight_median' => 29.0, 'weight_low' => 25.0, 'weight_high' => 33.5],
12 => ['height_median' => 150.0, 'height_low' => 142.0, 'height_high' => 158.0, 'weight_median' => 37.0, 'weight_low' => 31.5, 'weight_high' => 43.0],
15 => ['height_median' => 158.0, 'height_low' => 150.0, 'height_high' => 166.0, 'weight_median' => 48.0, 'weight_low' => 41.0, 'weight_high' => 56.0],
18 => ['height_median' => 159.0, 'height_low' => 152.0, 'height_high' => 166.0, 'weight_median' => 53.0, 'weight_low' => 46.0, 'weight_high' => 61.0],
]
];
if (!isset($reference[$gender][$age])) {
return 0; // 年龄不在范围内
}
$data = $reference[$gender][$age];
// 身高评分(线性插值)
$height_score = 100;
if ($height < $data['height_low']) {
$height_score = max(0, 50 * ($height - $data['height_low']) / ($data['height_median'] - $data['height_low']));
} elseif ($height > $data['height_high']) {
$height_score = max(0, 50 + 50 * ($data['height_high'] - $height) / ($data['height_high'] - $data['height_median']));
} else {
$height_score = 50 + 50 * (abs($height - $data['height_median']) / ($data['height_median'] - $data['height_low'])) * ($height > $data['height_median'] ? 1 : -1);
$height_score = max(0, min(100, $height_score));
}
// 体重评分
$weight_score = 100;
if ($weight < $data['weight_low']) {
$weight_score = max(0, 50 * ($weight - $data['weight_low']) / ($data['weight_median'] - $data['weight_low']));
} elseif ($weight > $data['weight_high']) {
$weight_score = max(0, 50 + 50 * ($data['weight_high'] - $weight) / ($data['weight_high'] - $data['weight_median']));
} else {
$weight_score = 50 + 50 * (abs($weight - $data['weight_median']) / ($data['weight_median'] - $data['weight_low'])) * ($weight > $data['weight_median'] ? 1 : -1);
$weight_score = max(0, min(100, $weight_score));
}
// 综合评分
$total_score = ($height_score + $weight_score) / 2;
// 四舍五入取整
return round($total_score);
} }
Loading…
Cancel
Save