shh_algo_PY

Ruffier

Mar 11th, 2023
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.25 KB | None | 0 0
  1. ''' Module for calculating the results of Ruffier tests.
  2.  
  3.  
  4. The sum of the three tries at pulse readings (before strain, right after strain, and after a short break)
  5. ideally, there should be no more than 200 beats per minute.
  6. We propose that the children measure their pulse for 15 seconds,
  7. and find the result of beats per minute by multiplying by 4:
  8.   S = 4 * (P1 + P2 + P3)
  9. The further the result is from the ideal 200 beats, the worse it is.
  10. Traditionally, tables are given by values divided by 10.
  11.  
  12.  
  13. Ruffier index  
  14.   IR = (S - 200) / 10
  15. is evaluated corresponding to age according to the table:
  16.       7–8             9–10                11–12               13–14               15+ (only for adolescents!)
  17. perfect    6.4 and below   4.9 and below       3.4 and below         1.9 and below               0.4 and below
  18. good    6.5–11.9     5–10.4          3.5–8.9           2–7.4                   0.5–5.9
  19. satisfactory  12–16.9      10.5–15.4       9–13.9            7.5–12.4                6–10.9
  20. weak  17–20.9      15.5–19.4       14–17.9           12.5–16.4               11–14.9
  21. unsatisfactory   21 and above     19.5 and above      18 and above          16.5 and above             15 and above
  22.  
  23.  
  24. the result “unsatisfactory” is 4 from the result “weak” for all ages,
  25. “weak” is separated from “satisfactory” by 5, and “good” from “satisfactory” by 5.5
  26.  
  27.  
  28. so we will write a function ruffier_result(r_index, level) which will produce
  29. the calculated Ruffier index and level “unsatisfactory” for the tested age, and produce a result
  30.  
  31.  
  32. '''
  33. # here the lines which produce the result are given
  34. txt_index = "Your Ruffier index: "
  35.  
  36. txt_workheart = "Heart efficiency: "
  37.  
  38. txt_nodata = '''
  39. there is no data for that age'''
  40.  
  41. txt_res = []
  42.  
  43. txt_res.append('''low.
  44. Go see your doctor ASAP!''')
  45.  
  46. txt_res.append('''satisfactory.
  47. Go see your doctor!''')
  48.  
  49. txt_res.append('''average.
  50. It might be worth additional tests at the doctor.''')
  51.  
  52. txt_res.append('''
  53. higher than average''')
  54.  
  55. txt_res.append('''
  56. high''')
  57.  
  58.  
  59. def ruffier_index(P1, P2, P3):
  60.    ''' it returns the index value according to the three pulse calculations for comparison with the table'''
  61.    return (4 * (P1+P2+P3) - 200) / 10
  62.  
  63.  
  64. def neud_level(age):
  65.    ''' the options with an age of less than 7 and with adults have to be processed separately,
  66.   here we select the level “unsatisfactory” only within the table:
  67.   for the age of 7, “unsatisfactory” is an index of 21, then onwards every 2 years it decreases by 1.5 until the level of 15 at age 15–16 '''
  68.    norm_age = (min(age, 15) - 7) // 2  # every two years the from age seven turns into one unit, all the way to age 15
  69.    result = 21 - norm_age * 1.5 # every two years multiply the difference by 1.5, that's how the levels are arranged in the table
  70.    return result
  71.  
  72. def ruffier_result(r_index, level):
  73.    ''' the function obtains a Ruffier index and interprets it,
  74.   we return the readiness level: a number from 0 to 4
  75.   (the higher the readiness level, the better).  '''
  76.    if r_index >= level:
  77.        return 0
  78.    level = level - 4 # this will not run if we already returned the answer “unsatisfactory”
  79.    if r_index >= level:
  80.        return 1
  81.    level = level - 5 # analogously, we end up here if the level is, at minimum, “satisfactory”
  82.    if r_index >= level:
  83.        return 2
  84.    level = level - 5.5 # next level
  85.    if r_index >= level:
  86.        return 3
  87.    return 4 # we end up here if the index is less than all the intermediate levels, that is, the tested circle.
  88.  
  89.  
  90. def test(P1, P2, P3, age):
  91.    ''' this function can be used from outside the module for calculating the Ruffier index.
  92.   We return the ready texts that just need to be written in the necessary place
  93.   We use the constants used at the beginning of this module for texts. '''
  94.    if age < 7:
  95.        return (txt_index + "0", txt_nodata) # this is a mystery beyond this test
  96.    else:
  97.        ruff_index = ruffier_index(P1, P2, P3) # calculation
  98.        result = txt_res[ruffier_result(ruff_index, neud_level(age))] # the interpretation and conversion of the numeric preparation level into text data
  99.        res = txt_index + str(ruff_index) + '\n' + txt_workheart + result
  100.        return res
Advertisement
Add Comment
Please, Sign In to add comment