From e2ae3bb69380d6449dc22ba9e505b4b1f5a706ab Mon Sep 17 00:00:00 2001 From: tarentomaheshvakkund <139739142+tarentomaheshvakkund@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:39:44 +0530 Subject: [PATCH] KB-5545 | DEV| Assessment | BE | Enhancement in Consumption Logic for 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. --- .../service/AssessmentServiceV5Impl.java | 8 ++-- .../service/AssessmentUtilServiceV2Impl.java | 39 +++++++++---------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/sunbird/assessment/service/AssessmentServiceV5Impl.java b/src/main/java/org/sunbird/assessment/service/AssessmentServiceV5Impl.java index 167d8eef0..52ede65e3 100644 --- a/src/main/java/org/sunbird/assessment/service/AssessmentServiceV5Impl.java +++ b/src/main/java/org/sunbird/assessment/service/AssessmentServiceV5Impl.java @@ -796,7 +796,7 @@ private Map calculateSectionFinalResults(List calculateSectionFinalResults(List calculateSectionFinalResults(List validateQumlAssessmentV2(Map question Integer correct = 0; Integer blank = 0; Integer inCorrect = 0; - Integer sectionMarks =0; + Double sectionMarks =0.0; Map questionSetSectionScheme = new HashMap<>(); String assessmentType= (String)questionSetDetailsMap.get(Constants.ASSESSMENT_TYPE); String negativeWeightAgeEnabled; @@ -513,7 +511,7 @@ public Map validateQumlAssessmentV2(Map 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); @@ -527,26 +525,26 @@ public Map validateQumlAssessmentV2(Map question return new HashMap<>(); } - private static Integer calculateScoreForOptionWeightage(Map question, String assessmentType, Map optionWeightages, List> options, Integer sectionMarks, List marked) { + private static Double calculateScoreForOptionWeightage(Map question, String assessmentType, Map optionWeightages, Double sectionMarks, List marked) { if (assessmentType.equalsIgnoreCase(Constants.OPTION_WEIGHTAGE)) { Map optionWeightageMap = (Map) optionWeightages.get(question.get(Constants.IDENTIFIER)); for (Map.Entry 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> handleqTypeQuestion(Map question, List> options, List marked, String assessmentType, Map optionWeightages, Integer sectionMarks) { + private List> handleqTypeQuestion(Map question, List> options, List marked, String assessmentType, Map optionWeightages, Double sectionMarks) { if (question.containsKey(Constants.QUESTION_TYPE)) { String questionType = ((String) question.get(Constants.QUESTION_TYPE)).toLowerCase(); Map editorStateObj = (Map) question.get(Constants.EDITOR_STATE); options = (List>) editorStateObj .get(Constants.OPTIONS); - getMarkedIndexForEachQuestion(questionType, options, marked, assessmentType, optionWeightages, sectionMarks); + getMarkedIndexForEachQuestion(questionType, options, marked, assessmentType); } return options; } @@ -560,7 +558,7 @@ private List> handleqTypeQuestion(Map 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 getOptionWeightages(List questions, Map questionMap) throws Exception { + private Map getOptionWeightages(List questions, Map questionMap) { logger.info("Retrieving option weightages for questions based on the options..."); Map ret = new HashMap<>(); for (String questionId : questions) { @@ -573,9 +571,10 @@ private Map getOptionWeightages(List questions, Map option : options) { Map valueObj = (Map) 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: @@ -596,10 +595,8 @@ private Map getOptionWeightages(List questions, Map> options, List marked, String assessmentType, Map optionWeightages, Integer sectionMarks) { + private void getMarkedIndexForEachQuestion(String questionType, List> options, List marked, String assessmentType) { logger.info("Getting marks or index for each question..."); switch (questionType) { case Constants.MTF: @@ -669,7 +666,7 @@ private void getMarkedIndexForQuestionWeightAge(List> optio * @param proficiencyMap the proficiency map containing question levels. * @return the updated section marks. */ - private Integer handleCorrectAnswer(Integer sectionMarks, Map questionSetSectionScheme, Map proficiencyMap) { + private Double handleCorrectAnswer(Double sectionMarks, Map questionSetSectionScheme, Map 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."); @@ -686,10 +683,10 @@ private Integer handleCorrectAnswer(Integer sectionMarks, Map qu * @param proficiencyMap the proficiency map containing question levels. * @return the updated section marks. */ - private Integer handleIncorrectAnswer(int negativeMarksValue,Integer sectionMarks, Map questionSetSectionScheme, Map proficiencyMap) { + private Double handleIncorrectAnswer(int negativeMarksValue,Double sectionMarks, Map questionSetSectionScheme, Map 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; @@ -724,7 +721,7 @@ private Integer handleBlankAnswers(List> userQuestionList, M * @param sectionMarks the section marks obtained. * @param totalMarks the total marks for the assessment. */ - private void updateResultMap(List> userQuestionList, Integer correct, Integer blank, Integer inCorrect, Map resultMap, Integer sectionMarks, Integer totalMarks) { + private void updateResultMap(List> userQuestionList, Integer correct, Integer blank, Integer inCorrect, Map resultMap, Double sectionMarks, Integer totalMarks) { logger.info("Updating result map..."); resultMap.put(Constants.INCORRECT, inCorrect); resultMap.put(Constants.BLANK, blank); @@ -744,9 +741,9 @@ private void updateResultMap(List> 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 resultMap) { + private void computeSectionResults(Double sectionMarks, Integer totalMarks, int minimumPassValue, Map 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); @@ -774,9 +771,9 @@ private void sortAnswers(List 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 resultMap) { + private static void calculatePassPercentage(Double sectionMarks, Integer totalMarks, Integer correct, Integer blank, Integer inCorrect,String assessmentType,Map 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;