working on poll evaluation
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -56,6 +56,7 @@ public class Field {
|
||||
public static final String END_TIME = "end_time";
|
||||
public static final String ENTITY_ID = "entity_id";
|
||||
public static final String EST_TIME = "est_time";
|
||||
public static final String EVALUATION = "evaluation";
|
||||
public static final String EXPECTED = "expected";
|
||||
public static final String EXPIRATION = "expiration";
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ public class Text {
|
||||
public static final String DOCUMENT_WITH_ID = "document ({id})";
|
||||
|
||||
public static final String EMAILS_FOR_RECEIVER = "emails for {email}";
|
||||
public static final String EVALUATION = "evaluation";
|
||||
|
||||
public static final String FILES = "files";
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.text.MessageFormat.format;
|
||||
@@ -104,6 +105,22 @@ public class Poll implements Mappable {
|
||||
}
|
||||
|
||||
}
|
||||
public static class Evaluation {
|
||||
// Map<Option → Map<Weight → Count>>
|
||||
private HashMap<Integer,Map<Integer,Integer>> selections = new HashMap<>();
|
||||
|
||||
public void count(ResultSet rs) throws SQLException {
|
||||
var optionId = rs.getInt(OPTION_ID);
|
||||
var userId = rs.getObject(USER_ID);
|
||||
var weight = rs.getInt(WEIGHT);
|
||||
var optionStats = selections.computeIfAbsent(optionId, k -> new HashMap<>());
|
||||
optionStats.compute(weight, (k, sum) -> sum == null ? 1 : sum + 1);
|
||||
}
|
||||
|
||||
public HashMap<Integer, Map<Integer, Integer>> toMap() {
|
||||
return selections;
|
||||
}
|
||||
}
|
||||
private Owner owner;
|
||||
|
||||
private String id, name, description;
|
||||
@@ -212,7 +229,7 @@ public class Poll implements Mappable {
|
||||
Field.SOURCE,description,
|
||||
Field.RENDERED,Util.markdown(description)
|
||||
),
|
||||
Field.OPTIONS, options.stream().map(Option::toMap).toList(),
|
||||
Field.OPTIONS, options.stream().collect(Collectors.toMap(Option::id,Option::toMap)),
|
||||
Field.SHARES, mapShares(),
|
||||
Field.PRIVATE, isPrivate,
|
||||
Field.WEIGHTS, weights
|
||||
|
||||
Reference in New Issue
Block a user