Skip to content
Snippets Groups Projects
Commit 3828ae14 authored by Anton Danilov's avatar Anton Danilov
Browse files

#43 function for selecting games based on user and game difficulty

parent 708175a3
Branches
Tags
No related merge requests found
...@@ -3,8 +3,10 @@ import com.badlogic.gdx.tools.texturepacker.TexturePacker ...@@ -3,8 +3,10 @@ import com.badlogic.gdx.tools.texturepacker.TexturePacker
buildscript { buildscript {
repositories { repositories {
mavenCentral() //mavenCentral()
jcenter() jcenter{
url "http://jcenter.bintray.com/"
}
} }
dependencies { dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6' classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
......
...@@ -13,6 +13,7 @@ import cz.nic.tablexia.model.User; ...@@ -13,6 +13,7 @@ import cz.nic.tablexia.model.User;
import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuScreen; import cz.nic.tablexia.screen.gamemenu.GameMenuScreen;
import cz.nic.tablexia.screen.loader.LoaderScreen; import cz.nic.tablexia.screen.loader.LoaderScreen;
import cz.nic.tablexia.screen.statistics.StatisticsScreen;
import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.Log;
public class TablexiaSettings { public class TablexiaSettings {
......
...@@ -5,9 +5,11 @@ import com.badlogic.gdx.utils.TimeUtils; ...@@ -5,9 +5,11 @@ import com.badlogic.gdx.utils.TimeUtils;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.TablexiaStorage; import cz.nic.tablexia.TablexiaStorage;
import cz.nic.tablexia.game.AbstractTablexiaGame; import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.GameDefinition; import cz.nic.tablexia.game.GameDefinition;
...@@ -70,7 +72,7 @@ public class Game { ...@@ -70,7 +72,7 @@ public class Game {
public Long getAllPausesDuration() { public Long getAllPausesDuration() {
List<GamePause> gamePauses = GamePause.selectGamePausesForGame(this); List<GamePause> gamePauses = GamePause.selectGamePausesForGame(this);
long pausesDuration = 0; long pausesDuration = 0;
for (GamePause gamePause: gamePauses) { for (GamePause gamePause : gamePauses) {
if (gamePause.hasStartTime() && gamePause.hasEndTime()) { if (gamePause.hasStartTime() && gamePause.hasEndTime()) {
pausesDuration = pausesDuration + (gamePause.getEndTime() - gamePause.getStartTime()); pausesDuration = pausesDuration + (gamePause.getEndTime() - gamePause.getStartTime());
} }
...@@ -112,6 +114,10 @@ public class Game { ...@@ -112,6 +114,10 @@ public class Game {
return selectGameForId(id); return selectGameForId(id);
} }
public static List<Game> getGamesForResults(Long userId, int difficultyNumber) {
return selectGamesForUserAndDifficulty(userId, difficultyNumber);
}
public void startGame() { public void startGame() {
startTime = gameUpdateStart(getId(), TimeUtils.millis()); startTime = gameUpdateStart(getId(), TimeUtils.millis());
} }
...@@ -187,6 +193,7 @@ public class Game { ...@@ -187,6 +193,7 @@ public class Game {
public static final String GAME_SELECT_FOR_ID = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE id = ?"; public static final String GAME_SELECT_FOR_ID = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE id = ?";
public static final String GAME_SELECT_LAST_ID = "SELECT max(id) FROM game"; public static final String GAME_SELECT_LAST_ID = "SELECT max(id) FROM game";
public static final String GAME_SELECT_COUNT_FOR_GAME_AND_DIFFICULTY = "SELECT count(id) FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL"; public static final String GAME_SELECT_COUNT_FOR_GAME_AND_DIFFICULTY = "SELECT count(id) FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_USER_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE user_id = ? AND difficulty_number = ?";
private static Long insertNewGame(User user, GameDifficulty difficulty, GameDefinition gameDefinition, TablexiaRandom random) { private static Long insertNewGame(User user, GameDifficulty difficulty, GameDefinition gameDefinition, TablexiaRandom random) {
try { try {
...@@ -216,12 +223,12 @@ public class Game { ...@@ -216,12 +223,12 @@ public class Game {
String startTimeStr = resultSet.getString(6); String startTimeStr = resultSet.getString(6);
String endTimeStr = resultSet.getString(7); String endTimeStr = resultSet.getString(7);
selectedGame = new Game(resultSet.getLong(1), selectedGame = new Game(resultSet.getLong(1),
User.selectUser(resultSet.getLong(2)), User.selectUser(resultSet.getLong(2)),
GameDifficulty.getGameDifficultyForDifficultyNumber(resultSet.getInt(3)), GameDifficulty.getGameDifficultyForDifficultyNumber(resultSet.getInt(3)),
GameDefinition.getGameDefinitionForGameNumber(resultSet.getInt(4)), GameDefinition.getGameDefinitionForGameNumber(resultSet.getInt(4)),
new TablexiaRandom(resultSet.getLong(5)), new TablexiaRandom(resultSet.getLong(5)),
startTimeStr != null ? Long.valueOf(startTimeStr) : null, startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null); endTimeStr != null ? Long.valueOf(endTimeStr) : null);
} }
resultSet.close(); resultSet.close();
} catch (SQLException e) { } catch (SQLException e) {
...@@ -234,6 +241,57 @@ public class Game { ...@@ -234,6 +241,57 @@ public class Game {
return selectedGame; return selectedGame;
} }
private static List<Game> selectGamesForUserAndDifficulty(long userId, int difficultyNumber) {
List<Game> selectedGames = new ArrayList<Game>();
try {
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(GAME_SELECT_FOR_USER_AND_DIFFICULTY);
statement.setLong(1, userId);
statement.setInt(2, difficultyNumber);
try {
ResultSet resultSet = statement.executeQuery();
boolean hasNextGames = true;
while (hasNextGames) {
if (resultSet.next()) {
Game game;
String startTimeStr = resultSet.getString(6);
String endTimeStr = resultSet.getString(7);
game = new Game(resultSet.getLong(1),
User.selectUser(resultSet.getLong(2)),
GameDifficulty.getGameDifficultyForDifficultyNumber(resultSet.getInt(3)),
GameDefinition.getGameDefinitionForGameNumber(resultSet.getInt(4)),
new TablexiaRandom(resultSet.getLong(5)),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null);
selectedGames.add(game);
} else {
hasNextGames = false;
Log.info(User.class, "Select completed, no more games");
}
}
resultSet.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot select game with user id : " + userId + ", and difficulty: " + difficultyNumber, e);
}
statement.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot select game with user id : " + userId + ", and difficulty: " + difficultyNumber, e);
}
return selectedGames;
}
private static Long selectLastGameId() { private static Long selectLastGameId() {
Long id = null; Long id = null;
try { try {
......
...@@ -17,13 +17,17 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; ...@@ -17,13 +17,17 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable; import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Map; import java.util.Map;
import cz.nic.tablexia.TablexiaSettings; import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.TablexiaStorage;
import cz.nic.tablexia.game.GameDefinition; import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager; import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.model.game.Game;
import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.statistics.views.BookmarkButton; import cz.nic.tablexia.screen.statistics.views.BookmarkButton;
import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.Log;
...@@ -106,6 +110,12 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> { ...@@ -106,6 +110,12 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
screenResized(0, 0); screenResized(0, 0);
// TODO change dataset // TODO change dataset
//ukázkový výpis
for(Game game : Game.getGamesForResults(getSelectedUser().getId(), 1)) {
Log.info(((Object) this).getClass(), "Game id: "+ game.getId() + " results: " + game.getDifficulty() + " " + game.getGameDuration());
}
} }
private Switch.DragSwitchListener.SwitchSelectedListener switchListener = new Switch.DragSwitchListener.SwitchSelectedListener() { private Switch.DragSwitchListener.SwitchSelectedListener switchListener = new Switch.DragSwitchListener.SwitchSelectedListener() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment