Skip to content

Instantly share code, notes, and snippets.

@andermoran
Created October 26, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andermoran/88fead79a37f2ffed54038497576e472 to your computer and use it in GitHub Desktop.
Save andermoran/88fead79a37f2ffed54038497576e472 to your computer and use it in GitHub Desktop.
Calculate a person's height given a size of their bone, race, sex, and age
bone_coefficient = -1;
addition_constant = -1;
error_margin = -1;
bone_length = -1;
bone_coefficients = [[[0 for col in range(2)]for row in range(3)] for x in range(6)]
# Femur
bone_coefficients[0][0][0] = 2.32
bone_coefficients[0][0][1] = 2.47
bone_coefficients[0][1][0] = 2.10
bone_coefficients[0][1][1] = 2.28
bone_coefficients[0][2][0] = 2.15
bone_coefficients[0][2][1] = None
# Tibia
bone_coefficients[1][0][0] = 2.42
bone_coefficients[1][0][1] = 2.90
bone_coefficients[1][1][0] = 2.19
bone_coefficients[1][1][1] = 2.45
bone_coefficients[1][2][0] = 2.39
bone_coefficients[1][2][1] = None
# Fibula
bone_coefficients[2][0][0] = 2.60
bone_coefficients[2][0][1] = 2.93
bone_coefficients[2][1][0] = 2.34
bone_coefficients[2][1][1] = 2.49
bone_coefficients[2][2][0] = 2.40
bone_coefficients[2][2][1] = None
# Humerus
bone_coefficients[3][0][0] = 2.89
bone_coefficients[3][0][1] = 3.36
bone_coefficients[3][1][0] = 2.88
bone_coefficients[3][1][1] = 3.08
bone_coefficients[3][2][0] = 2.68
bone_coefficients[3][2][1] = None
# Ulna
bone_coefficients[4][0][0] = 3.76
bone_coefficients[4][0][1] = 4.27
bone_coefficients[4][1][0] = 3.20
bone_coefficients[4][1][1] = 3.31
bone_coefficients[4][2][0] = 3.48
bone_coefficients[4][2][1] = None
# Radius
bone_coefficients[5][0][0] = 3.79
bone_coefficients[5][0][1] = 4.74
bone_coefficients[5][1][0] = 3.32
bone_coefficients[5][1][1] = 3.67
bone_coefficients[5][2][0] = 3.54
bone_coefficients[5][2][1] = None
addition_constants = [[[0 for col in range(2)]for row in range(3)] for x in range(6)]
# Femur
addition_constants[0][0][0] = 65.53
addition_constants[0][0][1] = 54.10
addition_constants[0][1][0] = 72.22
addition_constants[0][1][1] = 59.76
addition_constants[0][2][0] = 72.57
addition_constants[0][2][1] = None
# Tibia
addition_constants[1][0][0] = 81.93
addition_constants[1][0][1] = 61.53
addition_constants[1][1][0] = 85.36
addition_constants[1][1][1] = 72.56
addition_constants[1][2][0] = 81.45
addition_constants[1][2][1] = None
# Fibula
addition_constants[2][0][0] = 75.50
addition_constants[2][0][1] = 59.61
addition_constants[2][1][0] = 80.07
addition_constants[2][1][1] = 70.90
addition_constants[2][2][0] = 80.56
addition_constants[2][2][1] = None
# Humerus
addition_constants[3][0][0] = 78.10
addition_constants[3][0][1] = 57.97
addition_constants[3][1][0] = 75.48
addition_constants[3][1][1] = 64.67
addition_constants[3][2][0] = 83.19
addition_constants[3][2][1] = None
# Ulna
addition_constants[4][0][0] = 75.55
addition_constants[4][0][1] = 57.76
addition_constants[4][1][0] = 82.77
addition_constants[4][1][1] = 75.38
addition_constants[4][2][0] = 77.45
addition_constants[4][2][1] = None
# Radius
addition_constants[5][0][0] = 79.42
addition_constants[5][0][1] = 54.93
addition_constants[5][1][0] = 85.43
addition_constants[5][1][1] = 71.79
addition_constants[5][2][0] = 82.00
addition_constants[5][2][1] = None
error_margins = [[[0 for col in range(2)]for row in range(3)] for x in range(6)]
# Femur
error_margins[0][0][0] = 3.94
error_margins[0][0][1] = 3.72
error_margins[0][1][0] = 3.91
error_margins[0][1][1] = 3.41
error_margins[0][2][0] = 3.80
error_margins[0][2][1] = None
# Tibia
error_margins[1][0][0] = 4.00
error_margins[1][0][1] = 3.66
error_margins[1][1][0] = 3.96
error_margins[1][1][1] = 3.70
error_margins[1][2][0] = 3.24
error_margins[1][2][1] = None
# Fibula
error_margins[2][0][0] = 3.86
error_margins[2][0][1] = 3.57
error_margins[2][1][0] = 4.02
error_margins[2][1][1] = 3.80
error_margins[2][2][0] = 3.24
error_margins[2][2][1] = None
# Humerus
error_margins[3][0][0] = 4.57
error_margins[3][0][1] = 4.45
error_margins[3][1][0] = 4.23
error_margins[3][1][1] = 4.25
error_margins[3][2][0] = 4.16
error_margins[3][2][1] = None
# Ulna
error_margins[4][0][0] = 4.72
error_margins[4][0][1] = 4.30
error_margins[4][1][0] = 4.74
error_margins[4][1][1] = 4.83
error_margins[4][2][0] = 4.66
error_margins[4][2][1] = None
# Radius
error_margins[5][0][0] = 4.66
error_margins[5][0][1] = 4.24
error_margins[5][1][0] = 4.57
error_margins[5][1][1] = 4.59
error_margins[5][2][0] = 4.60
error_margins[5][2][1] = None
bone = -1;
while bone < 1 or bone > 6:
try:
bone = int(input("1) Femur\n2) Tibia\n3) Fibula\n4) Humerus\n5) Ulna\n6) Radius\nSelect bone: "))
if bone < 1 or bone > 6:
print("[ERROR] Value must be between 1-6")
except ValueError:
print("[ERROR] Value must be between 1-6")
if bone == 1:
bone_length = int(input("Length of femur (cm): "))
elif bone == 2:
bone_length = int(input("Length of tibia (cm): "))
elif bone == 3:
bone_length = int(input("Length of fibula (cm): "))
elif bone == 4:
bone_length = int(input("Length of humerus (cm): "))
elif bone == 5:
bone_length = int(input("Length of ulna (cm): "))
elif bone == 6:
bone_length = int(input("Length of radius (cm): "))
bone = bone - 1
race = -1;
while race < 1 or race > 3:
try:
race = int(input("1) European\n2) African\n3) Asian\nSelect race: "))
if race < 1 or race > 3:
print("[ERROR] Value must be between 1-3")
except ValueError:
print("[ERROR] Value must be between 1-3")
race = race - 1
sex = -1;
while sex < 1 or sex > 2:
try:
sex = int(input("1) Male\n2) Female\nSelect sex: "))
if sex < 1 or sex > 2:
print("[ERROR] Value must be between 1-2")
except ValueError:
print("[ERROR] Value must be between 1-2")
sex = sex - 1
age = -1;
while age < 0:
try:
age = int(input("Age of the deceased: "))
if age < 0:
print("[ERROR] Value must be at least 0")
except ValueError:
print("[ERROR] Value must be at least 0")
bone_coefficient = bone_coefficients[bone][race][sex]
addition_constant = addition_constants[bone][race][sex]
error_margin = error_margins[bone][race][sex]
if bone_coefficient is None:
print("[NOTICE] Cannot perform height calculations for Asian females due to insufficient data.")
exit(0)
# Calculates the middle of the range of heights
center_height = bone_coefficient * bone_length + addition_constant - 0.06 * (age - 30)
# This corrects for floating point rounding! For example round(2.765,2) rounds to 2.67 instead of 2.68
center_height = center_height + 0.0000000001
center_height = round(center_height, 2)
# Calculate lower/upper bound heights
lower_bound_height = center_height - error_margin
upper_bound_height = center_height + error_margin
# This corrects for floating point rounding! For example round(2.765,2) rounds to 2.67 instead of 2.68
lower_bound_height = lower_bound_height + 0.0000000001
lower_bound_height = round(lower_bound_height, 2)
upper_bound_height = upper_bound_height + 0.0000000001
upper_bound_height = round(upper_bound_height, 2)
# Formula strings
center_height_formula = str(bone_coefficient) + " * " + str(bone_length) + " + " + str(addition_constant) + " - " + "0.06 * (" + str(age) + " - 30)"
range_formula = str(center_height) + " +/- " + str(error_margin)
print("\n")
print("-------------------")
print(" CALCULATED HEIGHT ")
print("-------------------")
print("Middle height: " + str(center_height) + " cm = " + center_height_formula)
print("Height range: " + str(lower_bound_height) + " cm to " + str(upper_bound_height) + " cm = " + range_formula)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment