push und pull Stats überarbeitet

This commit is contained in:
2022-03-03 13:27:19 +01:00
parent 4636051237
commit 2337ad327d
2 changed files with 60 additions and 26 deletions

View File

@@ -7,28 +7,43 @@ public class Query {
public void pullStats(User user) { public void pullStats(User user) {
String[][] r; String[][] r;
db.executeStatement("SELECT * FROM user WHERE user LIKE" + user.username); db.executeStatement("SELECT * FROM user WHERE user LIKE" + user.getUsername());
r = db.getCurrentQueryResult().getData(); r = db.getCurrentQueryResult().getData();
user.currentStreak = Integer.parseInt(r[1][0]); user.setCurrentStreak(Integer.parseInt(r[1][0]));
user.maxStreak = Integer.parseInt(r[2][0]); user.setMaxStreak(Integer.parseInt(r[2][0]));
user.wins = Integer.parseInt(r[3][0]); user.setWins(Integer.parseInt(r[3][0]));
user.timesPlayed = Integer.parseInt(r[4][0]); user.setTimesPlayed(Integer.parseInt(r[4][0]));
user.wonInTurn[0] = Integer.parseInt(r[5][0]);
user.wonInTurn[1] = Integer.parseInt(r[6][0]); int wonInTurn[] = new int[6];
user.wonInTurn[2] = Integer.parseInt(r[7][0]); wonInTurn[0] = Integer.parseInt(r[5][0]);
user.wonInTurn[3] = Integer.parseInt(r[8][0]); wonInTurn[1] = Integer.parseInt(r[6][0]);
user.wonInTurn[4] = Integer.parseInt(r[9][0]); wonInTurn[2] = Integer.parseInt(r[7][0]);
user.wonInTurn[5] = Integer.parseInt(r[10][0]); wonInTurn[3] = Integer.parseInt(r[8][0]);
user.lastDayWOTDFinished = Integer.parseInt(r[11][0]); wonInTurn[4] = Integer.parseInt(r[9][0]);
wonInTurn[5] = Integer.parseInt(r[10][0]);
user.setWonInTurn(wonInTurn);
user.setLastDayWOTDFinished(Integer.parseInt(r[11][0]));
} }
public void pushStats(User user) { public void pushStats(User user) {
db.executeStatement("UPDATE INTO Stats (current_streak," + " max_streak, " + "wins, " + "times_played, " db.executeStatement("UPDATE INTO Stats (current_streak," + " max_streak, " + "wins, " + "times_played, "
+ "won_on_1, " + "won_on_2, " + "won_on_3, " + "won_on_4, " + "won_on_5, " + "won_on_6, " + "won_on_1, " + "won_on_2, " + "won_on_3, " + "won_on_4, " + "won_on_5, " + "won_on_6, "
+ "last_day_WOTD_finished) " + "VALUES (" + user.currentStreak + user.maxStreak + user.wins + "last_day_WOTD_finished) " + "VALUES ("
+ user.timesPlayed + user.wonInTurn[0] + user.wonInTurn[1] + user.wonInTurn[2] + user.wonInTurn[3] + Integer.toString(user.getCurrentStreak())
+ user.wonInTurn[4] + user.wonInTurn[5] + user.lastDayWOTDFinished + ")"); + Integer.toString(user.getMaxStreak())
+ Integer.toString(user.getWins())
+ Integer.toString(user.getTimesPlayed())
+ Integer.toString(user.getWonInTurnIndex(0))
+ Integer.toString(user.getWonInTurnIndex(1))
+ Integer.toString(user.getWonInTurnIndex(2))
+ Integer.toString(user.getWonInTurnIndex(3))
+ Integer.toString(user.getWonInTurnIndex(4))
+ Integer.toString(user.getWonInTurnIndex(5))
+ Integer.toString(user.getLastDayWOTDFinished())
+ ")");
} }
public boolean checkLogin(String username, String password) { public boolean checkLogin(String username, String password) {

View File

@@ -1,16 +1,16 @@
public class User { public class User {
String connectionID; private String connectionID;
String username; private String username;
String password; String password;
int timesPlayed; private int timesPlayed;
int winPercentage; private int winPercentage;
int currentStreak; private int currentStreak;
int maxStreak; private int maxStreak;
int lastDayWOTDFinished; private int lastDayWOTDFinished;
int state; private int state;
int wins; private int wins;
int [] wonInTurn; private int [] wonInTurn;
Game game; private Game game;
public User (String pConnectionID){ public User (String pConnectionID){
connectionID =pConnectionID; connectionID =pConnectionID;
@@ -45,10 +45,21 @@ public class User {
return state; return state;
} }
public void setWins(int wins) {
this.wins = wins;
}
public int getWinPercentage() { public int getWinPercentage() {
return winPercentage; return winPercentage;
} }
public int getWonInTurnIndex(int index) {
return wonInTurn[index];
}
public int[] getWonInTurn() { public int[] getWonInTurn() {
return wonInTurn; return wonInTurn;
} }
@@ -61,6 +72,10 @@ public class User {
return username; return username;
} }
public int getWins() {
return wins;
}
public void setConnectionID(String connectionID) { public void setConnectionID(String connectionID) {
this.connectionID = connectionID; this.connectionID = connectionID;
} }
@@ -97,6 +112,10 @@ public class User {
this.winPercentage = winPercentage; this.winPercentage = winPercentage;
} }
public void setWonInTurnIndex(int index, int content) {
this.wonInTurn[index] = content;
}
public void setWonInTurn(int[] wonInTurn) { public void setWonInTurn(int[] wonInTurn) {
this.wonInTurn = wonInTurn; this.wonInTurn = wonInTurn;
} }