Skip to content

Commit

Permalink
Merge pull request #11 from KB-iGOT/4.8.17-dev-v3
Browse files Browse the repository at this point in the history
4.8.17 dev v3
  • Loading branch information
SaipradeepR authored Aug 23, 2024
2 parents 33af4fc + b827753 commit d47eda2
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public SBApiResponse readQuestionList(Map<String, Object> requestBody, String au
String assessmentIdFromRequest = (String) requestBody.get(Constants.ASSESSMENT_ID_KEY);
Map<String, Object> questionsMap = assessUtilServ.readQListfromCache(identifierList,assessmentIdFromRequest,editMode,authUserToken);
for (String questionId : identifierList) {
questionList.add(assessUtilServ.filterQuestionMapDetail((Map<String, Object>) questionsMap.get(questionId),
questionList.add(assessUtilServ.filterQuestionMapDetailV2((Map<String, Object>) questionsMap.get(questionId),
result.get(Constants.PRIMARY_CATEGORY)));
}
if (errMsg.isEmpty() && identifierList.size() == questionList.size()) {
Expand Down Expand Up @@ -481,10 +481,9 @@ private void readSectionLevelParams(Map<String, Object> assessmentAllDetail,
}
}
List<Map<String, Object>> questions = (List<Map<String, Object>>) section.get(Constants.CHILDREN);
int maxQuestions = (int) section.getOrDefault(Constants.MAX_QUESTIONS, questions.size());
List<String> childNodeList = questions.stream()
List<Map<String, Object>> selectedQuestionsList = processRandomizationForQuestions((Map<String, Map<String, Object>>) section.get(Constants.SECTION_LEVEL_DEFINITION),questions);
List<String> childNodeList = selectedQuestionsList.stream()
.map(question -> (String) question.get(Constants.IDENTIFIER))
.limit(maxQuestions)
.collect(toList());
Collections.shuffle(childNodeList);
newSection.put(Constants.CHILD_NODES, childNodeList);
Expand Down Expand Up @@ -1093,4 +1092,68 @@ public SBApiResponse readAssessmentSavePoint(String assessmentIdentifier, String
}
return response;
}


/**
* Process randomization for selecting questions based on section level definitions and limits.
*
* @param sectionLevelDefinitionMap Map containing section level definitions with 'noOfQuestions' and 'noOfMaxQuestions'.
* @param questions List of questions to be processed.
* @return List of selected questions based on randomization and limits.
*/
private List<Map<String, Object>> processRandomizationForQuestions(Map<String, Map<String, Object>> sectionLevelDefinitionMap, List<Map<String, Object>> questions) {
List<Map<String, Object>> shuffledQuestionsList = shuffleQuestions(questions);
List<Map<String, Object>> selectedQuestionsList = new ArrayList<>();
Map<String, Integer> noOfQuestionsMap = new HashMap<>();
Map<String, Integer> dupNoOfQuestionsMap = new HashMap<>(); // Duplicate map for tracking selected questions
boolean result = sectionLevelDefinitionMap.values().stream()
.anyMatch(proficiencyMap -> {
Object maxNoOfQuestionsValue = proficiencyMap.get(Constants.NO_OF_QUESTIONS);
if (maxNoOfQuestionsValue instanceof Integer) {
return (Integer) maxNoOfQuestionsValue > 0;
}
return false;
});

if (!result) {
return questions;
} else {
// Populate noOfQuestionsMap and noOfMaxQuestionsMap from sectionLevelDefinitionMap
sectionLevelDefinitionMap.forEach((sectionLevelDefinitionKey, proficiencyMap) -> proficiencyMap.forEach((key, value) -> {
if (key.equalsIgnoreCase(Constants.NO_OF_QUESTIONS)) {
noOfQuestionsMap.put(sectionLevelDefinitionKey, (Integer) value);
dupNoOfQuestionsMap.put(sectionLevelDefinitionKey,0);
}
}));

// Process each question for randomization and limit checking
for (Map<String, Object> question : shuffledQuestionsList) {
String questionLevel = (String) question.get(Constants.QUESTION_LEVEL);
// Check if adding one more question of this level is within limits
if (dupNoOfQuestionsMap.getOrDefault(questionLevel, 0) < noOfQuestionsMap.getOrDefault(questionLevel, 0)) {
// Add the question to selected list
selectedQuestionsList.add(question);
// Update dupNoOfQuestionsMap to track the count of selected questions for this level
dupNoOfQuestionsMap.put(questionLevel, dupNoOfQuestionsMap.getOrDefault(questionLevel, 0) + 1);
}
}
return selectedQuestionsList;
}
}



/**
* Shuffles the list of questions maps.
*
* @param questions The list of questions maps to be shuffled.
* @return A new list containing the shuffled questions maps.
*/
public static List<Map<String, Object>> shuffleQuestions(List<Map<String, Object>> questions) {
// Create a copy of the original list to avoid modifying the input list
List<Map<String, Object>> shuffledQnsList = new ArrayList<>(questions);
// Shuffle the list using Collections.shuffle()
Collections.shuffle(shuffledQnsList);
return shuffledQnsList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public Map<String, Object> validateQumlAssessment(List<String> originalQuestionL
*/
public Map<String, Object> validateQumlAssessmentV2(Map<String, Object> questionSetDetailsMap, List<String> originalQuestionList,
List<Map<String, Object>> userQuestionList, Map<String,Object> questionMap);

Map<String, Object> filterQuestionMapDetailV2(Map<String, Object> questionMapResponse, String primaryCategory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -796,4 +796,41 @@ public static List<Map<String, Object>> shuffleOptions(List<Map<String, Object>>
Collections.shuffle(shuffledList);
return shuffledList;
}

@Override
public Map<String, Object> filterQuestionMapDetailV2(Map<String, Object> questionMapResponse,
String primaryCategory) {
List<String> questionParams = serverProperties.getAssessmentQuestionParams();
Map<String, Object> updatedQuestionMap = new HashMap<>();
for (String questionParam : questionParams) {
if (questionMapResponse.containsKey(questionParam)) {
updatedQuestionMap.put(questionParam, questionMapResponse.get(questionParam));
}
}
if (questionMapResponse.containsKey(Constants.EDITOR_STATE)
&& primaryCategory.equalsIgnoreCase(Constants.PRACTICE_QUESTION_SET)) {
Map<String, Object> editorState = (Map<String, Object>) questionMapResponse.get(Constants.EDITOR_STATE);
updatedQuestionMap.put(Constants.EDITOR_STATE, editorState);
}
if (questionMapResponse.containsKey(Constants.CHOICES)
&& updatedQuestionMap.containsKey(Constants.PRIMARY_CATEGORY)) {
Map<String, Object> choicesObj = (Map<String, Object>) questionMapResponse.get(Constants.CHOICES);
Map<String, Object> updatedChoicesMap = new HashMap<>();
if (choicesObj.containsKey(Constants.OPTIONS)) {
List<Map<String, Object>> optionsMapList = (List<Map<String, Object>>) choicesObj
.get(Constants.OPTIONS);
updatedChoicesMap.put(Constants.OPTIONS, shuffleOptions(optionsMapList));
}
updatedQuestionMap.put(Constants.CHOICES, updatedChoicesMap);
}
if (questionMapResponse.containsKey(Constants.RHS_CHOICES)
&& updatedQuestionMap.containsKey(Constants.PRIMARY_CATEGORY) && updatedQuestionMap
.get(Constants.PRIMARY_CATEGORY).toString().equalsIgnoreCase(Constants.MTF_QUESTION)) {
List<Object> rhsChoicesObj = (List<Object>) questionMapResponse.get(Constants.RHS_CHOICES);
Collections.shuffle(rhsChoicesObj);
updatedQuestionMap.put(Constants.RHS_CHOICES, rhsChoicesObj);
}

return updatedQuestionMap;
}
}
32 changes: 30 additions & 2 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,36 @@ public class Constants {
public static final String TABLE_TOP_10_LEARNER ="mdo_top_learners";
public static final String CSV_FILE = ".csv";
public static final String XLSX_FILE = ".xlsx";

private Constants() {
public static final String NO_OF_QUESTIONS = "noOfQuestions";
public static final String CADRE_DETAILS = "cadreDetails";
public static final String CADRE_CONFIG = "cadreConfig";
public static final String CIVIL_SERVICE_TYPE = "civilServiceType";
public static final String SERVICE_TYPE = "serviceList";
public static final String CADRE_BATCH = "cadreBatch";
public static final String CONTROLLING_AUTHORITY = "cadreControllingAuthorityName";
public static final String CADRE_NAME = "cadreName";
public static final String CIVIL_SERVICE_NAME = "civilServiceName";
public static final String CADRE_LIST = "cadreList";
public static final String CIVIL_SERVICE_TYPE_ID = "civilServiceTypeId";
public static final String CIVIL_SERVICE_ID = "civilServiceId";
public static final String CADRE_ID = "cadreId";
public static final String CADRE_BATCH_START_YR = "startBatchYear";
public static final String CADRE_BATCH_END_YR = "endBatchYear";
public static final String CADRE_BATCH_EXCLUSION_YR = "exculsionYearList";
public static final String NLW_USER_LEADERBOARD = "nlw_user_leaderboard";
public static final String NLW_MDO_LEADERBOARD= "nlw_mdo_leaderboard";
public static final String API_HALL_OF_FAME_ORG_READ = "api.v1.halloffame.org.read";
public static final String API_HALL_OF_FAME_MDO_LEADERBOARD = "api.v1.halloffame.mdoleaderboard";
public static final String USER_LEADERBOARD = "userLeaderBoard";
public static final String SIZE = "size";
public static final String INVALID_ORG_ID = "invalid organisation id";
public static final String MDO_LEADERBOARD = "mdoLeaderBoard";
public static final String NO_DATA_FOUND = "no data found";
public static final String NO_DATA_FOUND_FOR_THE_ORGANISATION = "no data found for the organisation";
public static final String ERROR_WHILE_PROCESSING_USER_LEADERBOARD = "error while processing userLeaderBoard";
public static final String ERROR_WHILE_PROCESSING_MDO_LEADERBOARD = "error while processing mdoLeaderBoard";

private Constants() {
throw new IllegalStateException("Utility class");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ public ResponseEntity<Map<String, Object>> fetchHallOfFameData() {
SBApiResponse response = hallOfFameService.fetchingTop10Learners(ministryOrgId, authToken);
return new ResponseEntity<>(response, response.getResponseCode());
}

@GetMapping("v1/halloffame/org/read/{orgId}")
public ResponseEntity<SBApiResponse> getUserLeaderBoard(@PathVariable String orgId) {
SBApiResponse response = hallOfFameService.getUserLeaderBoard(orgId);
return new ResponseEntity<>(response, response.getResponseCode());
}

@GetMapping("v1/halloffame/mdoleaderboard")
public ResponseEntity<SBApiResponse> getMdoLeaderBoard() {
SBApiResponse response = hallOfFameService.getMdoLeaderBoard();
return new ResponseEntity<>(response, response.getResponseCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public interface HallOfFameService {
public SBApiResponse learnerLeaderBoard(String rootOrgId, String authToken);

public SBApiResponse fetchingTop10Learners(String ministryOrgId, String authToken);

public SBApiResponse getUserLeaderBoard(String OrgId);

public SBApiResponse getMdoLeaderBoard();

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,63 @@ public SBApiResponse fetchingTop10Learners(String ministryOrgId, String authToke
return response;
}

@Override
public SBApiResponse getUserLeaderBoard(String orgId) {
SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.API_HALL_OF_FAME_ORG_READ);
if (StringUtils.isBlank(orgId)) {
setBadRequestResponse(response, Constants.INVALID_ORG_ID);
return response;
}
Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put(Constants.ORGID, orgId);
propertyMap.put(Constants.DB_COLUMN_ROW_NUM, Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
try {
List<Map<String, Object>> userLeaderBoard = cassandraOperation.getRecordsByPropertiesWithoutFiltering(
Constants.KEYSPACE_SUNBIRD, Constants.NLW_USER_LEADERBOARD, propertyMap, null);
if (CollectionUtils.isEmpty(userLeaderBoard)) {
response.getParams().setErrmsg(Constants.NO_DATA_FOUND_FOR_THE_ORGANISATION);
response.getParams().setStatus(Constants.SUCCESS);
response.setResponseCode(HttpStatus.OK);
} else {
response.getParams().setStatus(Constants.SUCCESS);
response.put(Constants.USER_LEADERBOARD, userLeaderBoard);
response.setResponseCode(HttpStatus.OK);
}
} catch (Exception e) {
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
response.getParams().setErrmsg(Constants.ERROR_WHILE_PROCESSING_USER_LEADERBOARD);
response.getParams().setStatus(Constants.FAILED);
logger.error("failed to process userLeaderBoard :: {}", String.valueOf(e));
}
return response;
}

@Override
public SBApiResponse getMdoLeaderBoard() {
SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.API_HALL_OF_FAME_MDO_LEADERBOARD);
Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put(Constants.SIZE, Arrays.asList("S", "M", "L", "XL"));
try {
List<Map<String, Object>> mdoLeaderBoard = cassandraOperation.getRecordsByPropertiesWithoutFiltering(
Constants.KEYSPACE_SUNBIRD, Constants.NLW_MDO_LEADERBOARD, propertyMap, null);
if (CollectionUtils.isEmpty(mdoLeaderBoard)) {
response.getParams().setErrmsg(Constants.NO_DATA_FOUND);
response.getParams().setStatus(Constants.SUCCESS);
response.setResponseCode(HttpStatus.OK);
} else {
response.getParams().setStatus(Constants.SUCCESS);
response.put(Constants.MDO_LEADERBOARD, mdoLeaderBoard);
response.setResponseCode(HttpStatus.OK);
}
} catch (Exception e) {
response.getParams().setErrmsg(Constants.ERROR_WHILE_PROCESSING_MDO_LEADERBOARD);
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
response.getParams().setStatus(Constants.FAILED);
logger.error("failed to process mdoLeaderBoard :: {}", String.valueOf(e));
}
return response;
}

private void setBadRequestResponse(SBApiResponse response, String errMsg) {
response.getParams().setStatus(Constants.FAILED);
response.getParams().setErrmsg(errMsg);
Expand Down
Loading

0 comments on commit d47eda2

Please sign in to comment.