use of gov.nih.nci.ctd2.dashboard.util.SubjectWithSummaries in project nci-ctd2-dashboard by CBIIT.
the class SubjectScorer method scoreAllRoles.
@Transactional
public void scoreAllRoles() {
log.info("Removing all role-based scores...");
List<SubjectWithSummaries> oldEntities = dashboardDao.findEntities(SubjectWithSummaries.class);
for (SubjectWithSummaries subjectWithSummaries : oldEntities) {
dashboardDao.delete(subjectWithSummaries);
}
log.info("Removed " + oldEntities.size() + " old scores.");
log.info("Re-scoring all roles...");
List<SubjectWithSummaries> subjectWithSummariesList = new ArrayList<SubjectWithSummaries>();
List<SubjectRole> entities = dashboardDao.findEntities(SubjectRole.class);
for (SubjectRole subjectRole : entities) {
String keyword = subjectRole.getDisplayName();
log.info("Scoring subject with role: " + keyword);
HashMap<Subject, SubjectWithSummaries> subjectToSummaries = new HashMap<Subject, SubjectWithSummaries>();
HashMap<Subject, HashSet<SubmissionCenter>> subjectToCenters = new HashMap<Subject, HashSet<SubmissionCenter>>();
HashMap<Subject, HashMap<SubmissionCenter, Integer>> centerBasedScores = new HashMap<Subject, HashMap<SubmissionCenter, Integer>>();
for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectByRole(keyword)) {
Subject subject = observedSubject.getSubject();
SubjectWithSummaries withSummaries = subjectToSummaries.get(subject);
ObservationTemplate observationTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
SubmissionCenter submissionCenter = observationTemplate.getSubmissionCenter();
Integer tier = observationTemplate.getTier();
if (withSummaries == null) {
withSummaries = new SubjectWithSummaries();
withSummaries.setRole(keyword);
withSummaries.setSubject(subject);
withSummaries.setMaxTier(tier);
withSummaries.setNumberOfObservations(1);
HashSet<SubmissionCenter> centers = new HashSet<SubmissionCenter>();
centers.add(submissionCenter);
withSummaries.setNumberOfSubmissionCenters(1);
withSummaries.addSubmission(tier, submissionCenter.getId());
subjectToCenters.put(subject, centers);
subjectToSummaries.put(subject, withSummaries);
HashMap<SubmissionCenter, Integer> cScores = new HashMap<>();
cScores.put(submissionCenter, tier);
centerBasedScores.put(subject, cScores);
} else {
withSummaries.setMaxTier(Math.max(withSummaries.getMaxTier(), tier));
withSummaries.setNumberOfObservations(withSummaries.getNumberOfObservations() + 1);
HashSet<SubmissionCenter> submissionCenters = subjectToCenters.get(subject);
submissionCenters.add(submissionCenter);
withSummaries.setNumberOfSubmissionCenters(submissionCenters.size());
withSummaries.addSubmission(tier, submissionCenter.getId());
HashMap<SubmissionCenter, Integer> cScores = centerBasedScores.get(subject);
Integer previousScore = cScores.get(submissionCenter);
cScores.put(submissionCenter, previousScore == null ? tier : Math.max(tier, previousScore));
}
}
Collection<SubjectWithSummaries> perRole = subjectToSummaries.values();
for (SubjectWithSummaries subjectWithSummaries : perRole) {
Integer totalScore = 0;
for (Integer aScore : centerBasedScores.get(subjectWithSummaries.getSubject()).values()) {
totalScore += aScore;
}
subjectWithSummaries.setScore(totalScore);
}
subjectWithSummariesList.addAll(perRole);
log.info("Done scoring role: " + keyword);
}
dashboardDao.batchSave(subjectWithSummariesList, 0);
log.info("Done scoring all roles...");
}
use of gov.nih.nci.ctd2.dashboard.util.SubjectWithSummaries in project nci-ctd2-dashboard by CBIIT.
the class ExploreController method browseByKeyword.
@Transactional
@RequestMapping(value = "{roles}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> browseByKeyword(@PathVariable String roles) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
List<SubjectWithSummaries> entities = new ArrayList<SubjectWithSummaries>();
for (String s : roles.split(",")) {
String role = s.trim().toLowerCase();
entities.addAll(getWebServiceUtil().exploreSubjects(role));
}
Collections.sort(entities, new Comparator<SubjectWithSummaries>() {
@Override
public int compare(SubjectWithSummaries o1, SubjectWithSummaries o2) {
int i = o2.getScore() - o1.getScore();
if (i == 0) {
int j = o2.getMaxTier() - o1.getMaxTier();
if (j == 0) {
return o2.getNumberOfObservations() - o1.getNumberOfObservations();
} else {
return j;
}
} else {
return i;
}
}
});
JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
return new ResponseEntity<String>(jsonSerializer.deepSerialize(entities), headers, HttpStatus.OK);
}
Aggregations