Commit d760aa11 authored by manishatyagi's avatar manishatyagi
Browse files

Add api code to generate Tenure wise assessment infographic report

parent 2d8b9fa3
......@@ -186,6 +186,17 @@ public class ReportController {
return reportService.getGenderAssessInfographicReport(startDate, endDate, assessmentId,subLobId);
}
@RequestMapping(method=RequestMethod.GET,value="/api/admin/getTenureAssessmentInfographicReport")
public ResponseEntity<List<UserAssessmentInfographicReport>> getTenureAssessmentInfographicReport(
@RequestParam(value = "startDate", required = true) String startDate,
@RequestParam(value = "endDate", required = true) String endDate,
@RequestParam(value = "assessmentId", required = true) long assessmentId,
@RequestParam(value = "subLobId") long subLobId) throws Exception {
log.debug("Inside ReportController called method getTenureAssessmentInfographicReport with parameter,"
+ "startDate={},endDate={},assessmentId={},subLobId={}",startDate,endDate,assessmentId,subLobId);
return reportService.getTenureAssessmentInfographicReport(startDate, endDate, assessmentId,subLobId);
}
@RequestMapping(method=RequestMethod.GET,value="/api/admin/getCategoryAssessmentInfographicReport")
public ResponseEntity<List<DBObject>> getCategoryAssessmentInfographicReport(
@RequestParam(value = "startDate", required = true) String startDate,
......
......@@ -42,6 +42,8 @@ public interface QuestionSetRepositoryCustom {
public List<BotQuizResult> getUserQuestionList(String userId) throws Exception;
List<PendingUserCount> getUnattemptedUsers(Date startDate,Date endDate,long assessmentId,long subLobId,List<String> userId, String criteria) throws Exception;
List<PendingUserCount> getPendingUsers(Date startDate,Date endDate,long assessmentId,long subLobId,List<String> userId, Date currentDate) throws Exception;
List<DBObject> getUnattemptedQuestionSetCount(long assessmentId,List<String> userIdList) throws Exception;
}
......@@ -12,8 +12,6 @@ import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators;
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
......@@ -259,7 +257,38 @@ public class QuestionSetRepositoryImpl implements QuestionSetRepositoryCustom{
AggregationOperation sort = Aggregation.sort(Sort.Direction.ASC,"criteria");
Aggregation agg = Aggregation.newAggregation(match,project,group,lookup,unwind,project1,group1,project2,sort);
AggregationResults<PendingUserCount> result = template.aggregate(agg,COLLECTION,PendingUserCount.class);
log.debug("Response returned from QuestionSetRepositoryImpl -- getUserQuestionList , result={}",result.getMappedResults().size());
log.debug("Response returned from QuestionSetRepositoryImpl -- getUnattemptedUsers , result={}",result.getMappedResults().size());
return result.getMappedResults();
}
@Override
public List<PendingUserCount> getPendingUsers(Date startDate, Date endDate, long assessmentId, long subLobId,
List<String> userId , Date currentDate) throws Exception {
// TODO Auto-generated method stub
log.debug("Inside QuestionSetRepositoryImpl called getPendingUsers method with parameter, "
+ "startDate={},endDate={},assessmentId={},subLobId={},currentDate={}",startDate,endDate,
assessmentId,subLobId,currentDate);
AggregationOperation match = Aggregation.match(new Criteria().andOperator(
Criteria.where("isActive").is(true),
Criteria.where("isAttempted").is(false),
Criteria.where("subLob._id").is(subLobId),
Criteria.where("assessmentId").is(assessmentId),
Criteria.where("userId").nin(userId)));
AggregationOperation project = Aggregation.project("userId");
AggregationOperation group = Aggregation.group("userId").addToSet(currentDate).as("currentDate");
AggregationOperation unwind=Aggregation.unwind("currentDate");
AggregationOperation lookup = Aggregation.lookup("User_Master","_id","_id","userList");
AggregationOperation unwind1=Aggregation.unwind("userList");
AggregationOperation project1 = Aggregation.project("userId","currentDate").and("userList.joiningDateSSBJV").as("criteria");
AggregationOperation group1 = Aggregation.group("criteria","currentDate").count().as("pendingCount");
AggregationOperation project2 = Aggregation.project("pendingCount")
.andExpression("(currentDate - criteria)/(1000*60*60*24*30)").as("duration").and("_id").as("criteria");
AggregationOperation sort = Aggregation.sort(Sort.Direction.ASC,"criteria");
//Aggregation agg = Aggregation.newAggregation(match,project,group);
Aggregation agg = Aggregation.newAggregation(match,project,group,unwind,lookup,unwind1,project1,group1,project2,sort);
AggregationResults<PendingUserCount> result = template.aggregate(agg,COLLECTION,PendingUserCount.class);
log.debug("Response returned from QuestionSetRepositoryImpl -- getPendingUsers , result={}",result.getMappedResults().size());
return result.getMappedResults();
}
......@@ -279,10 +308,7 @@ public class QuestionSetRepositoryImpl implements QuestionSetRepositoryCustom{
Aggregation agg = Aggregation.newAggregation(match,project,group,group1);
AggregationResults<DBObject> result = template.aggregate(agg,COLLECTION,DBObject.class);
log.debug("Response returned from QuestionSetRepositoryImpl -- getUnattemptedQuestionSetUsers , result={}",result.getMappedResults());
if(result.getMappedResults().size()!=0)
return result.getMappedResults();
else
return null;
return result.getMappedResults();
}
}
......@@ -72,6 +72,8 @@ public interface QuizResultRepositoryCustom {
List<DBObject> getCriteriaWiseAssessInfographicReport(Date startDate, Date endDate, long assessmentId, long subLobId, String criteria) throws Exception;
List<DBObject> getTenureWiseAssessInfographicReport(Date startDate, Date endDate, long assessmentId, long subLobId, Date currentDate) throws Exception;
List<DBObject> getCategoryAssessmentInfographicReport(Date startDate, Date endDate, long assessmentId, long subLobId) throws Exception;
List<DBObject> getUserAssessmentReport(Date stDate, Date enDate, String userId)throws Exception;
......
......@@ -782,6 +782,43 @@ AggregationOperation match = Aggregation.match(new Criteria().andOperator(Crite
return result.getMappedResults();
}
@Override
public List<DBObject> getTenureWiseAssessInfographicReport(Date startDate, Date endDate, long assessmentId,
long subLobId, Date currentDate) throws Exception {
// TODO Auto-generated method stub
log.debug("Inside QuizResultRepositoryImpl called getTenureWiseAssessInfographicReport method, with parameter"
+ " startDate={},endDate={},assessmentId={},subLobId={},currentDate={}",startDate,endDate,
assessmentId,subLobId,currentDate);
AggregationOperation matchQ = Aggregation.match(new Criteria().andOperator(Criteria.where("quizDate")
.gte(startDate).lte(endDate),Criteria.where("questionSet.subLob._id").is(subLobId)
, Criteria.where("questionSet.assessmentId").is(assessmentId)));
Cond passQuiz =ConditionalOperators.when(Criteria.where("quizOutcome").is(CommonUtils.Quiz_Status.Pass.name())).then(1).otherwise(0);
Cond failQuiz =ConditionalOperators.when(Criteria.where("quizOutcome").is(CommonUtils.Quiz_Status.Fail.name())).then(1).otherwise(0);
Cond evalPendingQuiz = ConditionalOperators.when(Criteria.where("quizOutcome").is(CommonUtils.Quiz_Status.Pending.name())).then(1).otherwise(0);
AggregationOperation projectQ = Aggregation.project("_id").and("questionSet.userId").as("userId")
.and(passQuiz).as("pass").and(failQuiz).as("fail").and(evalPendingQuiz).as("evalPending");
AggregationOperation sort= Aggregation.sort(Sort.Direction.ASC,"_id");
AggregationOperation groupQ=Aggregation.group("userId").last("pass").as("pass").last("fail").as("fail")
.last("evalPending").as("evalPending").addToSet(currentDate).as("currentDate");
AggregationOperation unwind=Aggregation.unwind("currentDate");
AggregationOperation lookup = Aggregation.lookup("User_Master","_id","_id","userList");
AggregationOperation unwind1=Aggregation.unwind("userList");
AggregationOperation project = Aggregation.project("pass","fail","evalPending","currentDate")
.and("userList.joiningDateSSBJV").as("criteria").and("_id").as("userId");
AggregationOperation group=Aggregation.group("criteria","currentDate").sum("pass").as("pass").sum("fail").as("fail")
.sum("evalPending").as("evalPending").push("userId").as("userId");
AggregationOperation project2 = Aggregation.project("pass","fail","evalPending","userId","criteria")
.andExpression("(currentDate - criteria)/(1000*60*60*24*30)").as("duration");
AggregationOperation project1=Aggregation.project("criteria","pass","fail","evalPending","userId","duration")
.andExpression("add(pass,fail,evalPending)").as("total");
AggregationOperation sort1 = Aggregation.sort(Sort.Direction.ASC,"criteria");
Aggregation agg = Aggregation.newAggregation(matchQ,projectQ,sort,groupQ,unwind,lookup,unwind1,project,
group,project2,project1,sort1);
AggregationResults<DBObject> result = template.aggregate(agg,COLLECTION,DBObject.class);
log.debug("Response returned from QuizResultRepositoryImpl--getTenureWiseAssessInfographicReport method,result={}",result.getMappedResults().size());
return result.getMappedResults();
}
@Override
public List<DBObject> getCategoryAssessmentInfographicReport(Date startDate, Date endDate, long assessmentId,
long subLobId) throws Exception {
......
......@@ -10,5 +10,6 @@ import lombok.NoArgsConstructor;
public class PendingUserCount {
private long pendingCount;
private double duration;
private String criteria;
}
......@@ -247,10 +247,10 @@ public class LobServiceImpl implements LobService{
}
if(userList.isEmpty()) {
log.debug("Response returned from LobServiceImpl -- getLobByUser method, userList={}",userList);
return new ResponseEntity<List<UserMaster>>(HttpStatus.OK);
return new ResponseEntity<List<UserMaster>>(HttpStatus.NO_CONTENT);
}
log.debug("Response returned from LobServiceImpl -- getLobByUser method, userList={}",userList);
return new ResponseEntity<List<UserMaster>>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<List<UserMaster>>(HttpStatus.FOUND);
}
}
......@@ -59,6 +59,9 @@ public interface ReportService {
public ResponseEntity<List<UserAssessmentInfographicReport>> getGenderAssessInfographicReport (String startDate,
String endDate,long assessmentId, long subLobId) throws Exception;
ResponseEntity<List<UserAssessmentInfographicReport>> getTenureAssessmentInfographicReport (String startDate,
String endDate,long assessmentId, long subLobId) throws Exception;
public ResponseEntity<List<DBObject>> getCategoryAssessmentInfographicReport (String startDate,
String endDate,long assessmentId, long subLobId) throws Exception;
......
......@@ -610,6 +610,137 @@ public class ReportServiceImpl implements ReportService{
}
}
@Override
public ResponseEntity<List<UserAssessmentInfographicReport>> getTenureAssessmentInfographicReport(String startDate,
String endDate, long assessmentId, long subLobId) throws Exception {
// TODO Auto-generated method stub
log.debug("Inside ReportServiceImpl called method getTenureAssessmentInfographicReport with parameter,"
+ "startDate={},endDate={},assessmentId={},subLobId={}",startDate,endDate,assessmentId,subLobId);
DATE_FORMAT.setTimeZone(CommonUtils.TIME_ZONE);
Date stDate=DATE_FORMAT.parse(startDate);
Date enDate=DATE_FORMAT.parse(endDate);
Calendar cal = Calendar.getInstance();
cal.setTime(enDate);
cal.add(Calendar.DATE,1);
enDate=DATE_FORMAT.parse(DATE_FORMAT.format(cal.getTime()));
Date currentDate = DATE_FORMAT.parse(DATE_FORMAT.format(new Date()));
List<UserAssessmentInfographicReport> report=new ArrayList<UserAssessmentInfographicReport>();
UserAssessmentInfographicReport objReport;
List<DBObject> result = quizResultRepo.getTenureWiseAssessInfographicReport(stDate, enDate,assessmentId,subLobId,currentDate);
List<String> userIdList=new ArrayList<String>();
if(result.size()>0)
{
String[] userArray=result.stream().map(dbObject -> dbObject.get("userId")).map(Object::toString).toArray(String[]::new);
for(String user:userArray) {
user=user.substring(1,user.length()-1);
userIdList.add(user);
}
}
List<PendingUserCount> pendingResult = quesSetRepo.getPendingUsers(stDate, enDate,assessmentId,subLobId,userIdList,currentDate);
List<PendingUserCount> pendingResultTransform = pendingResult.stream().collect(Collectors.groupingBy(obj -> obj.getDuration()))
.entrySet().stream()
.map(e -> e.getValue().stream()
.reduce((f1,f2) -> new PendingUserCount(f1.getPendingCount()+f2.getPendingCount(),f1.getDuration(),f1.getCriteria())))
.map(f -> f.get())
.collect(Collectors.toList());
Map<Double, Long> pendingMap = pendingResultTransform.stream().collect(Collectors.toMap(PendingUserCount :: getDuration,PendingUserCount :: getPendingCount));
for(int i=0;i<result.size();i++)
{
DBObject obj=result.get(i);
double duration=Double.parseDouble(obj.get("duration").toString());
String tenure=getTenureRange(duration);
if(pendingMap.containsKey(duration))
{
long pendingCount=pendingMap.get(duration);
long total=Long.parseLong(obj.get("total").toString())+pendingCount;
objReport=new UserAssessmentInfographicReport(tenure,Long.parseLong(obj.get("pass").toString()),
Long.parseLong(obj.get("fail").toString()),Long.parseLong(obj.get("evalPending").toString()),pendingCount,total);
report.add(objReport);
pendingMap.remove(duration);
}
else
{
objReport=new UserAssessmentInfographicReport(tenure,Long.parseLong(obj.get("pass").toString()),
Long.parseLong(obj.get("fail").toString()),Long.parseLong(obj.get("evalPending").toString()),0,Long.parseLong(obj.get("total").toString()));
report.add(objReport);
}
}
if(pendingMap.size()>0)
{
pendingMap.forEach((key,value)-> {
String tenure=getTenureRange(key);
UserAssessmentInfographicReport tempObj=new UserAssessmentInfographicReport(tenure,0,0,0,value,value);
report.add(tempObj);
});
}
if(report.size()>0)
{
List<UserAssessmentInfographicReport> transform = report.stream().collect(Collectors.groupingBy(obj -> obj.getCriteria()))
.entrySet().stream()
.map(e -> e.getValue().stream()
.reduce((f1,f2) -> new UserAssessmentInfographicReport(f1.getCriteria(),f1.getPassCount()+f2.getPassCount(),
f1.getFailCount() + f2.getFailCount(),f1.getEvalPendingCount() + f2.getEvalPendingCount()
,f1.getPendingCount() + f2.getPendingCount(),f1.getTotal() + f2.getTotal())))
.map(f -> f.get())
.collect(Collectors.toList());
List<String> allTenure=Arrays.asList(CommonUtils.Tenure);
allTenure.forEach((str)->{
if(!transform.stream().anyMatch(o -> o.getCriteria().equals(str)))
{
UserAssessmentInfographicReport tempObj=new UserAssessmentInfographicReport(str,0, 0, 0, 0, 0);
transform.add(tempObj);
}
});
log.debug("Response returned from ReportServiceImpl --getTenureAssessmentInfographicReport method, No of record={}",report.size());
return new ResponseEntity<List<UserAssessmentInfographicReport>> (transform,HttpStatus.OK);
}
else
{
log.debug("Response returned from ReportServiceImpl --getTenureAssessmentInfographicReport method -- No record found");
return new ResponseEntity<List<UserAssessmentInfographicReport>> (HttpStatus.NO_CONTENT);
}
}
private String getTenureRange(double duration)
{
String tenure="";
if(duration>0 && duration<=6)
{
tenure=CommonUtils.Tenure[0];
}
else if(duration>6 && duration<=12)
{
tenure=CommonUtils.Tenure[1];
}
else if(duration>12 && duration<=18)
{
tenure=CommonUtils.Tenure[2];
}
else if(duration>18 && duration<=24)
{
tenure=CommonUtils.Tenure[3];
}
else if(duration>24 && duration<=30)
{
tenure=CommonUtils.Tenure[4];
}
else if(duration>30 && duration<=36)
{
tenure=CommonUtils.Tenure[5];
}
else if(duration>36 && duration<=42)
{
tenure=CommonUtils.Tenure[6];
}
else
{
tenure=CommonUtils.Tenure[7];
}
return tenure;
}
@Override
public ResponseEntity<List<DBObject>> getCategoryAssessmentInfographicReport(
String startDate, String endDate, long assessmentId, long subLobId) throws Exception {
......
package com.statestreet.utils;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;
public class CommonUtils {
......@@ -48,6 +49,8 @@ public class CommonUtils {
MALE,FEMALE,OTHER
}
public static String[] Tenure=new String[] {"0 to 6","6 to 12","12 to 18","18 to 24","24 to 30","30 to 36","36 to 42","More than 42"};
public static enum Training_Batch_Status{
Not_Started_Yet,Active_In_Progress,Completed,Active_Over_Due,Deactivate
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment