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

Assessments: Overview table - calculate not answered value #22156

Merged
merged 21 commits into from May 14, 2018

Conversation

nkiruka
Copy link
Contributor

@nkiruka nkiruka commented May 2, 2018

This PR is to calculate the percent of students that did not answer a question and to display the value in the "not Answered column".

-In PR 22118, a dash is displayed in empty columns.

  • In this PR, the default value for empty columns is 0%
    -The Not Answered column shows a teacher the percent of students that did not answer a question.

Implementation

  • Add a function to calculate the "not Answered" value
  • Add "notAnswered" prop to the multiple choice cell component

screen shot 2018-05-02 at 9 45 28 am

Next Steps:

  • Refactor code
  • Style table

@nkiruka
Copy link
Contributor Author

nkiruka commented May 2, 2018

@balderdash Please review

/>
);
};
const alphabetMapper = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this was named something like "multipleChoiceAnswerOptions"? Might be more descriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Thanks

{percentAnswered: 20, isCorrectAnswer: false},
{percentAnswered: 20, isCorrectAnswer: false},
{percentAnswered: 20, isCorrectAnswer: false},
],
Copy link
Contributor

@Erin007 Erin007 May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I'm confused, but I'm a little concerned that we're relying on order to match percentAnswered to specific answer options (eg. "A"). What if we had something like {multipleChoiceOption: "A", percentAnswered: 40, isCorrectAnswer: true}? Then all of the relevant data gets bundled together.

Copy link
Contributor

@Erin007 Erin007 May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want the translatable string, I think you could do:
{multipleChoiceOption: {i18n.answerOptionA()}, percentAnswered: 40, isCorrectAnswer: true}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Erin007 This is a valid point! After our in-person discussion, there is a tremendous payoff being able to identify which percentAnswered is associated with the answer choice. Additionally, debugging is easier. Thanks!

@caleybrock caleybrock changed the base branch from staging to assessments-answer-columns May 2, 2018 19:45
@caleybrock
Copy link
Contributor

I changed the base on this PR to your original branch so that we only see the new changes :)

@caleybrock
Copy link
Contributor

We chatted about component organization offline and @nkiruka will update.

if (property === 'notAnswered') {
percentValue = calculateNotAnswered(rowData.answers);
} else {
percentValue = (cell && cell.percentAnswered) || '-';
Copy link
Contributor

@Erin007 Erin007 May 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set percentValue to "-" rather than to a number here, MultipleChoiceAnswerCell will be confused because it's expecting that propType to be a number.

You have a few choices:

1.) Instead of "-" you could set percentValue to 0, then have MultipleChoiceAnswerCell just render "0%"
2.) Instead of "-" you could set percentValue to 0. Then, you could introduce some logic in MultipleChoiceAnswerCell if percentValue === 0 render "-"
3.) Adjust the propTypes in MultipleChoiceAnswerCell to use oneOfType, explained here

Which option are you leaning toward? Other idea? If you want to chat through the pros/cons of each, let me know.

}
});

return (100 - total);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked "Do we have any multiple choice questions where students can select multiple answers, like a "select all that apply..." ?" in Slack because, if that's the case, you could run into a situation where calculateNotAnswered returns a negative number. For example, let's say there are only two answer choices: "A" and "B" and students are allowed to select: only "A", only "B", none, or "A" AND "B". If 100% of the students selected "A" AND "B", total in this function is 200, and you'd return -100. Let's confirm the requirements with Poorva.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Since this is an overview table of all the students' assessments, I do not think this will be an issue. For the individual student tables, this will be applicable (a good test :-) to check). Thoughts!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If students can select multiple answer options, I'm still concerned about calculateNotAnswered for this overview table. For example we could have a scenario like:
img_0564
In this case we would want the % not answered to be 25% because 1 out of 4 students did not answer the question; however the function as written would return 0%.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a great unit test case!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur!! Tests will be covered in the next PR.

@nkiruka
Copy link
Contributor Author

nkiruka commented May 4, 2018

@caleybrock @Erin007 Please see updated code for review

@nkiruka nkiruka requested a review from maddiedierker May 4, 2018 16:19
@nkiruka nkiruka changed the base branch from assessments-answer-columns to staging May 4, 2018 16:50
<span>{`${percentValue}%`}</span>
}
{(percentValue < 0 ) &&
<span>{'-'}</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you said Poorva likes it without -?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poorva also likes it with the dash and she is open to either option. I ran a mini survey with Maddie and Erin and the 'dash' option is preferred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

const NOT_ANSWERED = 'notAnswered';

const calculateNotAnswered = (multipleChoiceDataArr) => {
let total = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation in this function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, Thanks


let percentValue = 0;

if (property === 'notAnswered') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use your constant here instead of this string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, Thanks

const maxAnswerChoicesLength = this.props.questionAnswerData.reduce((answersTotal, currentAnswerCount) => {
return Math.max(answersTotal, currentAnswerCount.answers.length);
}, 0);

let dataColumns = [];
Copy link
Contributor

@caleybrock caleybrock May 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I totally understand the reason for the re-factoring in this function but I do have some suggestions to make it easier to read.
Your new code creates an empty dataColumns, pushes one element to it, and then deconstructs it to add it to an array. Would it be simpler to just add this.getQuestionColumn(sortable) to your array like this?

return [
  this.getQuestionColumn(sortable),
  ...columnLabelNames,
  this.getNotAnsweredColumn()},
];

I think it could make your final constructed array easier to read.
Note: you could make this.getNotAnsweredColumn() return an object that already has the property NOT_ANSWERED so you don't have to reconstruct it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it does make it easier to read. Fixed.

@nkiruka
Copy link
Contributor Author

nkiruka commented May 8, 2018

Please review. Next PR will contain the refactored code with the new data structures. Thanks.

@nkiruka
Copy link
Contributor Author

nkiruka commented May 8, 2018

@caleybrock Please see updated changes. Thanks

let dataColumns = [];

dataColumns.push(this.getQuestionColumn(sortable));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataColumns is not longer used - so you can delete it.

@nkiruka
Copy link
Contributor Author

nkiruka commented May 8, 2018

@caleybrock Please review. Thanks

Copy link
Contributor

@caleybrock caleybrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good given we address Erin's concerns in a follow up PR

@nkiruka nkiruka merged commit ed81c60 into staging May 14, 2018
@nkiruka nkiruka deleted the calculate-notAnswered branch September 17, 2018 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants