Previous notes from aryan

progress:

Untitled

Untitled

Untitled

Untitled

This will be helpful for evaluating grade levels if we’re measuring text with Lexile:

## Lexile to Grade Level Conversion

def lex_to_grade(lexile):

	# Might change this later, if we're including the "BR"/"beginner reader" subzero levels
  if lexile < 0:
    raise ValueError("Lexile level must be non-negative")
  
  # Define Lexile level thresholds for each grade
  lexile_thresholds = [
    (0, 164, 0),        # Kindergarten
    (165, 424, 1),      # 1st grade
    (425, 644, 2),      # 2nd grade
    (645, 849, 3),      # 3rd grade
    (850, 949, 4),      # 4th grade
    (950, 1029, 5),     # 5th grade
    (1030, 1094, 6),    # 6th grade
    (1095, 1154, 7),    # 7th grade
    (1155, 1204, 8),    # 8th grade
    (1205, 1249, 9),    # 9th grade
    (1250, 1294, 10),   # 10th grade
    (1295, 1349, 11),   # 11th grade
    (1350, 1400, 12)    # 12th grade
  ]
  
  # Check lexile against the thresholds and calculate the grade level
  for lower_bound, upper_bound, grade in lexile_thresholds:
    if lower_bound <= lexile <= upper_bound:
      # Calculate the fractional part within the grade level range
      decimal_grade = grade + (lexile - lower_bound) / (upper_bound - lower_bound + 1)
      return decimal_grade
  
  # If Lexile level is above 1600, return 13
  if lexile > 1400:
    return 13
  
  # If Lexile level is below the minimum threshold, return 0
  return 0

print(lex_to_grade(100))  # Expected output: ~0.5
print(lex_to_grade(450))  # Expected output: ~2.25
print(lex_to_grade(1250)) # Expected output: ~9.25
print(lex_to_grade(1700)) # Expected output: 13