-
Notifications
You must be signed in to change notification settings - Fork 0
/
meld.py
41 lines (27 loc) · 868 Bytes
/
meld.py
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
from math import log
def limit_lab(x, low=float('-inf'), hi=float('inf')):
if x < low:
return low
elif x > hi:
return hi
return x
def na_correct(na):
return limit_lab(na, 125, 137)
def cr_correct(cr):
return limit_lab(cr, 1.0, 4.0)
def tb_inr_correct(tb):
return limit_lab(tb, 1.0)
def meld_i(inr, tb, cr):
return (0.957 * log(cr_correct(cr)) +
0.378 * log(tb_inr_correct(tb)) +
1.120 * log(tb_inr_correct(inr)) +
0.643) * 10
def meld_no_rounding(na, inr, tb, cr):
m = meld_i(inr, tb, cr)
n = na_correct(na)
if m > 11: # interesting, what if it is 10.6, should it be "pre-rounded"?
m = m + 1.32 * (137 - n) - (0.033 * m * (137 - n))
return m
def meld(na, inr, tb, cr):
m = meld_no_rounding(na, inr, tb, cr)
return limit_lab(round(m), hi=40)