From 4a1fc915356f9654d68252ec812c10e9bcc65615 Mon Sep 17 00:00:00 2001 From: mroeder Date: Tue, 17 May 2016 20:02:10 +0200 Subject: [PATCH] Decreased the time needed to load the data for the overview. refs #77. --- pom.xml | 2 +- .../aksw/gerbil/database/ExperimentDAO.java | 46 ++++++++++++++----- .../gerbil/database/ExperimentDAOImpl.java | 29 +++++++++++- .../web/ExperimentOverviewController.java | 2 +- .../database/ExperimentDAOImplJUnitTest.java | 20 ++++---- .../database/SimpleLoggingDAO4Debugging.java | 7 +++ 6 files changed, 83 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index cf3d04018..fa7d58a5b 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ 1.7.6 4.11 UTF-8 - 3.2.10.RELEASE + 3.2.17.RELEASE 2.13.0 0.4.1 diff --git a/src/main/java/org/aksw/gerbil/database/ExperimentDAO.java b/src/main/java/org/aksw/gerbil/database/ExperimentDAO.java index 65cc5aca8..238498c66 100644 --- a/src/main/java/org/aksw/gerbil/database/ExperimentDAO.java +++ b/src/main/java/org/aksw/gerbil/database/ExperimentDAO.java @@ -56,8 +56,9 @@ public interface ExperimentDAO extends Closeable { /** * Initializes the database. Searches the database for experiment tasks that - * have been started but not ended yet (their status equals {@link #TASK_STARTED_BUT_NOT_FINISHED_YET} ) and set - * their status to {@link ErrorTypes#SERVER_STOPPED_WHILE_PROCESSING}. This method should + * have been started but not ended yet (their status equals + * {@link #TASK_STARTED_BUT_NOT_FINISHED_YET} ) and set their status to + * {@link ErrorTypes#SERVER_STOPPED_WHILE_PROCESSING}. This method should * only be called directly after the initialization of the database. It * makes sure that "old" experiment tasks which have been started but never * finished are set to an error state and can't be used inside the caching @@ -90,8 +91,8 @@ public interface ExperimentDAO extends Closeable { * experiment task inside the database that does not have an error code as * state. If such a task exists and if it is not to old regarding the * durability of experiment task results, the experiment id is connected to - * the already existing task and {@link #CACHED_EXPERIMENT_TASK_CAN_BE_USED} = - * {@value #CACHED_EXPERIMENT_TASK_CAN_BE_USED} is returned. Otherwise, a + * the already existing task and {@link #CACHED_EXPERIMENT_TASK_CAN_BE_USED} + * = {@value #CACHED_EXPERIMENT_TASK_CAN_BE_USED} is returned. Otherwise, a * new experiment task is created, set to unfinished by setting its state to * {@link #TASK_STARTED_BUT_NOT_FINISHED_YET}, connected to the given * experiment and the id of the newly created experiment task is returned. @@ -109,8 +110,8 @@ public interface ExperimentDAO extends Closeable { * the name of the matching used * @param experimentId * the id of the experiment - * @return {@link #CACHED_EXPERIMENT_TASK_CAN_BE_USED}= {@value #CACHED_EXPERIMENT_TASK_CAN_BE_USED} if there is - * already + * @return {@link #CACHED_EXPERIMENT_TASK_CAN_BE_USED}= + * {@value #CACHED_EXPERIMENT_TASK_CAN_BE_USED} if there is already * an experiment task with the given preferences or the id of the * newly created experiment task. */ @@ -118,8 +119,9 @@ public int connectCachedResultOrCreateTask(String annotatorName, String datasetN String matching, String experimentId); /** - * Creates a new experiment task with the given preferences, sets its GERBIL version value using the current - * version, sets the task to unfinished by setting its state to {@link #TASK_STARTED_BUT_NOT_FINISHED_YET} and + * Creates a new experiment task with the given preferences, sets its GERBIL + * version value using the current version, sets the task to unfinished by + * setting its state to {@link #TASK_STARTED_BUT_NOT_FINISHED_YET} and * connects it to the experiment with the given experiment id. * * @param annotatorName @@ -170,8 +172,8 @@ public int createTask(String annotatorName, String datasetName, String experimen * @param experimentTaskId * the id of the experiment task for which the state should be * retrieved - * @return the state of the experiment task or {@link #TASK_NOT_FOUND}= {@value #TASK_NOT_FOUND} if such a task - * couldn't be found. + * @return the state of the experiment task or {@link #TASK_NOT_FOUND}= + * {@value #TASK_NOT_FOUND} if such a task couldn't be found. */ public int getExperimentState(int experimentTaskId); @@ -184,8 +186,9 @@ public int createTask(String annotatorName, String datasetName, String experimen public String getHighestExperimentId(); /** - * Returns the latest results for experiments with the given experiment type and matching type. Note that the - * experiment tasks of which the results are returned should be finished. + * Returns the latest results for experiments with the given experiment type + * and matching type. Note that the experiment tasks of which the results + * are returned should be finished. * * @param experimentType * the name of the experiment type @@ -193,8 +196,27 @@ public int createTask(String annotatorName, String datasetName, String experimen * the name of the matching used * @return a list of the latest results available in the database. */ + @Deprecated public List getLatestResultsOfExperiments(String experimentType, String matching); + /** + * Returns the latest results for experiments with the given experiment type + * and matching type. Note that the experiment tasks of which the results + * are returned should be finished. + * + * @param experimentType + * the name of the experiment type + * @param matching + * the name of the matching used + * @param annotatorNames + * the names of annotators for which the data should be collected + * @param datasetNames + * the names of datasets for which the data should be collected + * @return a list of the latest results available in the database. + */ + public List getLatestResultsOfExperiments(String experimentType, String matching, + String annotatorNames[], String datasetNames[]); + /** * Returns a list of all running experiment tasks. * diff --git a/src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java b/src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java index bcf0dad32..eb626e715 100644 --- a/src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java +++ b/src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java @@ -19,6 +19,8 @@ import java.io.IOException; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import javax.sql.DataSource; @@ -59,7 +61,7 @@ public class ExperimentDAOImpl extends AbstractExperimentDAO { private final static String GET_LATEST_EXPERIMENT_TASKS = "SELECT DISTINCT annotatorName, datasetName FROM ExperimentTasks WHERE experimentType=:experimentType AND matching=:matching"; @Deprecated private final static String GET_LATEST_EXPERIMENT_TASK_RESULT = "SELECT annotatorName, datasetName, experimentType, matching, microF1, microPrecision, microRecall, macroF1, macroPrecision, macroRecall, state, errorCount, lastChanged FROM ExperimentTasks WHERE annotatorName=:annotatorName AND datasetName=:datasetName AND experimentType=:experimentType AND matching=:matching AND state<>:unfinishedState ORDER BY lastChanged DESC LIMIT 1"; - private final static String GET_LATEST_EXPERIMENT_TASK_RESULTS = "SELECT tasks.annotatorName, tasks.datasetName, tasks.experimentType, tasks.matching, tasks.microF1, tasks.microPrecision, tasks.microRecall, tasks.macroF1, tasks.macroPrecision, tasks.macroRecall, tasks.state, tasks.errorCount, tasks.lastChanged, tasks.id FROM ExperimentTasks tasks, (SELECT datasetName, annotatorName, MAX(lastChanged) AS lastChanged FROM ExperimentTasks WHERE experimentType=:experimentType AND matching=:matching AND state<>:unfinishedState GROUP BY datasetName, annotatorName) pairs WHERE tasks.annotatorName=pairs.annotatorName AND tasks.datasetName=pairs.datasetName AND tasks.experimentType=:experimentType AND tasks.matching=:matching AND tasks.lastChanged=pairs.lastChanged"; + private final static String GET_LATEST_EXPERIMENT_TASK_RESULTS = "SELECT tasks.annotatorName, tasks.datasetName, tasks.experimentType, tasks.matching, tasks.microF1, tasks.microPrecision, tasks.microRecall, tasks.macroF1, tasks.macroPrecision, tasks.macroRecall, tasks.state, tasks.errorCount, tasks.lastChanged, tasks.id FROM ExperimentTasks tasks, (SELECT datasetName, annotatorName, MAX(lastChanged) AS lastChanged FROM ExperimentTasks WHERE experimentType=:experimentType AND matching=:matching AND state<>:unfinishedState AND annotatorName IN (:annotatorNames) AND datasetName IN (:datasetNames) GROUP BY datasetName, annotatorName) pairs WHERE tasks.annotatorName=pairs.annotatorName AND tasks.datasetName=pairs.datasetName AND tasks.experimentType=:experimentType AND tasks.matching=:matching AND tasks.lastChanged=pairs.lastChanged"; private final static String GET_RUNNING_EXPERIMENT_TASKS = "SELECT annotatorName, datasetName, experimentType, matching, microF1, microPrecision, microRecall, macroF1, macroPrecision, macroRecall, state, errorCount, lastChanged FROM ExperimentTasks WHERE state=:unfinishedState"; private final static String SHUTDOWN = "SHUTDOWN"; @@ -327,6 +329,31 @@ public List getLatestResultsOfExperiments(String experimen return results; } + @Override + public List getLatestResultsOfExperiments(String experimentType, String matching, + String annotatorNames[], String datasetNames[]) { + MapSqlParameterSource parameters = new MapSqlParameterSource(); + parameters.addValue("experimentType", experimentType); + parameters.addValue("matching", matching); + parameters.addValue("unfinishedState", TASK_STARTED_BUT_NOT_FINISHED_YET); + parameters.addValue("annotatorNames", Arrays.asList(annotatorNames)); + parameters.addValue("datasetNames", Arrays.asList(datasetNames)); + List results = this.template.query(GET_LATEST_EXPERIMENT_TASK_RESULTS, parameters, + new ExperimentTaskResultRowMapper()); + // FIXME remove this ugly workaround regarding the version of an + // experiment task + // We had to took this part out, because it needs to much time and the + // version isn't used inside the overview + // for (ExperimentTaskResult e : result) { + // addVersion(e); + // } + + for (ExperimentTaskResult result : results) { + addAdditionalResults(result); + } + return results; + } + protected void addAdditionalResults(ExperimentTaskResult result) { MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("taskId", result.idInDb); diff --git a/src/main/java/org/aksw/gerbil/web/ExperimentOverviewController.java b/src/main/java/org/aksw/gerbil/web/ExperimentOverviewController.java index abfa019a5..d2110b09c 100644 --- a/src/main/java/org/aksw/gerbil/web/ExperimentOverviewController.java +++ b/src/main/java/org/aksw/gerbil/web/ExperimentOverviewController.java @@ -99,7 +99,7 @@ private double[][] loadLatestResults(ExperimentType experimentType, Matching mat } List expResults = dao.getLatestResultsOfExperiments(experimentType.name(), - matching.name()); + matching.name(), annotatorNames, datasetNames); double results[][] = new double[annotatorNames.length][datasetNames.length]; for (int i = 0; i < results.length; ++i) { Arrays.fill(results[i], NOT_AVAILABLE_SENTINAL); diff --git a/src/test/java/org/aksw/gerbil/database/ExperimentDAOImplJUnitTest.java b/src/test/java/org/aksw/gerbil/database/ExperimentDAOImplJUnitTest.java index 4a4d3d44a..2b0e110f8 100644 --- a/src/test/java/org/aksw/gerbil/database/ExperimentDAOImplJUnitTest.java +++ b/src/test/java/org/aksw/gerbil/database/ExperimentDAOImplJUnitTest.java @@ -103,21 +103,23 @@ public void testExperimentCreationAndSelection() throws InterruptedException { for (int i = 0; i < 10; ++i) { if (i < 8) { results.add(new ExperimentTaskResult("annotator1", "dataset" + i, ExperimentType.D2KB, - Matching.STRONG_ANNOTATION_MATCH, new double[] { random.nextFloat(), random.nextFloat(), - random.nextFloat(), random.nextFloat(), random.nextFloat(), random.nextFloat() }, + Matching.STRONG_ANNOTATION_MATCH, + new double[] { random.nextFloat(), random.nextFloat(), random.nextFloat(), random.nextFloat(), + random.nextFloat(), random.nextFloat() }, ExperimentDAO.TASK_FINISHED, random.nextInt())); } else { results.add(new ExperimentTaskResult("annotator1", "dataset" + i, ExperimentType.D2KB, Matching.STRONG_ANNOTATION_MATCH, new double[6], - i == 8 ? ExperimentDAO.TASK_STARTED_BUT_NOT_FINISHED_YET : ErrorTypes.UNEXPECTED_EXCEPTION - .getErrorCode(), 0)); + i == 8 ? ExperimentDAO.TASK_STARTED_BUT_NOT_FINISHED_YET + : ErrorTypes.UNEXPECTED_EXCEPTION.getErrorCode(), + 0)); } } int taskId; for (ExperimentTaskResult result : results) { - taskId = this.dao.createTask(result.getAnnotator(), result.getDataset(), result.getType().name(), result - .getMatching().name(), EXPERIMENT_ID); + taskId = this.dao.createTask(result.getAnnotator(), result.getDataset(), result.getType().name(), + result.getMatching().name(), EXPERIMENT_ID); if (result.state == ExperimentDAO.TASK_FINISHED) { this.dao.setExperimentTaskResult(taskId, result); } else { @@ -173,7 +175,8 @@ public void testSetRunningExperimentsToError() { @Test public void testGetLatestResultsOfExperiments() { - // Only the first task should be retrieved, the second is not finished, the third has the wrong matching and the + // Only the first task should be retrieved, the second is not finished, + // the third has the wrong matching and the // fourth has the wrong type String tasks[][] = new String[][] { { "annotator1", "dataset1", ExperimentType.A2KB.name(), Matching.WEAK_ANNOTATION_MATCH.name() }, @@ -188,7 +191,8 @@ public void testGetLatestResultsOfExperiments() { } } List results = this.dao.getLatestResultsOfExperiments(ExperimentType.A2KB.name(), - Matching.WEAK_ANNOTATION_MATCH.name()); + Matching.WEAK_ANNOTATION_MATCH.name(), new String[] { "annotator1", "annotator2" }, + new String[] { "dataset1", "dataset2" }); Assert.assertEquals(1, results.size()); Assert.assertEquals("annotator1", results.get(0).annotator); Assert.assertEquals("dataset1", results.get(0).dataset); diff --git a/src/test/java/org/aksw/gerbil/database/SimpleLoggingDAO4Debugging.java b/src/test/java/org/aksw/gerbil/database/SimpleLoggingDAO4Debugging.java index d3f029f52..42568f313 100644 --- a/src/test/java/org/aksw/gerbil/database/SimpleLoggingDAO4Debugging.java +++ b/src/test/java/org/aksw/gerbil/database/SimpleLoggingDAO4Debugging.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.aksw.gerbil.datatypes.ExperimentTaskResult; @@ -116,4 +117,10 @@ public List getAllRunningExperimentTasks() { public void close() throws IOException { } + @Override + public List getLatestResultsOfExperiments(String experimentType, String matching, + String[] annotatorNames, String[] datasetNames) { + return null; + } + }