diff --git a/RaceTimer/racetimer_endpoints/src/main/java/DTO/MapBoardDTO.java b/RaceTimer/racetimer_endpoints/src/main/java/DTO/MapBoardDTO.java index f8e307c5..df64091a 100644 --- a/RaceTimer/racetimer_endpoints/src/main/java/DTO/MapBoardDTO.java +++ b/RaceTimer/racetimer_endpoints/src/main/java/DTO/MapBoardDTO.java @@ -21,7 +21,7 @@ public class MapBoardDTO { private String name; private String avatar; private int mapPoint; - private String mapTime; + private Float mapTime; private int position; private List badgesUrls = new ArrayList(); @@ -69,11 +69,11 @@ public class MapBoardDTO { this.mapPoint = mapPoint; } - public String getMapTime() { + public Float getMapTime() { return mapTime; } - public void setMapTime(String mapTime) { + public void setMapTime(Float mapTime) { this.mapTime = mapTime; } diff --git a/RaceTimer/racetimer_endpoints/src/main/java/DTO/MapValuesDTO.java b/RaceTimer/racetimer_endpoints/src/main/java/DTO/MapValuesDTO.java index ad95d043..38c23c78 100644 --- a/RaceTimer/racetimer_endpoints/src/main/java/DTO/MapValuesDTO.java +++ b/RaceTimer/racetimer_endpoints/src/main/java/DTO/MapValuesDTO.java @@ -15,7 +15,7 @@ public class MapValuesDTO { private int position; private String playerSteamID; - private String time; + private Float time; private int mapPoints; public int getPosition() { @@ -34,11 +34,11 @@ public class MapValuesDTO { this.playerSteamID = playerSteamID; } - public String getTime() { + public Float getTime() { return time; } - public void setTime(String time) { + public void setTime(Float time) { this.time = time; } diff --git a/RaceTimer/racetimer_endpoints/src/main/java/DTO/PlayerMapBoardDTO.java b/RaceTimer/racetimer_endpoints/src/main/java/DTO/PlayerMapBoardDTO.java index ca91a2a4..e8893b2f 100644 --- a/RaceTimer/racetimer_endpoints/src/main/java/DTO/PlayerMapBoardDTO.java +++ b/RaceTimer/racetimer_endpoints/src/main/java/DTO/PlayerMapBoardDTO.java @@ -24,7 +24,7 @@ public class PlayerMapBoardDTO { private String mapname; private int mapstage; private int mapPoint; - private String mapTime; + private Float mapTime; private int position; public PlayerMapBoardDTO() { diff --git a/RaceTimer/racetimer_endpoints/src/main/java/DataMapper/DataMapperCalls.java b/RaceTimer/racetimer_endpoints/src/main/java/DataMapper/DataMapperCalls.java index 660d3a36..8de5f3c8 100644 --- a/RaceTimer/racetimer_endpoints/src/main/java/DataMapper/DataMapperCalls.java +++ b/RaceTimer/racetimer_endpoints/src/main/java/DataMapper/DataMapperCalls.java @@ -30,33 +30,55 @@ public class DataMapperCalls { public static Map.Entry, Collection> getAllValues() { Collection allPlayers = new ArrayList(); ConcurrentMap allMapBoards = new MapMaker().concurrencyLevel(4).makeMap(); - String sqlQuery = "SELECT * FROM `zetimer_table`"; try (Connection con = DBCPDataSource.getConnection()) { - try (PreparedStatement ps = con.prepareStatement(sqlQuery)) { + String sqlQuery_size = "SELECT count(*) FROM `zetimer_table_new`"; + int rows_size = 0; + try (PreparedStatement ps = con.prepareStatement(sqlQuery_size)) { try (ResultSet result = ps.executeQuery()) { - int fetchSize = result.getMetaData().getColumnCount(); - while (result.next() /*&& limitfetch < 25*/) { - int timesCounter = 0; - Player player = new Player(result.getString(1), result.getString(2)); - //System.out.println("player dataMapper: " + player.getName() + "\nsteamid: " + player.getSteamID()); - int i = 3; - while (i <= fetchSize) { - String specificTime = result.getString(i); - if (specificTime != null && !specificTime.equals("0.000")) { - String columnLabel = result.getMetaData().getColumnLabel(i); - if (!allMapBoards.keySet().contains(columnLabel)) { - allMapBoards.put(columnLabel, new MapBoard(columnLabel)); + result.next(); + rows_size = result.getInt(1); + } + } + //just a way to fetch 500 results at a time as seemingly struggling with just a select * from table statement. + String last_steam_auth = ""; + while (allPlayers.size() < rows_size) + { + String sqlQuery = "select * from `zetimer_table_new` ztn where ztn.steam_auth > '" + last_steam_auth + "'\n" + + "order by steam_auth asc limit 5000 "; + if (allPlayers.size() == 0) + { + sqlQuery = "select * from `zetimer_table_new` ztn order by steam_auth asc limit 5000"; + } + //System.out.println("sqlQuery: " + sqlQuery); + try (PreparedStatement ps = con.prepareStatement(sqlQuery)) { + ps.setFetchSize(100); + //System.out.println("allplayers size: " + allPlayers.size() + " rows_size: " + rows_size); + try (ResultSet result = ps.executeQuery()) { + int fetchSize = result.getMetaData().getColumnCount(); + while (result.next() /*&& limitfetch < 25*/) { + int timesCounter = 0; + Player player = new Player(result.getString(1), result.getString(2)); + //System.out.println("player dataMapper: " + player.getName() + "\nsteamid: " + player.getSteamID()); + int i = 3; + while (i <= fetchSize) { + Float specificTime = result.getFloat(i); + if (specificTime != null && specificTime != 0) { + String columnLabel = result.getMetaData().getColumnLabel(i); + if (!allMapBoards.keySet().contains(columnLabel)) { + allMapBoards.put(columnLabel, new MapBoard(columnLabel)); + } + timesCounter++; + MapValues mapValue = new MapValues(); + mapValue.setPlayerSteamID(player.getSteamID()); + mapValue.setTime(specificTime); + allMapBoards.get(columnLabel).getMapvalues().add(mapValue); } - timesCounter++; - MapValues mapValue = new MapValues(); - mapValue.setPlayerSteamID(player.getSteamID()); - mapValue.setTime(specificTime); - allMapBoards.get(columnLabel).getMapvalues().add(mapValue); + i++; } - i++; + player.setTimesCount(timesCounter); + allPlayers.add(player); + last_steam_auth = player.getSteamID(); } - player.setTimesCount(timesCounter); - allPlayers.add(player); } } } @@ -114,4 +136,4 @@ public class DataMapperCalls { } return new AbstractMap.SimpleEntry(map, stage); } -} +} \ No newline at end of file diff --git a/RaceTimer/racetimer_endpoints/src/main/java/entity/MapValues.java b/RaceTimer/racetimer_endpoints/src/main/java/entity/MapValues.java index b8995c29..0d298a5a 100644 --- a/RaceTimer/racetimer_endpoints/src/main/java/entity/MapValues.java +++ b/RaceTimer/racetimer_endpoints/src/main/java/entity/MapValues.java @@ -40,7 +40,7 @@ public class MapValues implements Serializable { private String playerSteamID; @Basic(optional = false) @NotNull - private String time; + private Float time; @Basic(optional = false) @NotNull private int mapPoints; @@ -75,11 +75,11 @@ public class MapValues implements Serializable { this.playerSteamID = steamID; } - public String getTime() { + public Float getTime() { return time; } - public void setTime(String specificTime) { + public void setTime(Float specificTime) { this.time = specificTime; } diff --git a/RaceTimer/racetimer_endpoints/src/main/java/facade/Facade.java b/RaceTimer/racetimer_endpoints/src/main/java/facade/Facade.java index 31291cf5..57c521ec 100644 --- a/RaceTimer/racetimer_endpoints/src/main/java/facade/Facade.java +++ b/RaceTimer/racetimer_endpoints/src/main/java/facade/Facade.java @@ -398,29 +398,12 @@ public class Facade { for (MapBoard mapboard : mapboards) { //System.out.println("mapName: " + mapboard.getMapName()); List mapvalues = new ArrayList(); - List less_than_a_minute = new ArrayList<>(); - List less_than_10_seconds = new ArrayList<>(); for (MapValues mv : mapboard.getMapvalues()) { - String time = mv.getTime(); - int indexOf = time.indexOf("."); - if (indexOf == 1){ - less_than_10_seconds.add(mv); - } - else if (!time.contains(":")) - { - less_than_a_minute.add(mv); - } - else{ - mapvalues.add(mv); - } + mapvalues.add(mv); } - less_than_10_seconds.sort(Comparator.comparing(MapValues::getTime)); mapvalues.sort(Comparator.comparing(MapValues::getTime)); - less_than_a_minute.sort(Comparator.comparing(MapValues::getTime)); - less_than_10_seconds.addAll(less_than_a_minute); - less_than_10_seconds.addAll(mapvalues); - mapBoardCache.get(mapboard.getMapName()).setMapvalues(less_than_10_seconds); + mapBoardCache.get(mapboard.getMapName()).setMapvalues(mapvalues); } }