diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/communication.js b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/communication.js
index ee76385ea..5134b27ce 100644
--- a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/communication.js
+++ b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/communication.js
@@ -79,7 +79,7 @@ var GempLotrCommunication = Class.extend({
participantId:getUrlParam("participantId") },
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
- dataType:"xml"
+ dataType:"json"
});
},
diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/statsUi.js b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/statsUi.js
index ddd404f60..25f670150 100644
--- a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/statsUi.js
+++ b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/statsUi.js
@@ -35,38 +35,66 @@ var StatsUI = Class.extend({
})
});
},
+
+ getPercentage:function (num1, num2) {
+ return Number(num1 / num2).toLocaleString(undefined, {style: 'percent', minimumFractionDigits:2});
+ },
- loadedStats:function (xml) {
+ loadedStats:function (json) {
var that = this;
- log(xml);
- var root = xml.documentElement;
- if (root.tagName == 'stats') {
- $("#stats").html("");
+ log(json);
+
+ var getPercentage = (num1, num2) => Number(num1 / num2).toLocaleString(undefined, {style: 'percent', minimumFractionDigits:2});
- var stats = root;
+ $("#startDateSpan").html(json["StartDate"]);
+ $("#endDateSpan").html(json["EndDate"]);
+ $("#activePlayersStat").html(json["ActivePlayers"]);
+ $("#gamesCountStat").html(json["GamesCount"]);
- var activePlayers = stats.getAttribute("activePlayers");
- var gamesCount = stats.getAttribute("gamesCount");
- var start = stats.getAttribute("start");
- var end = stats.getAttribute("end");
-
- $("#stats").append("
Stats for " + start + " - " + end + "
");
- $("#stats").append("
Active players: " + activePlayers + "
");
- $("#stats").append("
All games count: " + gamesCount + "
");
-
- var formatStats = stats.getElementsByTagName("formatStat");
- if (formatStats.length > 0) {
- $("#stats").append("
Casual games per format
");
-
- var table = $("
");
- table.append("
Format name
# of games
% of casual
");
- for (var i = 0; i < formatStats.length; i++) {
- var formatStat = formatStats[i];
- table.append("
" + formatStat.getAttribute("format") + "
" + formatStat.getAttribute("count") + "
" + formatStat.getAttribute("perc") + "
");
+ var formatStats = json["Stats"];
+ if (formatStats.length > 0) {
+
+ var casualStats = $("#casualStatsTable");
+ var compStats = $("#competitiveStatsTable");
+ $("#casualStatsTable > tbody").empty();
+ $("#competitiveStatsTable > tbody").empty();
+
+ var casuals = 0;
+ var comps = 0;
+ var total = 0;
+
+ json["Stats"].forEach(item => {
+ if(item.Casual) {
+ casuals += item.Count;
}
+ else {
+ comps += item.Count;
+ }
+ total += item.Count;
+ });
+
+ json["Stats"].forEach(item => {
+
+ var test = getPercentage(item.Count, total);
+
+ if(item.Casual) {
+ casualStats.append("
"
+ + "
" + item.Format + "
"
+ + "
" + item.Count + "
"
+ + "
" + getPercentage(item.Count, casuals) + "
"
+ + "
" + getPercentage(item.Count, total) + "
"
+ + "
");
+ }
+ else {
+ compStats.append("
"
+ + "
" + item.Format + "
"
+ + "
" + item.Count + "
"
+ + "
" + getPercentage(item.Count, comps) + "
"
+ + "
" + getPercentage(item.Count, total) + "
"
+ + "
");
+ }
+ });
- $("#stats").append(table);
- }
}
}
});
\ No newline at end of file
diff --git a/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/DBDefs.java b/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/DBDefs.java
index 12e990a86..b10e8d936 100644
--- a/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/DBDefs.java
+++ b/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/DBDefs.java
@@ -65,4 +65,10 @@ public class DBDefs {
public int id;
public String name;
}
+
+ public static class FormatStats {
+ public String Format;
+ public int Count;
+ public boolean Casual;
+ }
}
diff --git a/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/JSONDefs.java b/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/JSONDefs.java
index 5d0d5e76b..4efa31e0c 100644
--- a/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/JSONDefs.java
+++ b/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/JSONDefs.java
@@ -73,4 +73,12 @@ public class JSONDefs {
public Map ErrataIDs;
}
+ public static class PlayHistoryStats {
+ public List Stats;
+ public int ActivePlayers;
+ public int GamesCount;
+ public String StartDate;
+ public String EndDate;
+ }
+
}
diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbGameHistoryDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbGameHistoryDAO.java
index 5bda87e5d..c020b68a6 100644
--- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbGameHistoryDAO.java
+++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbGameHistoryDAO.java
@@ -174,6 +174,34 @@ public class DbGameHistoryDAO implements GameHistoryDAO {
}
}
+ public List GetAllGameFormatData(long from, long duration) {
+ try {
+ Sql2o db = new Sql2o(_dbAccess.getDataSource());
+
+ try (org.sql2o.Connection conn = db.open()) {
+ String sql = """
+ SELECT
+ COUNT(*) AS Count
+ ,format_name AS Format
+ ,CASE WHEN tournament IS NULL OR tournament LIKE 'Casual %' THEN 1 ELSE 0 END AS Casual
+ FROM game_history
+ WHERE end_date >= :from
+ AND end_date < :to
+ GROUP BY format_name, CASE WHEN tournament IS NULL OR tournament LIKE 'Casual %' THEN 1 ELSE 0 END
+ """;
+ List result = conn.createQuery(sql)
+ .addParameter("from", from)
+ .addParameter("to", from + duration)
+ .executeAndFetch(DBDefs.FormatStats.class);
+
+ return result;
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException("Unable to retrieve format stats", ex);
+ }
+ }
+
+
public List getCasualPlayerStatistics(Player player) {
try {
try (Connection connection = _dbAccess.getDataSource().getConnection()) {
diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/GameHistoryDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/GameHistoryDAO.java
index 236cced60..e7626e51a 100644
--- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/GameHistoryDAO.java
+++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/GameHistoryDAO.java
@@ -22,6 +22,8 @@ public interface GameHistoryDAO {
public Map getCasualGamesPlayedPerFormat(long from, long duration);
+ public List GetAllGameFormatData(long from, long duration);
+
public List getCasualPlayerStatistics(Player player);
public List getCompetitivePlayerStatistics(Player player);
diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameHistoryService.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameHistoryService.java
index d271074d7..7868366af 100644
--- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameHistoryService.java
+++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameHistoryService.java
@@ -56,10 +56,8 @@ public class GameHistoryService {
return _gameHistoryDAO.getGamesPlayedCount(from, duration);
}
- public GameHistoryStatistics getGameHistoryStatistics(long from, long duration) {
- GameHistoryStatistics stats = new GameHistoryStatistics(from, duration);
- stats.init(_gameHistoryDAO);
- return stats;
+ public List getGameHistoryStatistics(long from, long duration) {
+ return _gameHistoryDAO.GetAllGameFormatData(from, duration);
}
public List getCasualPlayerStatistics(Player player) {