Skip to content

Commit

Permalink
Decreased the time needed to load the data for the overview. refs #77.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRoeder committed May 17, 2016
1 parent 42f4b55 commit 4a1fc91
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<slf4j.version>1.7.6</slf4j.version>
<junit.version>4.11</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.2.10.RELEASE</spring.version>
<spring.version>3.2.17.RELEASE</spring.version>
<jena.version>2.13.0</jena.version>
<jsonld-java-jena.version>0.4.1</jsonld-java-jena.version>
</properties>
Expand Down
46 changes: 34 additions & 12 deletions src/main/java/org/aksw/gerbil/database/ExperimentDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -109,17 +110,18 @@ 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.
*/
public int connectCachedResultOrCreateTask(String annotatorName, String datasetName, String experimentType,
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
Expand Down Expand Up @@ -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);

Expand All @@ -184,17 +186,37 @@ 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
* @param matching
* the name of the matching used
* @return a list of the latest results available in the database.
*/
@Deprecated
public List<ExperimentTaskResult> 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<ExperimentTaskResult> getLatestResultsOfExperiments(String experimentType, String matching,
String annotatorNames[], String datasetNames[]);

/**
* Returns a list of all running experiment tasks.
*
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -327,6 +329,31 @@ public List<ExperimentTaskResult> getLatestResultsOfExperiments(String experimen
return results;
}

@Override
public List<ExperimentTaskResult> 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<ExperimentTaskResult> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private double[][] loadLatestResults(ExperimentType experimentType, Matching mat
}

List<ExperimentTaskResult> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() },
Expand All @@ -188,7 +191,8 @@ public void testGetLatestResultsOfExperiments() {
}
}
List<ExperimentTaskResult> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,4 +117,10 @@ public List<ExperimentTaskResult> getAllRunningExperimentTasks() {
public void close() throws IOException {
}

@Override
public List<ExperimentTaskResult> getLatestResultsOfExperiments(String experimentType, String matching,
String[] annotatorNames, String[] datasetNames) {
return null;
}

}

0 comments on commit 4a1fc91

Please sign in to comment.