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

Convert Sentence length and paragraph length to use HTML parser and enable AI button for both assessments #21866

Open
wants to merge 16 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Return assessmentResult
  • Loading branch information
FAMarfuaty committed Nov 27, 2024
commit a30b72d56d3162058363ebecbcbb28645a525414
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,15 @@ export default class ParagraphTooLongAssessment extends Assessment {
}

/**
* Returns the scores and text for the ParagraphTooLongAssessment.
*
* @param {ParagraphLength[]} paragraphsLength The array containing the lengths of individual paragraphs.
* Returns the score for the ParagraphTooLongAssessment.
* @param {array} paragraphsLength The array containing the lengths of individual paragraphs.
* @param {object} config The config to use.
*
* @returns {AssessmentResult} The assessmentResult.
* @returns {number} The score.
*/
calculateResult( paragraphsLength, config ) {
const assessmentResult = new AssessmentResult();

if ( paragraphsLength.length === 0 ) {
return assessmentResult;
}
getScore( paragraphsLength, config ) {
const sortedParagraphsLength = paragraphsLength.sort( ( a, b ) => b.paragraphLength - a.paragraphLength );

paragraphsLength = paragraphsLength.sort( ( a, b ) => b.paragraphLength - a.paragraphLength );
const longestParagraphLength = paragraphsLength[ 0 ].paragraphLength;
const longestParagraphLength = sortedParagraphsLength[ 0 ].paragraphLength;
let score;
if ( longestParagraphLength <= config.parameters.recommendedLength ) {
// Green indicator.
Expand All @@ -104,11 +97,30 @@ export default class ParagraphTooLongAssessment extends Assessment {
// Red indicator.
score = 3;
}
return score;
}

assessmentResult.setScore( score );
if ( score < 9 ) {
assessmentResult.setHasAIFixes( true );
/**
* Returns the scores and text for the ParagraphTooLongAssessment.
*
* @param {ParagraphLength[]} paragraphsLength The array containing the lengths of individual paragraphs.
* @param {object} config The config to use.
*
* @returns {AssessmentResult} The assessmentResult.
*/
calculateResult( paragraphsLength, config ) {
const tooLongParagraphs = this.getTooLongParagraphs( paragraphsLength, config );

const assessmentResult = new AssessmentResult();

if ( paragraphsLength.length === 0 ) {
return assessmentResult;
}

const score = this.getScore( paragraphsLength, config );

assessmentResult.setScore( score );

if ( score >= 7 ) {
assessmentResult.setHasMarks( false );
assessmentResult.setText( sprintf(
Expand Down Expand Up @@ -154,12 +166,11 @@ export default class ParagraphTooLongAssessment extends Assessment {
config.parameters.recommendedLength,
config.urlCallToAction
);
assessmentResult.setHasMarks( true );
assessmentResult.setText( config.countCharacters ? characterFeedback : wordFeedback );
assessmentResult.setHasAIFixes( true );

return {
score: score,
hasMarks: true,
text: config.countCharacters ? characterFeedback : wordFeedback,
};
return assessmentResult;
}

/**
Expand Down
Loading