mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-07 21:01:03 +00:00
Minimized the resulting dimension set for a data retriever chain
This commit is contained in:
1 parent
f7cc736b41
commit
ce8f556a48
6 files changed
+62
-7
No files matched your search
+29
-2
@@ -17,6 +17,7 @@ import com.sap.sse.datamining.DataRetrieverChainDefinition;
|
||||
import com.sap.sse.datamining.Query;
|
||||
import com.sap.sse.datamining.components.FilterCriterion;
|
||||
import com.sap.sse.datamining.components.Processor;
|
||||
import com.sap.sse.datamining.factories.FunctionFactory;
|
||||
import com.sap.sse.datamining.factories.ProcessorFactory;
|
||||
import com.sap.sse.datamining.functions.Function;
|
||||
import com.sap.sse.datamining.functions.FunctionProvider;
|
||||
@@ -37,12 +38,14 @@ import com.sap.sse.datamining.shared.impl.dto.DataRetrieverChainDefinitionDTO;
|
||||
public class SailingDataMiningFactory {
|
||||
|
||||
private final ProcessorFactory processorFactory;
|
||||
private final FunctionFactory functionFactory;
|
||||
|
||||
private final FunctionProvider functionProvider;
|
||||
private final DataRetrieverChainDefinitionRegistry dataRetrieverChainDefinitionRegistry;
|
||||
|
||||
public SailingDataMiningFactory(FunctionProvider functionProvider, DataRetrieverChainDefinitionRegistry dataRetrieverChainDefinitionRegistry) {
|
||||
processorFactory = new ProcessorFactory(DataMiningActivator.getExecutor());
|
||||
functionFactory = new FunctionFactory();
|
||||
|
||||
this.functionProvider = functionProvider;
|
||||
this.dataRetrieverChainDefinitionRegistry = dataRetrieverChainDefinitionRegistry;
|
||||
@@ -150,12 +153,36 @@ public class SailingDataMiningFactory {
|
||||
private Collection<Function<?>> getDimensionsOf(
|
||||
DataRetrieverChainDefinition<RacingEventService> dataRetrieverChainDefinition) {
|
||||
Collection<Function<?>> dimensions = new HashSet<>();
|
||||
for (DataRetrieverTypeWithInformation<?, ?> dataRetrieverTypeWithInformation : dataRetrieverChainDefinition.getDataRetrieverTypesWithInformation()) {
|
||||
dimensions.addAll(functionProvider.getDimensionsFor(dataRetrieverTypeWithInformation.getRetrievedDataType()));
|
||||
List<? extends DataRetrieverTypeWithInformation<?, ?>> dataRetrieverTypesWithInformation = dataRetrieverChainDefinition.getDataRetrieverTypesWithInformation();
|
||||
for (int i = dataRetrieverTypesWithInformation.size() - 1; i >= 0; i--) {
|
||||
DataRetrieverTypeWithInformation<?, ?> dataRetrieverTypeWithInformation = dataRetrieverTypesWithInformation.get(i);
|
||||
Collection<Function<?>> dimensionsOfDataType = functionProvider.getDimensionsFor(dataRetrieverTypeWithInformation.getRetrievedDataType());
|
||||
|
||||
if (!dimensions.isEmpty()) {
|
||||
Map<Function<?>, Function<?>> dimensionsMappedByTrimmedDimensions = trimFirstMethodAndMapOriginal(dimensions);
|
||||
for (Function<?> dimensionOfDataType : dimensionsOfDataType) {
|
||||
if (dimensionsMappedByTrimmedDimensions.containsKey(dimensionOfDataType)) {
|
||||
dimensions.remove(dimensionsMappedByTrimmedDimensions.get(dimensionOfDataType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dimensions.addAll(dimensionsOfDataType);
|
||||
}
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
private Map<Function<?>, Function<?>> trimFirstMethodAndMapOriginal(Collection<Function<?>> dimensions) {
|
||||
Map<Function<?>, Function<?>> dimensionsMappedByTrimmedDimensions = new HashMap<>();
|
||||
for (Function<?> dimension : dimensions) {
|
||||
Function<?> trimmedDimension = functionFactory.trimFirstMethod(dimension);
|
||||
if (trimmedDimension != null) {
|
||||
dimensionsMappedByTrimmedDimensions.put(trimmedDimension, dimension);
|
||||
}
|
||||
}
|
||||
return dimensionsMappedByTrimmedDimensions;
|
||||
}
|
||||
|
||||
private Map<Class<?>, Collection<Function<?>>> mapFunctionsByDeclaringType(Collection<Function<?>> functions) {
|
||||
Map<Class<?>, Collection<Function<?>>> mappedFunctions = new HashMap<>();
|
||||
for (Function<?> function : functions) {
|
||||
|
||||
+5
-2
@@ -3,9 +3,11 @@ package com.sap.sse.datamining.impl;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -14,7 +16,6 @@ import com.sap.sse.datamining.DataRetrieverChainBuilder;
|
||||
import com.sap.sse.datamining.DataRetrieverChainDefinition;
|
||||
import com.sap.sse.datamining.components.FilterCriterion;
|
||||
import com.sap.sse.datamining.components.Processor;
|
||||
import com.sap.sse.datamining.impl.SimpleDataRetrieverChainDefinition;
|
||||
import com.sap.sse.datamining.impl.criterias.AbstractFilterCriterion;
|
||||
import com.sap.sse.datamining.test.functions.registry.test_classes.Test_Regatta;
|
||||
import com.sap.sse.datamining.test.functions.registry.test_contexts.Test_HasLegOfCompetitorContext;
|
||||
@@ -85,8 +86,10 @@ public class TestDataRetrieverChainCreation {
|
||||
assertThat(chainClone.getDataSourceType().equals(dataRetrieverChainDefinition.getDataSourceType()), is(true));
|
||||
assertThat(chainClone.getRetrievedDataType().equals(dataRetrieverChainDefinition.getRetrievedDataType()), is(true));
|
||||
|
||||
Collection<DataRetrieverTypeWithInformation<?, ?>> cloneDataRetrieverTypesWithInformation = (Collection<DataRetrieverTypeWithInformation<?, ?>>) chainClone.getDataRetrieverTypesWithInformation();
|
||||
List<DataRetrieverTypeWithInformation<?, ?>> cloneDataRetrieverTypesWithInformation = (List<DataRetrieverTypeWithInformation<?, ?>>) chainClone.getDataRetrieverTypesWithInformation();
|
||||
assertThat(cloneDataRetrieverTypesWithInformation, is(dataRetrieverChainDefinition.getDataRetrieverTypesWithInformation()));
|
||||
|
||||
assertThat(chainClone.getUUID(), not(dataRetrieverChainDefinition.getUUID()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.sap.sse.datamining;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -32,7 +32,7 @@ public interface DataRetrieverChainDefinition<DataSourceType> {
|
||||
Class<Processor<NextInputType, NextResultType>> nextRetrieverType,
|
||||
Class<NextResultType> retrievedDataType);
|
||||
|
||||
public Collection<? extends DataRetrieverTypeWithInformation<?, ?>> getDataRetrieverTypesWithInformation();
|
||||
public List<? extends DataRetrieverTypeWithInformation<?, ?>> getDataRetrieverTypesWithInformation();
|
||||
|
||||
public DataRetrieverChainBuilder<DataSourceType> startBuilding(ExecutorService executor);
|
||||
|
||||
|
||||
@@ -42,4 +42,25 @@ public class FunctionFactory {
|
||||
return createCompoundFunction(name, functions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Function for the given function, without the first method in the list.</br>
|
||||
* @return A new CompoundFunction without the first method in the list or <code>null</code>, if the given
|
||||
* function is no CompoundFunction or the method list has the size of 1.
|
||||
*/
|
||||
public Function<?> trimFirstMethod(Function<?> function) {
|
||||
if (function instanceof ConcatenatingCompoundFunction<?>) {
|
||||
ConcatenatingCompoundFunction<?> compoundFunction = (ConcatenatingCompoundFunction<?>) function;
|
||||
List<Function<?>> methodList = compoundFunction.getFunctions();
|
||||
if (methodList.size() > 1) {
|
||||
List<Function<?>> trimmedMethodList = new ArrayList<>();
|
||||
for (int i = 1; i < methodList.size(); i++) {
|
||||
trimmedMethodList.add(methodList.get(i));
|
||||
}
|
||||
return trimmedMethodList.size() == 1 ? trimmedMethodList.get(0) : createCompoundFunction(trimmedMethodList);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -104,7 +104,7 @@ public class SimpleDataRetrieverChainDefinition<DataSourceType> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends DataRetrieverTypeWithInformation<?, ?>> getDataRetrieverTypesWithInformation() {
|
||||
public List<? extends DataRetrieverTypeWithInformation<?, ?>> getDataRetrieverTypesWithInformation() {
|
||||
return dataRetrieverTypesWithInformation;
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -156,6 +156,10 @@ public class ConcatenatingCompoundFunction<ReturnType> extends AbstractFunction<
|
||||
public int getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
public List<Function<?>> getFunctions() {
|
||||
return functions;
|
||||
}
|
||||
|
||||
private Function<?> getFirstFunction() {
|
||||
return functions.get(0);
|
||||
|
||||
Reference in new issue
Block a user