Advertisement
shh_algo_PY

Ruffier.py

Mar 18th, 2023
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.59 KB | None | 0 0
  1. txt_index = "Your Ruffier index: "
  2. txt_workheart = "Heart performance: "
  3. txt_nodata = '''
  4. there is no data for that age'''
  5. txt_res = []
  6. txt_res.append('''low.
  7. Go see your doctor ASAP!''')
  8. txt_res.append('''satisfactory.
  9. Go see your doctor!''')
  10. txt_res.append('''average.
  11. It might be worth doing additional tests at the doctor.''')
  12. txt_res.append('''
  13. higher than average''')
  14. txt_res.append('''
  15. high''')
  16.  
  17.  
  18. def ruffier_index(P1, P2, P3):
  19.    ''' it returns the index value according to the three heart rate calculations for comparison with the table'''
  20.    return (4 * (P1+P2+P3) - 200) / 10
  21.  
  22.  
  23. def neud_level(age):
  24.    ''' the options with an age of less than 7 and with adults have to be processed separately,
  25.   here we select the level “unsatisfactory” only within the table:
  26.   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 '''
  27.    norm_age = (min(age, 15) - 7) // 2  # every two years the from age seven difference is one, all the way to age 15
  28.    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
  29.    return result
  30.  
  31. def ruffier_result(r_index, level):
  32.    ''' the function obtains a Ruffier index and interprets it,
  33.   we return the readiness level: a number from 0 to 4
  34.   (the higher the readiness level, the better).  '''
  35.    if r_index >= level:
  36.        return 0
  37.    level = level - 4 # this will not run if we already returned the answer “unsatisfactory”
  38.    if r_index >= level:
  39.        return 1
  40.    level = level - 5 # similarly, we end up here if the level is at least “satisfactory”
  41.    if r_index >= level:
  42.        return 2
  43.    level = level - 5.5 # next level
  44.    if r_index >= level:
  45.        return 3
  46.    return 4 # we end up here if the index is less than all the intermediate levels, in other words, the tested circle.
  47.  
  48.  
  49. def test(P1, P2, P3, age):
  50.    ''' this function can be used from outside the module for calculating the Ruffier index.
  51.   We return the ready texts that just need to be written in the necessary place
  52.   We use the constants used at the beginning of this module for the texts. '''
  53.    if age < 7:
  54.        return (txt_index + "0", txt_nodata) # this is a mystery beyond this test
  55.    else:
  56.        ruff_index = ruffier_index(P1, P2, P3) # calculation
  57.        result = txt_res[ruffier_result(ruff_index, neud_level(age))] # the interpretation and conversion of the numeric preparation level into text data
  58.        res = txt_index + str(ruff_index) + '\n' + txt_workheart + result
  59.        return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement