19 package org.turro.matching;
21 import java.util.List;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import java.util.stream.Stream;
25 import org.turro.action.IProcess;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.indicator.Formulas;
29 import org.turro.indicator.IElephantIndicator;
30 import org.turro.indicator.IPreprocessor;
31 import org.turro.indicator.IndicatorVariable;
32 import org.turro.indicator.Indicators;
33 import org.turro.indicator.VariableType;
34 import org.turro.jpa.Dao;
35 import org.turro.math.Zero;
76 wc.
addClause(
"where entityPath = :entityPath");
82 public void process(Stream<T> stream, List<IndicatorVariable> variables) {
88 public void processFor(T entity, List<IndicatorVariable> variables) {
91 related.forEach(r -> {
92 variables.forEach(v -> {
93 if(!v.isPreprocess()) {
94 process(entity, r, v);
123 matching =
getDao().saveObject(matching);
129 variables.forEach(v -> {
130 if(v.isPreprocess()) {
131 IElephantIndicator ei = Indicators.getIndicator(v);
132 ei.preprocess(v, this, entitiesRoot(), relatedRoot());
138 variables.forEach(v -> {
171 private List<IndicatorVariable> variables;
173 private void calculateMatching() {
177 try(Stream<IMatching> tuples = getIndicatorTuples()) {
178 tuples.forEach(t -> {
188 private Stream<IMatching> getIndicatorTuples() {
189 WhereClause wc =
new WhereClause();
190 wc.addClause(
"select m from " +
instanceClass().getSimpleName() +
" m");
194 wc.addClause(
"order by entityPath, relatedPath, concept");
195 return createDao().stream(IMatching.class, wc, 1000);
198 private void doCalculate(IMatching matching) {
199 if(matching ==
null || (previous !=
null && !sameTuple(previous, matching))) {
200 set.addMissing(variables);
202 IndicatorVariable.result(
indicatorsRoot(), VariableType.MATCHING_VARIABLE));
204 if(!Zero.near(result.getMatching(), 2)) {
207 set =
new MatchingSet();
209 if(matching !=
null) {
215 private boolean sameTuple(IMatching matching1, IMatching matching2) {
216 if(matching1 ==
null || matching2 ==
null) {
219 return matching1.
getEntityPath().equals(matching2.getEntityPath()) &&
220 matching1.getRelatedPath().equals(matching2.getRelatedPath());
static String logMsg(String msg)
void addClause(String clause)
void addIn(String operator, String field, List values)
void addNamedValue(String name, Object value)
static boolean hasDirectProcess(List< IndicatorVariable > variables)
static double getValue(Object entity, IndicatorVariable variable)
static List< IndicatorVariable > getMatchingVariables(String root)
static IElephantIndicator getIndicator(String root)
abstract String getPath(Object object)
int executeUpdate(String query)
void poolObject(Object obj, int poolSize)
int executeNativeUpdate(SqlClause sc, Object... pars)
abstract String indicatorsRoot()
double calculate(MatchingSet set)
void postProcess(List< IndicatorVariable > variables)
void processFor(T entity, List< IndicatorVariable > variables)
abstract IMatching createMatchingInstance()
void prepareEntity(T entity)
void finishPreprocessor()
abstract Stream< T > getEntityStream()
IMatching createMatchingInstance(String entityPath, String relatedPath, IndicatorVariable variable)
void poolInstance(Object value)
void process(Stream< T > stream, List< IndicatorVariable > variables)
void prepareProcess(List< IndicatorVariable > variables)
abstract String relatedRoot()
abstract Class instanceClass()
void startProcessFor(Object entity)
List< String > getSelectedPaths()
IMatching process(T entity, String relatedPath, IndicatorVariable variable)
abstract String entitiesRoot()
static boolean near(double value, int digits)
void postprocess(IndicatorVariable variable, IPreprocessor preprocessor, String entityRoot, String relatedRoot)
Stream< String > getEntityPaths(String entityRoot)
void setRelatedPath(String relatedPath)
void setConcept(String concept)
void setMatching(double value)
void setEntityPath(String entityPath)