Changeset 71 for trunk/CrossPare
- Timestamp:
- 05/04/16 10:52:04 (9 years ago)
- Location:
- trunk/CrossPare
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/eval/IResultStorage.java
r69 r71 1 // Copyright 2015 Georg-August-Universit�t G�ttingen, Germany 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 1 15 package de.ugoe.cs.cpdp.eval; 2 16 17 /** 18 * <p> 19 * Interface for result storages. 20 * </p> 21 * 22 * @author Steffen Herbold 23 */ 3 24 public interface IResultStorage { 4 25 26 /** 27 * <p> 28 * Stores a new experiment result 29 * </p> 30 * 31 * @param result 32 * result to be stored 33 */ 5 34 public void addResult(ExperimentResult result); 6 35 36 /** 37 * <p> 38 * Checks if a result is already contained in the storage. 39 * </p> 40 * 41 * @param experimentName 42 * name of the experiment 43 * @param productName 44 * name of the product 45 * @return true of the results ofr the given product and experiment are contained in the result 46 * storage 47 */ 7 48 public boolean containsResult(String experimentName, String productName); 8 49 } -
trunk/CrossPare/src/de/ugoe/cs/cpdp/eval/MySQLResultStorage.java
r69 r71 1 // Copyright 2015 Georg-August-Universit�t G�ttingen, Germany 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 1 14 2 15 package de.ugoe.cs.cpdp.eval; 3 16 17 import java.io.FileInputStream; 18 import java.io.IOException; 4 19 import java.sql.Connection; 5 20 import java.sql.DriverManager; … … 7 22 import java.sql.SQLException; 8 23 import java.sql.Statement; 24 import java.util.Properties; 9 25 26 import de.lmu.ifi.dbs.elki.logging.Logging.Level; 10 27 import de.ugoe.cs.util.console.Console; 11 28 29 /** 30 * <p> 31 * Implements a storage of experiment results in a MySQL database. 32 * </p> 33 * 34 * @author Steffen Herbold 35 */ 12 36 public class MySQLResultStorage implements IResultStorage { 37 38 /** 39 * Connection to the database 40 */ 13 41 private Connection con = null; 14 42 43 /** 44 * <p> 45 * Creates a new results storage. Tries to read a properties file mysql.cred located in the 46 * working directory. If this file is not found, the default database configuration is used: 47 * <ul> 48 * <li>dbHost = localhost</li> 49 * <li>dbPort = 3306</li> 50 * <li>dbName = crosspare</li> 51 * <li>dbUser = crosspare</li> 52 * <li>dbPass = benchmark</li> 53 * </p> 54 */ 15 55 public MySQLResultStorage() { 16 this("localhost", "3306", "crosspare", "crosspare", "benchmark"); 56 Properties dbProperties = new Properties(); 57 try { 58 dbProperties.load(new FileInputStream("mysql.cred")); 59 } 60 catch (IOException e) { 61 Console.printerr("Could not load mysql.cred file: " + e.getMessage()); 62 Console.printerr("Must be a properties file located in working directory."); 63 Console 64 .traceln(Level.WARNING, 65 "Using default DB configuration since mysql.cred file could not be loaded"); 66 } 67 String dbHost = dbProperties.getProperty("db.host", "localhost"); 68 String dbPort = dbProperties.getProperty("db.port", "3306"); 69 String dbName = dbProperties.getProperty("db.name", "crosspare"); 70 String dbUser = dbProperties.getProperty("db.user", "crosspare"); 71 String dbPass = dbProperties.getProperty("db.pass", "benchmark"); 72 connectToDB(dbHost, dbPort, dbName, dbUser, dbPass); 17 73 } 18 19 public MySQLResultStorage(String dbHost, String dbPort, String dbName, String dbUser, String dbPass) { 74 75 /** 76 * <p> 77 * Sets up the database connection 78 * </p> 79 * 80 * @param dbHost 81 * host of the database 82 * @param dbPort 83 * port of the database 84 * @param dbName 85 * name of the database 86 * @param dbUser 87 * user of the database 88 * @param dbPass 89 * password of the user 90 */ 91 private void connectToDB(String dbHost, 92 String dbPort, 93 String dbName, 94 String dbUser, 95 String dbPass) 96 { 20 97 try { 21 98 Class.forName("com.mysql.jdbc.Driver"); 22 99 con = DriverManager.getConnection("jdbc:mysql://" + dbHost + ":" + dbPort + "/" + 23 100 dbName + "?" + "user=" + dbUser + "&" + "password=" + dbPass); 24 101 } 25 102 catch (ClassNotFoundException e) { … … 34 111 } 35 112 113 /* 114 * (non-Javadoc) 115 * 116 * @see de.ugoe.cs.cpdp.eval.IResultStorage#addResult(de.ugoe.cs.cpdp.eval.ExperimentResult) 117 */ 118 @Override 36 119 public void addResult(ExperimentResult result) { 37 120 StringBuilder sql = new StringBuilder(); 38 121 sql.append("INSERT INTO crosspare.results VALUES (NULL,"); 39 sql.append("\'" + result.getConfigurationName() +"\',");40 sql.append("\'" + result.getProductName() +"\',");41 sql.append("\'" + result.getClassifier() +"\',");42 sql.append(result.getSizeTestData() +",");43 sql.append(result.getSizeTrainingData() +",");44 sql.append(result.getSuccHe() +",");45 sql.append(result.getSuccZi() +",");46 sql.append(result.getSuccG75() +",");47 sql.append(result.getSuccG60() +",");48 sql.append(result.getError() +",");49 sql.append(result.getRecall() +",");50 sql.append(result.getPrecision() +",");51 sql.append(result.getFscore() +",");52 sql.append(result.getGscore() +",");53 sql.append(result.getMcc() +",");54 sql.append(result.getAuc() +",");55 sql.append(result.getAucec() +",");56 sql.append(result.getTpr() +",");57 sql.append(result.getTnr() +",");58 sql.append(result.getFpr() +",");59 sql.append(result.getFnr() +",");60 sql.append(result.getTp() +",");61 sql.append(result.getFn() +",");62 sql.append(result.getTn() +",");63 sql.append(result.getFp() +");");64 122 sql.append("\'" + result.getConfigurationName() + "\',"); 123 sql.append("\'" + result.getProductName() + "\',"); 124 sql.append("\'" + result.getClassifier() + "\',"); 125 sql.append(result.getSizeTestData() + ","); 126 sql.append(result.getSizeTrainingData() + ","); 127 sql.append(result.getSuccHe() + ","); 128 sql.append(result.getSuccZi() + ","); 129 sql.append(result.getSuccG75() + ","); 130 sql.append(result.getSuccG60() + ","); 131 sql.append(result.getError() + ","); 132 sql.append(result.getRecall() + ","); 133 sql.append(result.getPrecision() + ","); 134 sql.append(result.getFscore() + ","); 135 sql.append(result.getGscore() + ","); 136 sql.append(result.getMcc() + ","); 137 sql.append(result.getAuc() + ","); 138 sql.append(result.getAucec() + ","); 139 sql.append(result.getTpr() + ","); 140 sql.append(result.getTnr() + ","); 141 sql.append(result.getFpr() + ","); 142 sql.append(result.getFnr() + ","); 143 sql.append(result.getTp() + ","); 144 sql.append(result.getFn() + ","); 145 sql.append(result.getTn() + ","); 146 sql.append(result.getFp() + ");"); 147 65 148 Statement stmt; 66 149 try { … … 76 159 } 77 160 } 78 161 162 /* 163 * (non-Javadoc) 164 * 165 * @see de.ugoe.cs.cpdp.eval.IResultStorage#containsResult(java.lang.String, java.lang.String) 166 */ 79 167 @Override 80 168 public boolean containsResult(String experimentName, String productName) { 81 String sql = "SELECT COUNT(*) as cnt FROM crosspare.results WHERE configurationName=\'" + experimentName + "\' AND productName=\'" + productName + "\';"; 169 String sql = "SELECT COUNT(*) as cnt FROM crosspare.results WHERE configurationName=\'" + 170 experimentName + "\' AND productName=\'" + productName + "\';"; 82 171 Statement stmt; 83 172 boolean contained = false; … … 87 176 results.next(); 88 177 int count = results.getInt("cnt"); 89 contained = count >0;178 contained = count > 0; 90 179 } 91 180 catch (SQLException e) { -
trunk/CrossPare/test/de/ugoe/cs/cpdp/eval/MySQLResultStorageTest.java
r68 r71 7 7 @Test 8 8 public void testAddResult() throws Exception { 9 String dbHost = "localhost"; 10 String dbPort = "3306"; 11 String dbName = "crosspare"; 12 String dbUser = "crosspare"; 13 String dbPass = "benchmark"; 14 15 MySQLResultStorage storage = new MySQLResultStorage(dbHost, dbPort, dbName, dbUser, dbPass); 9 MySQLResultStorage storage = new MySQLResultStorage(); 16 10 17 11 ExperimentResult result = new ExperimentResult("dummy", "product-1.0", "classifier");
Note: See TracChangeset
for help on using the changeset viewer.