Skip to content

Commit

Permalink
New file to calculate score/evaluation into database
Browse files Browse the repository at this point in the history
  • Loading branch information
fresnault committed Aug 5, 2015
1 parent efe4848 commit d0b422c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 52 deletions.
6 changes: 5 additions & 1 deletion lib/Rscript/GenerateGraphs.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ if(nbUniqueDate > 10) {
}


#> df30 = subset(na.omit(data.frame(date, maxElo)), maxElo >2500 & maxElo<2900)
#> df30 = subset(na.omit(data.frame(date, maxElo)), maxElo >2800 & maxElo<2900)
#> p30 = ggplot(df30, aes(date, maxElo))
#> p30 + geom_point(aes(colour = maxElo))


#> library(plotly)
#> py <- plotly()
#> py$ggplotly(save30)
93 changes: 42 additions & 51 deletions src/main/java/database/AnalyseFromDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand All @@ -24,69 +25,59 @@ public AnalyseFromDatabase() throws SQLException, ClassNotFoundException {
}

private void init() throws ClassNotFoundException, SQLException {
ConfigSQL config= new ConfigSQL("diverse");
ConfigSQL config= new ConfigSQL("localhost");
Class.forName(config.getDriver());
this.connexion = DriverManager.getConnection(config.getUrl() + config.getDb() + "?user=" + config.getUser() + "&password=" + config.getPass() + "&rewriteBatchedStatements=true");
Statement stmt = connexion.createStatement();

ResultSet rs = stmt.executeQuery("SELECT id FROM Game limit 1;");
List<Move> list = new ArrayList<Move>();

while (rs.next()) {
ResultSet rs = stmt.executeQuery("SELECT id FROM Game limit 10 offset 0;");
while(rs.next()) {
int idGame = rs.getInt(1);
Log.info("Process Game #" + idGame);
list.add(analyseGame(idGame));
}

Iterator<Move> it = list.iterator();
while(it.hasNext()) {
Move tmpRows = it.next();
Log.info(tmpRows.toAnalyse());
analyseGame(idGame);
}
}

private Move analyseGame(int idGame) throws SQLException, ClassNotFoundException {
Statement stmt = connexion.createStatement();

ResultSet rs = stmt.executeQuery("SELECT Move.move, FEN2.id, FEN2.log FROM Move, Game, FEN2 WHERE Game.id = " + idGame + " AND Game.id = Move.idGame AND Move.idFEN = FEN2.id ORDER BY Move.halfMove ASC");
private void analyseGame(int idGame) throws SQLException {
PreparedStatement selectMoves = connexion.prepareStatement("SELECT Move.id, FEN.id, FEN.log FROM FEN, Move WHERE Move.idGame = '" + idGame + "' AND Move.idFEN = FEN.id ORDER BY Move.halfMove ASC");
PreparedStatement updateFEN = connexion.prepareStatement("UPDATE FEN SET score = ? WHERE id = ?");
PreparedStatement updateMove = connexion.prepareStatement("UPDATE Move SET evaluation = ? WHERE id = ?");

String crtFEN;
String crtLOG = "";
int previous = 0;
int count = 0;

Move rows = new Move();

while (rs.next()) {
crtFEN = rs.getString(2);
System.out.println(crtFEN);
crtLOG = rs.getString(3);
//String crtLOG = "info depth 1 seldepth 1 multipv 1 score cp 0 nodes 70 nps 35000 time 2 pv e4b4. info depth 2 seldepth 2 multipv 1 score cp 117 nodes 191 nps 63666 time 3 pv e4f4 b8c7 f4g5 c7d6 g5f6 d8c7 f8h6. info depth 3 seldepth 3 multipv 1 score cp 117 nodes 243 nps 81000 time 3 pv e4f4 b8c7 f4g5. info depth 4 seldepth 4 multipv 1 score cp 117 nodes 351 nps 117000 time 3 pv e4f4 b8c7 f4g5 c7d6. info depth 5 seldepth 6 multipv 1 score cp 34 nodes 1559 nps 389750 time 4 pv e4f4 d8c8 f4g5 b8d6 f8d6. info depth 6 seldepth 6 multipv 1 score cp 34 nodes 2241 nps 560250 time 4 pv e4g2 d8c8 g2g5 b8d6 f8d6 c6d6. info depth 7 seldepth 8 multipv 1 score cp 22 nodes 3906 nps 781200 time 5 pv e4g2 d8c8 g2g5 b8d6 f8d6 c6d6 g5h6. info depth 8 seldepth 9 multipv 1 score cp 22 nodes 5566 nps 927666 time 6 pv e4e5 d8c8 e5g5 b8d6 f8d6 c6d6 g5h6 d6d8 h6f8. info depth 9 seldepth 14 multipv 1 score cp 0 nodes 13377 nps 1216090 time 11 pv e4e5 d8c8 e5f5 c8b7 f5b1 b7c7 b1f5 c7b7. info depth 10 seldepth 14 multipv 1 score cp 0 nodes 18385 nps 1225666 time 15 pv e4e5 d8c8 e5f5 c8b7 f5b1 b7c7 b1f5 c7b7. info depth 11 seldepth 21 multipv 1 score cp 0 nodes 29630 nps 1346818 time 22 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 12 seldepth 21 multipv 1 score cp 0 nodes 33952 nps 1358080 time 25 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 13 seldepth 21 multipv 1 score cp 0 nodes 38669 nps 1432185 time 27 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 14 seldepth 21 multipv 1 score cp 0 nodes 51391 nps 1427527 time 36 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 15 seldepth 21 multipv 1 score cp 0 nodes 59579 nps 1241229 time 48 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 16 seldepth 21 multipv 1 score cp 0 nodes 72354 nps 1292035 time 56 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 17 seldepth 21 multipv 1 score cp 0 nodes 86874 nps 1336523 time 65 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 18 seldepth 21 multipv 1 score cp 0 nodes 107197 nps 1392168 time 77 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 19 seldepth 21 multipv 1 score cp 0 nodes 133170 nps 1431935 time 93 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. info depth 20 seldepth 21 multipv 1 score cp 0 nodes 166078 nps 1456824 time 114 pv e4e5 b8c7 e5f4 c6e8 f4g5 c7d6 g5f6 d6e7 f6b6 d8c8 b6a6 c8b8 a6b6 b8a8 b6a6 a8b8. bestmove e4e5 ponder b8c7. ";

System.out.println();

String[] lines = crtLOG.split("\\. ");
for(int i = 0 ; i < lines.length ; i++) {
if(!lines[i].startsWith("bestmove") && !lines[i].contains("mate 0")) {
StringTokenizer st = new StringTokenizer(lines[i], " ");
int k=0;
RowLog currentRaw = new RowLog();
while(st.hasMoreTokens()) {
String t = st.nextToken();
switch(k) {
case 2 : currentRaw.setDepth(t); break;
case 4 : currentRaw.setSeldepth(t); break;
case 6 : currentRaw.setMultipv(t); break;
case 8 : currentRaw.setScoreType(t); break;
case 9 : currentRaw.setScoreResult(t); break;
}
k++;
}
rows.add(currentRaw);
}
ResultSet rs = selectMoves.executeQuery();
while(rs.next()) {
int idMove = rs.getInt(1);
String idFEN = rs.getString(2);
String logFEN = rs.getString(3).split("\\.")[19];
String[] splittedFEN = logFEN.split(" ");
if(splittedFEN[9].equals("mate")) {

}else{
Integer eval = getEval(count, Integer.valueOf(splittedFEN[10]));
Integer gain = eval - previous;
previous = eval;

updateFEN.setInt(1, eval);
updateFEN.setString(2, idFEN);
updateFEN.addBatch();

updateMove.setInt(1, gain);
updateMove.setInt(2, idMove);
updateMove.addBatch();
}
count++;
}
updateMove.executeBatch();
updateFEN.executeBatch();
}

private Integer getEval(int count, int scoreResult) {
if((count%2)==0) {
return -Integer.valueOf(scoreResult);
} else {
return Integer.valueOf(scoreResult);
}

stmt.close();
return rows;
}

public static void main(String[] args) throws SQLException, ClassNotFoundException {
Expand Down

0 comments on commit d0b422c

Please sign in to comment.