Updated the sailing service and the entry point

This commit is contained in:
Lennart Hensler committed 2013-08-06 17:13:16 +02:00
1 parent c7965b1aa6
commit cb49ecdbd8
13 files changed
+164 -43

No files matched your search

@@ -30,8 +30,8 @@ import com.sap.sailing.domain.common.LegType;
public class DataMiningFactory {
public static Query createQuery(Map<Dimension, Collection<?>> selection) {
return new QueryImpl(createSelector(selection), null, null, null);
public static Query createQuery(Map<Dimension, Collection<?>> selection, Dimension groupByDimension, StatisticType statisticToCalculate, AggregatorType aggregatedAs) {
return new QueryImpl(createSelector(selection), createGrouper(groupByDimension), createExtractor(statisticToCalculate), createAggregator(aggregatedAs));
}
protected static Grouper createGrouper(Dimension dimension) {
@@ -9,8 +9,10 @@ import java.util.Set;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.sap.sailing.datamining.shared.AggregatorType;
import com.sap.sailing.datamining.shared.Dimension;
import com.sap.sailing.datamining.shared.QueryResult;
import com.sap.sailing.datamining.shared.StatisticType;
import com.sap.sailing.domain.common.DetailType;
import com.sap.sailing.domain.common.MasterDataImportObjectCreationCount;
import com.sap.sailing.domain.common.MaxPointsReason;
@@ -331,7 +333,7 @@ public interface SailingService extends RemoteService {
MasterDataImportObjectCreationCount importMasterData(String host, String[] groupNames, boolean override);
Pair<Double, Integer> runQueryAsBenchmark(Map<Dimension, Collection<?>> selection);
Pair<Double, Integer> runQueryAsBenchmark(Map<Dimension, Collection<?>> selection, Dimension groupByDimension, StatisticType statisticToCalculate, AggregatorType aggregatedAs);
QueryResult runQuery(Map<Dimension, Collection<?>> selection);
QueryResult runQuery(Map<Dimension, Collection<?>> selection, Dimension groupByDimension, StatisticType statisticToCalculate, AggregatorType aggregatedAs);
}
@@ -8,8 +8,10 @@ import java.util.Map;
import java.util.Set;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sap.sailing.datamining.shared.AggregatorType;
import com.sap.sailing.datamining.shared.Dimension;
import com.sap.sailing.datamining.shared.QueryResult;
import com.sap.sailing.datamining.shared.StatisticType;
import com.sap.sailing.domain.common.DetailType;
import com.sap.sailing.domain.common.MasterDataImportObjectCreationCount;
import com.sap.sailing.domain.common.MaxPointsReason;
@@ -456,9 +458,9 @@ public interface SailingServiceAsync {
/**
* Creates and runs a data mining query with the specified properties.
*/
void runQueryAsBenchmark(Map<Dimension, Collection<?>> selection, AsyncCallback<Pair<Double, Integer>> asyncCallback);
void runQueryAsBenchmark(Map<Dimension, Collection<?>> selection, Dimension groupByDimension, StatisticType statisticToCalculate, AggregatorType aggregatedAs, AsyncCallback<Pair<Double, Integer>> asyncCallback);
void runQuery(Map<Dimension, Collection<?>> selection, AsyncCallback<QueryResult> asyncCallback);
void runQuery(Map<Dimension, Collection<?>> selection, Dimension groupByDimension, StatisticType statisticToCalculate, AggregatorType aggregatedAs, AsyncCallback<QueryResult> asyncCallback);
}
@@ -764,4 +764,6 @@ public interface StringMessages extends Messages {
String overallTime();
String cleanedOverallTime();
String dataMiningResult();
String groupBy();
String statisticToCalculate();
}
@@ -757,4 +757,6 @@ serverTime=Server Time
cleanedServerTime=Cleaned Server Time
overallTime=Overall Time
cleanedOverallTime=Cleaned Overall Time
dataMiningResult=Data Mining Result
dataMiningResult=Data Mining Result
groupBy=Group by
statisticToCalculate=Calculate statistic
@@ -753,4 +753,6 @@ serverTime=Server-Zeit
cleanedServerTime=Bereinigte Server-Zeit
overallTime=Gesamt-Zeit
cleanedOverallTime=Bereinigte Gesamt-Zeit
dataMiningResult=Data Mining Ergebnis
dataMiningResult=Data Mining Ergebnis
groupBy=Gruppieren nach
statisticToCalculate=Berechne Kennzahl
@@ -21,19 +21,19 @@ public class QueryBenchmarkPanel extends FlowPanel {
private SailingServiceAsync sailingService;
private ErrorReporter errorReporter;
private StringMessages stringMessages;
private QuerySelectionProvider selectionProvider;
private QueryComponentsProvider queryComponentsProvider;
private IntegerBox numberOfQueriesBox;
private Label benchmarkStatusLabel;
private QueryBenchmarkResultsChart resultsChart;
public QueryBenchmarkPanel(StringMessages stringMessages, SailingServiceAsync sailingService,
ErrorReporter errorReporter, QuerySelectionProvider selectionProvider) {
ErrorReporter errorReporter, QueryComponentsProvider queryComponentsProvider) {
super();
this.sailingService = sailingService;
this.errorReporter = errorReporter;
this.stringMessages = stringMessages;
this.selectionProvider = selectionProvider;
this.queryComponentsProvider = queryComponentsProvider;
add(createFunctionsPanel());
resultsChart = new QueryBenchmarkResultsChart(this.stringMessages);
@@ -51,14 +51,16 @@ public class QueryBenchmarkPanel extends FlowPanel {
@Override
public void onSuccess(List<RegattaDTO> regattas) {
final int times = numberOfQueriesBox.getValue() == null ? 1 : numberOfQueriesBox.getValue();
runQuery(new ClientBenchmarkData(selectionProvider.getSelection(), times, 1));
runQuery(new ClientBenchmarkData(queryComponentsProvider.getSelection(), times, 1));
}
});
}
private void runQuery(final ClientBenchmarkData benchmarkData) {
final long startTime = System.currentTimeMillis();
sailingService.runQueryAsBenchmark(benchmarkData.getSelection(), new AsyncCallback<Pair<Double, Integer>>() {
sailingService.runQueryAsBenchmark(benchmarkData.getSelection(), queryComponentsProvider.getDimensionToGroupBy(),
queryComponentsProvider.getStatisticToCalculate(), queryComponentsProvider.getAggregationType(),
new AsyncCallback<Pair<Double, Integer>>() {
@Override
public void onFailure(Throwable caught) {
errorReporter.reportError("Error running a query: " + caught.getMessage());
@@ -0,0 +1,20 @@
package com.sap.sailing.gwt.ui.datamining;
import java.util.Collection;
import java.util.Map;
import com.sap.sailing.datamining.shared.AggregatorType;
import com.sap.sailing.datamining.shared.Dimension;
import com.sap.sailing.datamining.shared.StatisticType;
public interface QueryComponentsProvider {
public Map<Dimension, Collection<?>> getSelection();
public Dimension getDimensionToGroupBy();
public StatisticType getStatisticToCalculate();
public AggregatorType getAggregationType();
}
@@ -16,17 +16,17 @@ public class QueryPanel extends FlowPanel {
private StringMessages stringMessages;
private SailingServiceAsync sailingService;
private ErrorReporter errorReporter;
private QuerySelectionProvider selectionProvider;
private QueryComponentsProvider queryComponentsProvider;
private QueryResultsChart resultChart;
public QueryPanel(StringMessages stringMessages, SailingServiceAsync sailingService,
ErrorReporter errorReporter, QuerySelectionProvider selectionProvider) {
ErrorReporter errorReporter, QueryComponentsProvider queryComponentsProvider) {
super();
this.stringMessages = stringMessages;
this.sailingService = sailingService;
this.errorReporter = errorReporter;
this.selectionProvider = selectionProvider;
this.queryComponentsProvider = queryComponentsProvider;
add(createFunctionsPanel());
resultChart = new QueryResultsChart(this.stringMessages);
@@ -34,7 +34,9 @@ public class QueryPanel extends FlowPanel {
}
private void runQuery() {
sailingService.runQuery(selectionProvider.getSelection(), new AsyncCallback<QueryResult>() {
sailingService.runQuery(queryComponentsProvider.getSelection(), queryComponentsProvider.getDimensionToGroupBy(),
queryComponentsProvider.getStatisticToCalculate(), queryComponentsProvider.getAggregationType(),
new AsyncCallback<QueryResult>() {
@Override
public void onFailure(Throwable caught) {
errorReporter.reportError("Error running the query: " + caught.getMessage());
@@ -1,12 +0,0 @@
package com.sap.sailing.gwt.ui.datamining;
import java.util.Collection;
import java.util.Map;
import com.sap.sailing.datamining.shared.Dimension;
public interface QuerySelectionProvider {
public Map<Dimension, Collection<?>> getSelection();
}
@@ -1,5 +1,6 @@
package com.sap.sailing.gwt.ui.datamining;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -10,11 +11,16 @@ import java.util.Set;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.text.shared.Renderer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ValueListBox;
import com.sap.sailing.datamining.shared.AggregatorType;
import com.sap.sailing.datamining.shared.Dimension;
import com.sap.sailing.datamining.shared.StatisticType;
import com.sap.sailing.domain.common.LegType;
import com.sap.sailing.domain.common.dto.BoatClassDTO;
import com.sap.sailing.domain.common.dto.CompetitorDTO;
@@ -25,11 +31,14 @@ import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sailing.gwt.ui.shared.RaceWithCompetitorsDTO;
import com.sap.sailing.gwt.ui.shared.RegattaDTO;
public class SelectionPanel extends FlowPanel implements QuerySelectionProvider {
public class SelectionPanel extends FlowPanel implements QueryComponentsProvider {
private StringMessages stringMessages;
private SailingServiceAsync sailingService;
private ErrorReporter errorReporter;
private ValueListBox<Dimension> groupByListBox;
private ValueListBox<StatisticAndAggregatorType> statisticsListBox;
private Map<Dimension, SelectionTable<?, ?>> tablesMappedByDimension;
private SelectionTable<RegattaDTO, String> regattaNameTable;
@@ -48,16 +57,10 @@ public class SelectionPanel extends FlowPanel implements QuerySelectionProvider
this.sailingService = sailingService;
this.errorReporter = errorReporter;
Button clearSelectionButton = new Button(this.stringMessages.clearSelection());
clearSelectionButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
clearSelection();
}
});
add(clearSelectionButton);
add(createSelectionTables());
add(createFunctionsPanel());
fillSelectionTables();
}
@@ -79,6 +82,21 @@ public class SelectionPanel extends FlowPanel implements QuerySelectionProvider
}
}
@Override
public Dimension getDimensionToGroupBy() {
return groupByListBox.getValue();
}
@Override
public StatisticType getStatisticToCalculate() {
return statisticsListBox.getValue().getStatisticType();
}
@Override
public AggregatorType getAggregationType() {
return statisticsListBox.getValue().getAggregatorType();
}
private void fillSelectionTables() {
sailingService.getRegattas(new AsyncCallback<List<RegattaDTO>>() {
@Override
@@ -120,6 +138,56 @@ public class SelectionPanel extends FlowPanel implements QuerySelectionProvider
});
}
private HorizontalPanel createFunctionsPanel() {
HorizontalPanel functionsPanel = new HorizontalPanel();
functionsPanel.setSpacing(5);
Button clearSelectionButton = new Button(this.stringMessages.clearSelection());
clearSelectionButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
clearSelection();
}
});
functionsPanel.add(clearSelectionButton);
functionsPanel.add(new Label(stringMessages.groupBy() + ": "));
groupByListBox = new ValueListBox<Dimension>(new Renderer<Dimension>() {
@Override
public String render(Dimension dimension) {
if (dimension == null) {
return "";
}
return dimension.toString();
}
@Override
public void render(Dimension dimension, Appendable appendable) throws IOException {
appendable.append(render(dimension));
}
});
groupByListBox.setAcceptableValues(Arrays.asList(Dimension.values()));
functionsPanel.add(groupByListBox);
functionsPanel.add(new Label(stringMessages.statisticToCalculate() + ": "));
statisticsListBox = new ValueListBox<StatisticAndAggregatorType>(new Renderer<StatisticAndAggregatorType>() {
@Override
public String render(StatisticAndAggregatorType statisticAndAggregatorType) {
if (statisticAndAggregatorType == null) {
return "";
}
return statisticAndAggregatorType.toString();
}
@Override
public void render(StatisticAndAggregatorType statisticAndAggregatorType, Appendable appendable) throws IOException {
appendable.append(render(statisticAndAggregatorType));
}
});
statisticsListBox.setAcceptableValues(Arrays.asList(new StatisticAndAggregatorType(StatisticType.FixAmount, AggregatorType.Average)));
functionsPanel.add(statisticsListBox);
return functionsPanel;
}
private HorizontalPanel createSelectionTables() {
HorizontalPanel tablesPanel = new HorizontalPanel();
tablesPanel.setSpacing(5);
@@ -0,0 +1,29 @@
package com.sap.sailing.gwt.ui.datamining;
import com.sap.sailing.datamining.shared.AggregatorType;
import com.sap.sailing.datamining.shared.StatisticType;
public class StatisticAndAggregatorType {
private StatisticType statisticType;
private AggregatorType aggregatorType;
public StatisticAndAggregatorType(StatisticType statisticType, AggregatorType aggregatorType) {
this.statisticType = statisticType;
this.aggregatorType = aggregatorType;
}
public StatisticType getStatisticType() {
return statisticType;
}
public AggregatorType getAggregatorType() {
return aggregatorType;
}
@Override
public String toString() {
return getStatisticType().toString() + " (" + getAggregatorType().toString() + ")";
}
}
@@ -51,8 +51,10 @@ import org.osgi.util.tracker.ServiceTracker;
import com.google.gwt.regexp.shared.RegExp;
import com.sap.sailing.datamining.DataMiningFactory;
import com.sap.sailing.datamining.Query;
import com.sap.sailing.datamining.shared.AggregatorType;
import com.sap.sailing.datamining.shared.Dimension;
import com.sap.sailing.datamining.shared.QueryResult;
import com.sap.sailing.datamining.shared.StatisticType;
import com.sap.sailing.domain.base.BoatClass;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.ControlPoint;
@@ -3316,17 +3318,17 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
@Override
public Pair<Double, Integer> runQueryAsBenchmark(Map<Dimension, Collection<?>> selection) {
public Pair<Double, Integer> runQueryAsBenchmark(Map<Dimension, Collection<?>> selection, Dimension groupByDimension, StatisticType statisticToCalculate, AggregatorType aggregatedAs) {
final long startTime = System.nanoTime();
Integer gpsFixAmount = runQuery(selection).getGPSFixAmount();
Integer gpsFixAmount = runQuery(selection, groupByDimension, statisticToCalculate, aggregatedAs).getGPSFixAmount();
long endTime = System.nanoTime();
double serverTime = (endTime - startTime) / 1000000000.0;
return new Pair<Double, Integer>(serverTime, gpsFixAmount);
}
@Override
public QueryResult runQuery(Map<Dimension, Collection<?>> selection) {
Query query = DataMiningFactory.createQuery(selection);
public QueryResult runQuery(Map<Dimension, Collection<?>> selection, Dimension groupByDimension, StatisticType statisticToCalculate, AggregatorType aggregatedAs) {
Query query = DataMiningFactory.createQuery(selection, groupByDimension, statisticToCalculate, aggregatedAs);
return query.run(getService());
}