Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aq_10 #13

Closed
wants to merge 1 commit into from
Closed

add aq_10 #13

wants to merge 1 commit into from

Conversation

sharlotta93
Copy link
Contributor

@sharlotta93 sharlotta93 commented Oct 14, 2024

User description

implement aq_10 as per https://docs.autismresearchcentre.com/tests/AQ10-Adolescent.pdf


PR Type

Enhancement, Tests, Documentation


Description

  • Implemented the AQ-10 calculation logic, including score calculation and interpretation.
  • Added unit tests to validate the AQ-10 calculation, covering various response scenarios and input validations.
  • Defined input and output structures for the AQ-10 calculation, specifying allowed answers and result fields.
  • Integrated AQ-10 into the existing calculations library.
  • Provided comprehensive documentation for the AQ-10 calculation, detailing its usage, method, and references.

Changes walkthrough 📝

Relevant files
Tests
aq_10_test_responses.ts
Add test data for AQ-10 calculation responses                       

src/calculation_suite/calculations/AQ_10/testdata/aq_10_test_responses.ts

  • Added test data for best, worst, and random responses.
  • Defined expected scores for different response scenarios.
  • +41/-0   
    aq_10.test.ts
    Implement unit tests for AQ-10 calculation                             

    src/calculation_suite/calculations/AQ_10/aq_10.test.ts

  • Implemented unit tests for AQ-10 calculation.
  • Tested calculation results, validation, and score computation.
  • Checked for invalid inputs and empty responses.
  • +132/-0 
    Enhancement
    aq_10.ts
    Implement AQ-10 calculation logic and integration               

    src/calculation_suite/calculations/AQ_10/aq_10.ts

  • Implemented AQ-10 calculation logic.
  • Defined score calculation and interpretation.
  • Integrated with calculation framework.
  • +64/-0   
    aq_10_inputs.ts
    Define input structure and allowed answers for AQ-10         

    src/calculation_suite/calculations/AQ_10/definition/aq_10_inputs.ts

  • Defined input structure for AQ-10 questions.
  • Specified allowed answers for each question.
  • +148/-0 
    aq_10_output.ts
    Define output structure for AQ-10 calculation                       

    src/calculation_suite/calculations/AQ_10/definition/aq_10_output.ts

  • Defined output structure for AQ-10 calculation.
  • Included score and interpretation fields.
  • +14/-0   
    index.ts
    Export AQ-10 input and output definitions                               

    src/calculation_suite/calculations/AQ_10/definition/index.ts

    • Exported AQ-10 input and output definitions.
    +2/-0     
    calculation_library.ts
    Add AQ-10 to calculations library                                               

    src/calculation_suite/calculations/calculation_library.ts

    • Added AQ-10 to the calculations library.
    +2/-0     
    Documentation
    README.md
    Add documentation for AQ-10 calculation                                   

    src/calculation_suite/calculations/AQ_10/README.md

  • Added documentation for AQ-10 calculation.
  • Included introduction, calculation method, and interpretation.
  • Provided references and usage guidelines.
  • +25/-0   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request tests Review effort [1-5]: 3 labels Oct 14, 2024
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling
    Ensure that the error handling for invalid inputs is comprehensive and covers all potential edge cases.

    Test Coverage
    Increase the test coverage to include scenarios where inputs are partially filled or have unexpected data types.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Implement a robust validation function to check input completeness and format

    Replace the manual check for input length with a more robust validation function
    that ensures all inputs are present and correctly formatted.

    src/calculation_suite/calculations/AQ_10/aq_10.ts [23-33]

    -if (valid_inputs.length !== AQ10_INPUTS.length)
    +if (!validateInputs(inputs_with_answers, AQ10_INPUTS)) {
       return [
         {
           id: 'AQ10_SCORE',
           score: MISSING_MESSAGE,
         },
         {
           id: 'AQ10_INTERPRETATION',
           score: MISSING_MESSAGE,
         },
       ]
    +}
    Suggestion importance[1-10]: 8

    Why: Replacing the manual check with a validation function improves code readability and maintainability. It also ensures that inputs are not only complete but also correctly formatted, which is crucial for accurate calculations.

    8
    Possible bug
    Add a check for the presence of all required inputs before score calculation

    Ensure that the calculation function checks for the presence of all required inputs
    before proceeding with the score calculation to avoid runtime errors due to missing
    data.

    src/calculation_suite/calculations/AQ_10/aq_10.ts [18-21]

    +if (inputs_with_answers.length !== AQ10_INPUTS.length) throw new Error('Missing input data');
     const valid_inputs = R.compose(
       R.filter(is_numeric),
       R.map(input => R.view(rawInputValueLens, input))
     )(inputs_with_answers)
    Suggestion importance[1-10]: 7

    Why: The suggestion adds a check for missing input data, which can prevent runtime errors and ensure that the calculation logic is only executed when all necessary inputs are present. This enhances the robustness of the code.

    7
    Maintainability
    Refactor to separate validation from scoring logic for better maintainability

    Refactor the calculation function to separate concerns, enhancing maintainability by
    isolating the validation logic from the scoring logic.

    src/calculation_suite/calculations/AQ_10/aq_10.ts [15-47]

    +const validateInputs = (inputs: Array<InputType>): boolean => {
    +  return inputs.every(input => is_numeric(R.view(rawInputValueLens, input)))
    +}
     const calculate_score = (
       inputs_with_answers: Array<InputType>
     ): WIPCalculationResultType => {
    -  const valid_inputs = R.compose(
    -    R.filter(is_numeric),
    -    R.map(input => R.view(rawInputValueLens, input))
    -  )(inputs_with_answers)
    +  if (!validateInputs(inputs_with_answers)) {
    +    return [
    +      {
    +        id: 'AQ10_SCORE',
    +        score: MISSING_MESSAGE,
    +      },
    +      {
    +        id: 'AQ10_INTERPRETATION',
    +        score: MISSING_MESSAGE,
    +      },
    +    ]
    +  }
    +  const valid_inputs = inputs_with_answers.map(input => R.view(rawInputValueLens, input))
       ...
     }
    Suggestion importance[1-10]: 6

    Why: Separating validation from scoring logic enhances code maintainability and readability. This refactor makes the function easier to understand and modify, although it introduces additional complexity with a new function.

    6
    Performance
    Optimize score calculation by using a direct summation method

    Optimize the calculation of the total score by directly summing the valid inputs
    without intermediate transformations, improving performance.

    src/calculation_suite/calculations/AQ_10/aq_10.ts [35]

    -const total_score = R.sum(valid_inputs)
    +const total_score = valid_inputs.reduce((acc, val) => acc + val, 0)
    Suggestion importance[1-10]: 5

    Why: The suggestion offers a minor performance improvement by using a direct summation method. While the performance gain might be negligible, it simplifies the code by removing the dependency on Ramda for this operation.

    5

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 3 tests
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant