Skip to content

Extract magic numbers as constants in SCORE2 #9

@fbraza

Description

@fbraza

Issue Description

The SCORE2 implementation contains several magic numbers that could be extracted as named constants for better readability and maintainability.

Current Magic Numbers

Transformation Constants

cage = (age - 60) / 5        # 60 and 5 are magic numbers
csbp = (sbp - 120) / 20      # 120 and 20 are magic numbers
ctchol = tchol - 6           # 6 is a magic number
chdl = (hdl - 1.3) / 0.5     # 1.3 and 0.5 are magic numbers

Risk Thresholds

if age < 50:
    if calibrated_risk < 2.5:      # 2.5 is a magic number
    elif calibrated_risk < 7.5:    # 7.5 is a magic number
else:
    if calibrated_risk < 5:        # 5 is a magic number
    elif calibrated_risk < 10:     # 10 is a magic number

Suggested Implementation

# Add at module level or as class constants
# Transformation reference values
AGE_REFERENCE = 60
AGE_SCALE = 5
SBP_REFERENCE = 120
SBP_SCALE = 20
TCHOL_REFERENCE = 6
HDL_REFERENCE = 1.3
HDL_SCALE = 0.5

# Risk thresholds by age group
RISK_THRESHOLDS_UNDER_50 = {
    'low_to_moderate': 2.5,
    'high': 7.5
}

RISK_THRESHOLDS_50_PLUS = {
    'low_to_moderate': 5.0,
    'high': 10.0
}

# Age threshold
AGE_THRESHOLD = 50

# Then use in code:
cage = (age - AGE_REFERENCE) / AGE_SCALE
csbp = (sbp - SBP_REFERENCE) / SBP_SCALE
# etc...

Benefits

  • Self-documenting code
  • Easier to update values if needed
  • Reduces risk of typos
  • Makes the algorithm parameters explicit

Impact

  • Low priority enhancement
  • Improves code readability
  • No functional changes

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions