Adding statistics UI.

This commit is contained in:
marcins78@gmail.com
2012-07-09 15:14:16 +00:00
parent 38fa8ef2c5
commit 3b61920fa3
4 changed files with 85 additions and 5 deletions

View File

@@ -255,6 +255,8 @@ public class ServerResource extends AbstractResource {
Element stats = doc.createElement("stats");
stats.setAttribute("activePlayers", String.valueOf(activePlayers));
stats.setAttribute("gamesCount", String.valueOf(gamesCount));
stats.setAttribute("start", format.format(new Date(from)));
stats.setAttribute("end", format.format(new Date(from + duration - 1)));
for (GameHistoryStatistics.FormatStat formatStat : gameHistoryStatistics.getFormatStats()) {
Element formatStatElem = doc.createElement("formatStat");
formatStatElem.setAttribute("format", formatStat.getFormat());

View File

@@ -184,6 +184,7 @@
<script type="text/javascript" src="js/gemp-009/hallUi.js"></script>
<script type="text/javascript" src="js/gemp-009/leagueResultsUi.js"></script>
<script type="text/javascript" src="js/gemp-009/tournamentResultsUi.js"></script>
<script type="text/javascript" src="js/gemp-009/statsUi.js"></script>
<script type="text/javascript" src="js/gemp-009/gameHistoryUi.js"></script>
<script type="text/javascript" src="js/gemp-009/communication.js"></script>
<!-- This is needed for delivery -->
@@ -231,11 +232,11 @@
var infoDialog = $("<div></div>")
.dialog({
autoOpen:false,
closeOnEscape:true,
resizable:false,
title:"Card information"
});
autoOpen:false,
closeOnEscape:true,
resizable:false,
title:"Card information"
});
$("body").click(
function (event) {
@@ -312,6 +313,7 @@
<li><a href="includes/instruction.html">Manual</a></li>
<li><a href="/gemp-lotr-server/hall/formats/html">Format Rules</a></li>
<li><a href="includes/contribute.html">Contribute</a></li>
<li><a href="includes/stats.html">Stats</a></li>
<script type="text/javascript">
document.write('<li><a href="includes/changeLog.html?_=' + (new Date().getTime()) + '">Change Log</a></li>');
</script>

View File

@@ -0,0 +1,10 @@
<script type="text/javascript">
$(document).ready(
function () {
var ui = new StatsUI("/gemp-lotr-server");
});
</script>
All times are GMT based.
<div id="statsParameters"></div>
<div id="stats"></div>

View File

@@ -0,0 +1,66 @@
var StatsUI = Class.extend({
communication:null,
formatDialog:null,
init:function (url) {
this.communication = new GempLotrCommunication(url,
function (xhr, ajaxOptions, thrownError) {
});
var now = new Date();
var nowStr = now.getFullYear() + "-" + (1 + now.getMonth()) + "-" + now.getDate();
$(".statsParameters").append("Start date: <input class='startDay' type='text' value='" + nowStr + "'>");
$(".statsParameters").append(" period: <select class='period'><option value='month'>month</option><option value='week'>week</option><option value='day'>day</option></select>");
$(".statsParameters").append(" <input class='getStats' type='button' value='Display stats'>");
var that = this;
$(".getStats", $(".statsParameters")).click(
function () {
var startDay = $(".startDay", $(".statsParameters")).prop("value");
var period = $("option:selected", $(".period", $(".statsParameters"))).prop("value");
that.communication.getStats(startDay, period, that.loadedStats, {
"400":function () {
alert("Invalid parameter entered");
}
})
});
},
loadedStats:function (xml) {
var that = this;
log(xml);
var root = xml.documentElement;
if (root.tagName == 'stats') {
$("#stats").html("");
var stats = root;
var activePlayers = stats.getAttribute("activePlayers");
var gamesCount = stats.getAttribute("gamesCount");
var start = stats.getAttribute("start");
var end = stats.getAttribute("end");
$("#stats").append("<div class='period'>Stats for " + start + " - " + end + "</div>");
$("#stats").append("<div class='activePlayers'>Active players: " + activePlayers + "</div>");
$("#stats").append("<div class='gamesCount'>All games count: " + gamesCount + "</div>");
var formatStats = stats.getElementsByTagName("formatStat");
if (formatStats.length > 0) {
$("#stats").append("<div class='tableHeader'>Casual games per format</div>");
var table = $("<table></table>");
table.append("<tr><th>Format name</th><th># of games</th><th>% of casual</th></tr>");
for (var i = 0; i < formatStats.length; i++) {
var formatStat = formatStats[i];
table.append("<tr><td>" + formatStat.getAttribute("format") + "</td><td>" + formatStat.getAttribute("count") + "</td><td>" + formatStat.getAttribute("perc") + "</td></tr>");
}
$("#stats").append(table);
}
}
}
});