Skip to content

Commit

Permalink
4.8.16 merge conflicts (#648)
Browse files Browse the repository at this point in the history
* KB-3998 | DEV | Assessment | BE | Analysis and code changes for the randomization of the options/choices. (#645)

1. Created a custom method to shuffle the options.

* Commiting for top 10 learners api (#644)

* Commiting for top 10 learners api

* Commiting for top 10 learners api

---------

Co-authored-by: pathiktarento1089 <123535830+pathiktarento1089@users.noreply.github.com>
  • Loading branch information
tarentomaheshvakkund and pathiktarento1089 authored Jul 19, 2024
1 parent bde07d8 commit 25e740d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public Map<String, Object> filterQuestionMapDetail(Map<String, Object> questionM
if (choicesObj.containsKey(Constants.OPTIONS)) {
List<Map<String, Object>> optionsMapList = (List<Map<String, Object>>) choicesObj
.get(Constants.OPTIONS);
updatedChoicesMap.put(Constants.OPTIONS, optionsMapList);
updatedChoicesMap.put(Constants.OPTIONS, shuffleOptions(optionsMapList));
}
updatedQuestionMap.put(Constants.CHOICES, updatedChoicesMap);
}
Expand Down Expand Up @@ -782,4 +782,18 @@ private static void calculatePassPercentage(Double sectionMarks, Integer totalMa
resultMap.put(Constants.TOTAL, total);
}
}

/**
* Shuffles the list of option maps.
*
* @param optionsMapList The list of option maps to be shuffled.
* @return A new list containing the shuffled option maps.
*/
public static List<Map<String, Object>> shuffleOptions(List<Map<String, Object>> optionsMapList) {
// Create a copy of the original list to avoid modifying the input list
List<Map<String, Object>> shuffledList = new ArrayList<>(optionsMapList);
// Shuffle the list using Collections.shuffle()
Collections.shuffle(shuffledList);
return shuffledList;
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,8 @@ public class Constants {
public static final String SEARCH_COMPETENCY_SUB_THEMES = "competencySubTheme";
public static final String MCQ_MCA_W = "mcq-mca-w";
public static final String MCQ_SCA_TF = "mcq-sca-tf";
public static final String TOP_10_LEARNERS ="top10Learners";
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";

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

@GetMapping("/v1/top/learners")
public ResponseEntity<SBApiResponse> fetchingTopLearners
(@RequestHeader(Constants.X_AUTH_TOKEN) String authToken,
@RequestHeader(Constants.X_AUTH_USER_ORG_ID) String rootOrgId) throws Exception {
SBApiResponse response = hallOfFameService.fetchingTop10Learners(rootOrgId, authToken);
return new ResponseEntity<>(response, response.getResponseCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* @author mahesh.vakkund
*/
public interface HallOfFameService {
public Map<String, Object> fetchHallOfFameData() ;
public SBApiResponse learnerLeaderBoard(String rootOrgId, String authToken) ;
public Map<String, Object> fetchHallOfFameData();

public SBApiResponse learnerLeaderBoard(String rootOrgId, String authToken);

public SBApiResponse fetchingTop10Learners(String rootOrgId, String authToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.sunbird.cassandra.utils.CassandraOperation;
import org.sunbird.common.model.SBApiResponse;
import org.sunbird.common.util.AccessTokenValidator;
Expand All @@ -15,7 +16,6 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
* @author mahesh.vakkund
Expand All @@ -28,6 +28,7 @@ public class HallOfFameServiceImpl implements HallOfFameService {
private Logger logger = LoggerFactory.getLogger(getClass().getName());
@Autowired
AccessTokenValidator accessTokenValidator;

@Override
public Map<String, Object> fetchHallOfFameData() {
Map<String, Object> resultMap = new HashMap<>();
Expand Down Expand Up @@ -112,6 +113,53 @@ public SBApiResponse learnerLeaderBoard(String rootOrgId, String authToken) {
return response;
}

@Override
public SBApiResponse fetchingTop10Learners(String rootOrgId, String authToken) {
SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.TOP_10_LEARNERS);
try {
if (StringUtils.isEmpty(rootOrgId)) {
setBadRequestResponse(response, Constants.ORG_ID_MISSING);
return response;
}
String userId = validateAuthTokenAndFetchUserId(authToken);
if (StringUtils.isBlank(userId)) {
setBadRequestResponse(response, Constants.USER_ID_DOESNT_EXIST);
return response;
}
Map<String, Object> propertiesMap = new HashMap<>();
propertiesMap.put(Constants.USER_ID_LOWER, userId);

List<Map<String, Object>> userRowNum = cassandraOperation.getRecordsByPropertiesWithoutFiltering(
Constants.SUNBIRD_KEY_SPACE_NAME,
Constants.TABLE_LEARNER_LEADER_BOARD_LOOK_UP,
propertiesMap,
null
);
if (CollectionUtils.isEmpty(userRowNum)) {
setNotFoundResponse(response, Constants.USER_ID_DOESNT_EXIST);
return response;
}
Map<String, Object> propMap = new HashMap<>();
int res = (Integer) userRowNum.get(0).get(Constants.DB_COLUMN_ROW_NUM);
List<Integer> ranksFilter = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
propMap.put(Constants.DB_COLUMN_ROW_NUM, ranksFilter);
propMap.put(Constants.ORGID, rootOrgId);

List<Map<String, Object>> result = cassandraOperation.getRecordsByPropertiesWithoutFiltering(
Constants.SUNBIRD_KEY_SPACE_NAME,
Constants.TABLE_TOP_10_LEARNER,
propMap,
null
);
response.put(Constants.RESULT, result);
return response;

} catch (Exception e) {
setInternalServerErrorResponse(response);
}
return response;
}

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

0 comments on commit 25e740d

Please sign in to comment.