一则使用体表温度和环境温度推算出核心体温的算法

样例

Python代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

class DegreeC(float):
'''摄氏温度对象'''
pass

# 通过Ta测算出正常的温度区间
def __caculateInterval(Ta: DegreeC):
'''
测算区间
'''
if Ta <= 25:
Tf_low = 32.66 + 0.186 * ( Ta - 25 )
Tf_high = 34.84 + 0.148 * (Ta - 25)
else:
Tf_low = 32.66 + 0.086 * (Ta - 25)
Tf_high=34.84 + 0.100*(Ta - 25)
return Tf_low, Tf_high

def getBodyTemp(Tf: DegreeC, Ta: DegreeC):
'''
计算身体温度

:param Tf: 测量温度,体表温度
:param Ta: 环境温度
:type Tf: DegreeC
:type TaL DegreeC

:return: 身体温度
:rtype: DegreeC
'''
Tf_low,Tf_high = __caculateInterval(Ta)

if Tf_low <= Tf <= Tf_high:
Tbody = 36.3 + 0.5 / (Tf_high - Tf_low) * (Tf-Tf_low)
elif Tf > Tf_high:
Tbody = 36.8 + ( 0.829320618 + 0.002364434 * Ta) * (Tf - Tf_high)
elif Tf < Tf_low:
Tbody = 36.3 + ( 0.551658273 + 0.021525068 * Ta) * (Tf - Tf_low)

return Tbody

if __name__ == '__main__':

Tb = getBodyTemp(Tf=34.5, Ta=25) # 测试样例
print(Tb)
# 返回36.72201834862385


Arduino代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "stdio.h"

float getBodyTemperature(float Ta, float Tf) // Ta: 环境温度, Tf: 测量温度
{
// 先对室温分类,计算出Tf_high, Tf_low
float Tf_low;
float Tf_high;

if (Ta <= 25)
{
Tf_low = 32.66 + 0.186 * (Ta - 25);
Tf_high = 34.84 + 0.148 * (Ta - 25);
}
else
{
Tf_low = 32.66 + 0.086 * (Ta - 25);
Tf_high = 34.84 + 0.100 * (Ta - 25);
}

// 然后分情况求体温
float Tbody;
if (Tf_low <= Tf <= Tf_high)
{
Tbody = 36.3 + 0.5 / (Tf_high - Tf_low) * (Tf - Tf_low);
}
else if (Tf > Tf_high)
{
Tbody = 36.8 + (0.829320618 + 0.002364434 * Ta) * (Tf - Tf_high);
}
else if (Tf < Tf_low)
{
Tbody = 36.3 + (0.551658273 + 0.021525068 * Ta) * (Tf - Tf_low);
}
return Tbody;
}

int main()
{
float Ta = 25;
float Tf = 30;
float Tbody = getBodyTemperature(Ta, Tf);
printf("Tbody = %f\n", Tbody);
return 0;
}