Skip to content

Commit

Permalink
KB-5545 | DEV| Assessment | BE | Enhancement in Consumption Logic for…
Browse files Browse the repository at this point in the history
… the OptionWeightage Assessment Type. (#624)

* KB-5545 | DEV| Assessment | BE | Enhancement in Consumption Logic for the OptionWeightage Assessment Type.

1. Option weightage logic fixed.
2. Negative marking is now calculated based on the percentage provided during creation.

* KB-5545 | DEV| Assessment | BE | Enhancement in Consumption Logic for the OptionWeightage Assessment Type.

1. Removed blank from accuracy calculation.

* KB-5545 | DEV| Assessment | BE | Enhancement in Consumption Logic for the OptionWeightage Assessment Type.

1. Section marks is handled to be double since negative marking can have decimal values.
  • Loading branch information
tarentomaheshvakkund authored Jun 25, 2024
1 parent bb2847b commit e2ae3bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ private Map<String, Object> calculateSectionFinalResults(List<Map<String, Object
Integer blank = 0;
Integer inCorrect = 0;
Integer total = 0;
Integer totalSectionMarks = 0;
Double totalSectionMarks = 0.0;
Integer totalMarks = 0;
int pass = 0;
Double totalResult = 0.0;
Expand All @@ -813,21 +813,21 @@ private Map<String, Object> calculateSectionFinalResults(List<Map<String, Object
pass++;
}
if(sectionChildren.get(Constants.SECTION_MARKS)!=null){
totalSectionMarks += (Integer) sectionChildren.get(Constants.SECTION_MARKS);
totalSectionMarks += (Double) sectionChildren.get(Constants.SECTION_MARKS);
}
if(sectionChildren.get(Constants.TOTAL_MARKS)!=null){
totalMarks += (Integer) sectionChildren.get(Constants.TOTAL_MARKS);
}
}
res.put(Constants.OVERALL_RESULT, ((double)correct / (double)(blank+correct+inCorrect)) * 100);
res.put(Constants.OVERALL_RESULT, ((double)correct / (double)(correct+inCorrect)) * 100);
res.put(Constants.BLANK, blank);
res.put(Constants.CORRECT, correct);
res.put(Constants.INCORRECT, inCorrect);
res.put(Constants.PASS, (pass == sectionLevelResults.size()));
res.put(Constants.TIME_TAKEN_FOR_ASSESSMENT,assessmentCompletionTime-assessmentStartTime);
res.put(Constants.MAX_ASSESSMENT_RETAKE_ATTEMPTS,maxAssessmentRetakeAttempts);
res.put(Constants.RETAKE_ATTEMPT_CONSUMED,retakeAttemptsConsumed);
double totalPercentage = ((double) totalSectionMarks / (double)totalMarks) * 100;
double totalPercentage = (totalSectionMarks / (double)totalMarks) * 100;
res.put(Constants.TOTAL_PERCENTAGE, totalPercentage);
res.put(Constants.TOTAL_SECTION_MARKS, totalSectionMarks);
res.put(Constants.TOTAL_MARKS, totalMarks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.validation.constraints.NotNull;

@Service
public class AssessmentUtilServiceV2Impl implements AssessmentUtilServiceV2 {

Expand Down Expand Up @@ -469,7 +467,7 @@ public Map<String, Object> validateQumlAssessmentV2(Map<String, Object> question
Integer correct = 0;
Integer blank = 0;
Integer inCorrect = 0;
Integer sectionMarks =0;
Double sectionMarks =0.0;
Map<String,Object> questionSetSectionScheme = new HashMap<>();
String assessmentType= (String)questionSetDetailsMap.get(Constants.ASSESSMENT_TYPE);
String negativeWeightAgeEnabled;
Expand Down Expand Up @@ -513,7 +511,7 @@ public Map<String, Object> validateQumlAssessmentV2(Map<String, Object> question
sectionMarks = handleIncorrectAnswer(negativeMarksValue, sectionMarks, questionSetSectionScheme, proficiencyMap);
}
}
sectionMarks = calculateScoreForOptionWeightage(question, assessmentType, optionWeightages, options, sectionMarks, marked);
sectionMarks = calculateScoreForOptionWeightage(question, assessmentType, optionWeightages, sectionMarks, marked);
}
}
blank = handleBlankAnswers(userQuestionList, answers, blank);
Expand All @@ -527,26 +525,26 @@ public Map<String, Object> validateQumlAssessmentV2(Map<String, Object> question
return new HashMap<>();
}

private static Integer calculateScoreForOptionWeightage(Map<String, Object> question, String assessmentType, Map<String, Object> optionWeightages, List<Map<String, Object>> options, Integer sectionMarks, List<String> marked) {
private static Double calculateScoreForOptionWeightage(Map<String, Object> question, String assessmentType, Map<String, Object> optionWeightages, Double sectionMarks, List<String> marked) {
if (assessmentType.equalsIgnoreCase(Constants.OPTION_WEIGHTAGE)) {
Map<String, Object> optionWeightageMap = (Map<String, Object>) optionWeightages.get(question.get(Constants.IDENTIFIER));
for (Map.Entry<String, Object> optionWeightAgeFromOptions : optionWeightageMap.entrySet()) {
String submittedQuestionSetIndex = marked.get(0);
if (submittedQuestionSetIndex.equals(optionWeightAgeFromOptions.getKey())) {
sectionMarks = sectionMarks + Integer.parseInt((String) optionWeightAgeFromOptions.getValue());
sectionMarks = sectionMarks + (Integer) optionWeightAgeFromOptions.getValue();
}
}
}
return sectionMarks;
}

private List<Map<String, Object>> handleqTypeQuestion(Map<String, Object> question, List<Map<String, Object>> options, List<String> marked, String assessmentType, Map<String, Object> optionWeightages, Integer sectionMarks) {
private List<Map<String, Object>> handleqTypeQuestion(Map<String, Object> question, List<Map<String, Object>> options, List<String> marked, String assessmentType, Map<String, Object> optionWeightages, Double sectionMarks) {
if (question.containsKey(Constants.QUESTION_TYPE)) {
String questionType = ((String) question.get(Constants.QUESTION_TYPE)).toLowerCase();
Map<String, Object> editorStateObj = (Map<String, Object>) question.get(Constants.EDITOR_STATE);
options = (List<Map<String, Object>>) editorStateObj
.get(Constants.OPTIONS);
getMarkedIndexForEachQuestion(questionType, options, marked, assessmentType, optionWeightages, sectionMarks);
getMarkedIndexForEachQuestion(questionType, options, marked, assessmentType);
}
return options;
}
Expand All @@ -560,7 +558,7 @@ private List<Map<String, Object>> handleqTypeQuestion(Map<String, Object> questi
* @return a map containing Identifier mapped to their option and option weightages.
* @throws Exception if there is an error processing the questions.
*/
private Map<String, Object> getOptionWeightages(List<String> questions, Map<String, Object> questionMap) throws Exception {
private Map<String, Object> getOptionWeightages(List<String> questions, Map<String, Object> questionMap) {
logger.info("Retrieving option weightages for questions based on the options...");
Map<String, Object> ret = new HashMap<>();
for (String questionId : questions) {
Expand All @@ -573,9 +571,10 @@ private Map<String, Object> getOptionWeightages(List<String> questions, Map<Stri
switch (questionType) {
case Constants.MCQ_SCA:
case Constants.MCQ_MCA:
case Constants.MCQ_MCA_W:
for (Map<String, Object> option : options) {
Map<String, Object> valueObj = (Map<String, Object>) option.get(Constants.VALUE);
optionWeightage.put(valueObj.get(Constants.VALUE).toString(), valueObj.get(Constants.OPTION_WEIGHT).toString());
optionWeightage.put(valueObj.get(Constants.VALUE).toString(), option.get(Constants.ANSWER));
}
break;
default:
Expand All @@ -596,10 +595,8 @@ private Map<String, Object> getOptionWeightages(List<String> questions, Map<Stri
* @param options the list of options.
* @param marked the list to store marked indices.
* @param assessmentType the type of assessment.
* @param optionWeightages the map of option weightages.
* @param sectionMarks the current section marks.
*/
private void getMarkedIndexForEachQuestion(String questionType, List<Map<String, Object>> options, List<String> marked, String assessmentType, Map<String, Object> optionWeightages, Integer sectionMarks) {
private void getMarkedIndexForEachQuestion(String questionType, List<Map<String, Object>> options, List<String> marked, String assessmentType) {
logger.info("Getting marks or index for each question...");
switch (questionType) {
case Constants.MTF:
Expand Down Expand Up @@ -669,7 +666,7 @@ private void getMarkedIndexForQuestionWeightAge(List<Map<String, Object>> optio
* @param proficiencyMap the proficiency map containing question levels.
* @return the updated section marks.
*/
private Integer handleCorrectAnswer(Integer sectionMarks, Map<String, Object> questionSetSectionScheme, Map<String, Object> proficiencyMap) {
private Double handleCorrectAnswer(Double sectionMarks, Map<String, Object> questionSetSectionScheme, Map<String, Object> proficiencyMap) {
logger.info("Handling correct answer scenario...");
sectionMarks = sectionMarks + (Integer) questionSetSectionScheme.get((String) proficiencyMap.get(Constants.QUESTION_LEVEL));
logger.info("Correct answer scenario handled successfully.");
Expand All @@ -686,10 +683,10 @@ private Integer handleCorrectAnswer(Integer sectionMarks, Map<String, Object> qu
* @param proficiencyMap the proficiency map containing question levels.
* @return the updated section marks.
*/
private Integer handleIncorrectAnswer(int negativeMarksValue,Integer sectionMarks, Map<String, Object> questionSetSectionScheme, Map<String, Object> proficiencyMap) {
private Double handleIncorrectAnswer(int negativeMarksValue,Double sectionMarks, Map<String, Object> questionSetSectionScheme, Map<String, Object> proficiencyMap) {
logger.info("Handling incorrect answer scenario...");
if (negativeMarksValue > 0) {
sectionMarks = sectionMarks - (Integer) questionSetSectionScheme.get((String)proficiencyMap.get(Constants.QUESTION_LEVEL));
sectionMarks = sectionMarks - (((double)negativeMarksValue /100 ) * (double) questionSetSectionScheme.get((String)proficiencyMap.get(Constants.QUESTION_LEVEL)));
}
logger.info("Incorrect answer scenario handled successfully.");
return sectionMarks;
Expand Down Expand Up @@ -724,7 +721,7 @@ private Integer handleBlankAnswers(List<Map<String, Object>> userQuestionList, M
* @param sectionMarks the section marks obtained.
* @param totalMarks the total marks for the assessment.
*/
private void updateResultMap(List<Map<String, Object>> userQuestionList, Integer correct, Integer blank, Integer inCorrect, Map<String, Object> resultMap, Integer sectionMarks, Integer totalMarks) {
private void updateResultMap(List<Map<String, Object>> userQuestionList, Integer correct, Integer blank, Integer inCorrect, Map<String, Object> resultMap, Double sectionMarks, Integer totalMarks) {
logger.info("Updating result map...");
resultMap.put(Constants.INCORRECT, inCorrect);
resultMap.put(Constants.BLANK, blank);
Expand All @@ -744,9 +741,9 @@ private void updateResultMap(List<Map<String, Object>> userQuestionList, Integer
* @param minimumPassValue the minimum percentage required to pass the section.
* @param resultMap the map to store the section result.
*/
private void computeSectionResults(Integer sectionMarks, Integer totalMarks, int minimumPassValue, Map<String, Object> resultMap) {
private void computeSectionResults(Double sectionMarks, Integer totalMarks, int minimumPassValue, Map<String, Object> resultMap) {
logger.info("Computing section results...");
if (sectionMarks > 0 && ((sectionMarks / totalMarks) * 100 >= minimumPassValue)) {
if (sectionMarks > 0 && totalMarks>0 && ((sectionMarks / totalMarks) * 100 >= minimumPassValue)) {
resultMap.put(Constants.SECTION_RESULT, Constants.PASS);
} else {
resultMap.put(Constants.SECTION_RESULT, Constants.FAIL);
Expand Down Expand Up @@ -774,9 +771,9 @@ private void sortAnswers(List<String> answer) {
* @param assessmentType Type of assessment (either "QUESTION_WEIGHTAGE" or "OPTION_WEIGHTAGE")
* @param resultMap Map to store the result of the calculation
*/
private static void calculatePassPercentage(Integer sectionMarks, Integer totalMarks, Integer correct, Integer blank, Integer inCorrect,String assessmentType,Map<String, Object> resultMap) {
private static void calculatePassPercentage(Double sectionMarks, Integer totalMarks, Integer correct, Integer blank, Integer inCorrect,String assessmentType,Map<String, Object> resultMap) {
if (assessmentType.equalsIgnoreCase(Constants.QUESTION_WEIGHTAGE)) {
resultMap.put(Constants.RESULT, (double)sectionMarks / (double)totalMarks * 100);
resultMap.put(Constants.RESULT, sectionMarks / (double)totalMarks * 100);
} else if (assessmentType.equalsIgnoreCase(Constants.OPTION_WEIGHTAGE)) {
int total;
total = correct + blank + inCorrect;
Expand Down

0 comments on commit e2ae3bb

Please sign in to comment.