19 package org.turro.indicator;
21 import java.time.Duration;
22 import java.time.Instant;
23 import java.util.stream.Stream;
24 import org.turro.annotation.ElephantIndicator;
25 import org.turro.assistant.ParticipationInfo;
26 import org.turro.contacts.Contact;
27 import org.turro.contacts.JobBoard;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.entities.Entities;
30 import org.turro.entities.IElephantEntity;
31 import org.turro.entities.Students;
32 import org.turro.jpa.Dao;
33 import org.turro.matching.GenericMatching;
34 import org.turro.matching.IMatching;
35 import org.turro.participation.ParticipationReason;
36 import org.turro.ranking.GenericRanking;
37 import org.turro.ranking.IRanking;
38 import org.turro.students.db.StudentsPU;
39 import org.turro.students.entities.Challenge;
40 import org.turro.students.entities.PracticalWork;
41 import org.turro.students.entities.Response;
42 import org.turro.zipcode.ZipCodeAPI;
43 import org.zkoss.lang.Strings;
83 return getResponsesFor(challenge);
85 return getResponsesLikeFor(challenge);
87 return challenge.
getCreation() !=
null ? Duration.between(challenge.
getCreation().toInstant(), Instant.now()).toDays() : 9999.9;
93 return getResponsesFor(contact);
95 return getResponsesLikeFor(contact);
101 return practicalWork.
getCreation() !=
null ? Duration.between(practicalWork.
getCreation().toInstant(), Instant.now()).toDays() : 9999.9;
106 return getResponsesFor(entity);
107 case "responsesLike":
108 return getResponsesLikeFor(entity);
119 if(
"contact".equals(related.
getRoot())) {
122 if(!Strings.isBlank(practicalWork.
getZipCode())) {
125 if(jobBoard !=
null && !Strings.isBlank(jobBoard.
getZipCode())) {
138 if(
"contact".equals(entityRoot)) {
162 try(Stream<GenericRanking> stream = dao.stream(
GenericRanking.class, wc, 1000)) {
163 stream.forEach(r -> {
174 if(
"contact".equals(relatedRoot)) {
175 if(
"contact".equals(entityRoot)) {
178 }
else if(
"praticalwork".equals(entityRoot)) {
197 try(Stream<GenericMatching> stream = dao.stream(
GenericMatching.class, wc, 1000)) {
198 stream.forEach(r -> {
206 private double getResponsesFor(
Challenge challenge) {
210 private double getResponsesFor(Contact contact) {
212 if(contact.getProfile().isStudent()) {
213 count += Students.getResponseCountFrom(contact.getId());
218 private double getResponsesFor(Object entity) {
219 return Students.getResponseCountFromEntity(entity);
222 private double getResponsesLikeFor(Challenge challenge) {
223 return Students.getResponsesFrom(
getDao(), challenge).stream()
224 .map(r -> (
double)
new ParticipationInfo(r,
null, ParticipationReason.REASON_LIKE).getCount())
225 .reduce(0.0, (subtotal, count) -> subtotal + count);
228 private double getResponsesLikeFor(Contact contact) {
230 if(contact.getProfile().isStudent()) {
231 for(Response response : Students.getResponsesFrom(contact.getId())) {
232 count +=
new ParticipationInfo(response,
null, ParticipationReason.REASON_LIKE).getCount();
238 private double getResponsesLikeFor(Object entity) {
240 for(Response response : Students.getResponsesFromEntity(entity)) {
241 count +=
new ParticipationInfo(response,
null, ParticipationReason.REASON_LIKE).getCount();
static IElephantEntity getController(String path)
static long getResponseCountFrom(IContact contact)
void addVariable(String name, VariableType type)
boolean itsMine(String root)
void addExternalVariable(String root, String name)
PreprocessClause setMatchingField(String pathField)
PreprocessClause setVariable(IndicatorVariable variable)
PreprocessClause setMatchingRoot(String entityRoot)
PreprocessClause setAggregate(String aggregate)
PreprocessClause setRankingRoot(String entityRoot)
static PreprocessClause load(String table)
PreprocessClause setRankingField(String pathField)
void processRankingVariable(Dao dao, IPreprocessor preprocessor, IndicatorVariable variable, String entityRoot)
double getValue(IndicatorVariable variable, Object entity, String relatedPath)
double getValue(IndicatorVariable variable, Object entity)
void processMatchingVariable(Dao dao, IPreprocessor preprocessor, IndicatorVariable variable, String entityRoot, String relatedRoot)
void initExternalVariables()
void poolInstance(Object value)
void finishPreprocessor()