Displaying player statistics.

This commit is contained in:
marcins78@gmail.com
2012-07-11 09:54:50 +00:00
parent 6dd7cf7d8c
commit 019ad5c0d4
10 changed files with 103 additions and 29 deletions

View File

@@ -268,7 +268,7 @@ public class GameHistoryDAO {
}
}
public List<PlayerStatistic> getCompetetivePlayerStatistics(Player player) {
public List<PlayerStatistic> getCompetitivePlayerStatistics(Player player) {
try {
Connection connection = _dbAccess.getDataSource().getConnection();
try {

View File

@@ -62,7 +62,7 @@ public class GameHistoryService {
return _gameHistoryDAO.getCasualPlayerStatistics(player);
}
public List<PlayerStatistic> getCompetetivePlayerStatistics(Player player) {
return _gameHistoryDAO.getCompetetivePlayerStatistics(player);
public List<PlayerStatistic> getCompetitivePlayerStatistics(Player player) {
return _gameHistoryDAO.getCompetitivePlayerStatistics(player);
}
}

View File

@@ -122,7 +122,7 @@ public class LotroServer extends AbstractServer {
return "Game" + gameId;
}
public synchronized String createNewGame(LotroFormat lotroFormat, String tournamentName, final LotroGameParticipant[] participants, boolean competetive, boolean tournament) {
public synchronized String createNewGame(LotroFormat lotroFormat, String tournamentName, final LotroGameParticipant[] participants, boolean competitive, boolean tournament) {
if (participants.length < 2)
throw new IllegalArgumentException("There has to be at least two players");
final String gameId = String.valueOf(_nextGameId);
@@ -139,7 +139,7 @@ public class LotroServer extends AbstractServer {
_chatServer.createChatRoom(getChatRoomName(gameId), 30);
LotroGameMediator lotroGameMediator = new LotroGameMediator(lotroFormat, participants, _lotroCardBlueprintLibrary,
competetive ? 60 * 40 : 60 * 80, noSpectators, cancellable);
competitive ? 60 * 40 : 60 * 80, noSpectators, cancellable);
lotroGameMediator.addGameResultListener(
new GameResultListener() {
@Override

View File

@@ -394,8 +394,8 @@ public class HallServer extends AbstractServer {
_awaitingTables.remove(tableId);
}
private void createGame(String tableId, LotroGameParticipant[] participants, GameResultListener listener, LotroFormat lotroFormat, String tournamentName, boolean competetive, boolean tournament) {
String gameId = _lotroServer.createNewGame(lotroFormat, tournamentName, participants, competetive, tournament);
private void createGame(String tableId, LotroGameParticipant[] participants, GameResultListener listener, LotroFormat lotroFormat, String tournamentName, boolean competitive, boolean tournament) {
String gameId = _lotroServer.createNewGame(lotroFormat, tournamentName, participants, competitive, tournament);
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
if (listener != null)
lotroGameMediator.addGameResultListener(listener);

View File

@@ -283,7 +283,7 @@ public class ServerResource extends AbstractResource {
Player resourceOwner = getResourceOwnerSafely(request, participantId);
List<PlayerStatistic> casualStatistics = _gameHistoryService.getCasualPlayerStatistics(resourceOwner);
List<PlayerStatistic> competetiveStatistics = _gameHistoryService.getCompetetivePlayerStatistics(resourceOwner);
List<PlayerStatistic> competitiveStatistics = _gameHistoryService.getCompetitivePlayerStatistics(resourceOwner);
DecimalFormat percFormat = new DecimalFormat("#0.0%");
@@ -296,9 +296,9 @@ public class ServerResource extends AbstractResource {
appendStatistics(casualStatistics, percFormat, doc, casual);
stats.appendChild(casual);
Element competetive = doc.createElement("competetive");
appendStatistics(competetiveStatistics, percFormat, doc, competetive);
stats.appendChild(competetive);
Element competitive = doc.createElement("competitive");
appendStatistics(competitiveStatistics, percFormat, doc, competitive);
stats.appendChild(competitive);
doc.appendChild(stats);
return doc;

View File

@@ -190,6 +190,7 @@
<script type="text/javascript" src="js/gemp-010/leagueResultsUi.js"></script>
<script type="text/javascript" src="js/gemp-010/tournamentResultsUi.js"></script>
<script type="text/javascript" src="js/gemp-010/statsUi.js"></script>
<script type="text/javascript" src="js/gemp-010/playerStatsUi.js"></script>
<script type="text/javascript" src="js/gemp-010/gameHistoryUi.js"></script>
<script type="text/javascript" src="js/gemp-010/communication.js"></script>
<!-- This is needed for delivery -->
@@ -237,11 +238,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) {
@@ -318,7 +319,8 @@
<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>
<li><a href="includes/yourStats.html">Your stats</a></li>
<li><a href="includes/stats.html">Server 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,9 @@
<script type="text/javascript">
$(document).ready(
function () {
var ui = new PlayerStatsUI("/gemp-lotr-server");
});
</script>
All times are GMT based.
<div id="playerStats"></div>

View File

@@ -83,6 +83,19 @@ var GempLotrCommunication = Class.extend({
});
},
getPlayerStats:function (callback, errorMap) {
$.ajax({
type:"GET",
url:this.url + "/playerStats",
cache:false,
data:{
participantId:getUrlParam("participantId") },
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
dataType:"xml"
});
},
getLiveTournaments:function (callback, errorMap) {
$.ajax({
type:"GET",

View File

@@ -0,0 +1,51 @@
var PlayerStatsUI = Class.extend({
communication:null,
init:function (url) {
this.communication = new GempLotrCommunication(url,
function (xhr, ajaxOptions, thrownError) {
});
this.loadPlayerStats();
},
loadPlayerStats:function () {
this.communication.getPlayerStats(this.loadedPlayerStats);
},
loadedPlayerStats:function (xml) {
var that = this;
log(xml);
var root = xml.documentElement;
if (root.tagName == 'playerStats') {
$("#playerStats").html("");
var stats = root;
var casual = stats.getElementsByTagName("casual")[0];
var competitive = stats.getElementsByTagName("competitive")[0];
$("#playerStats").append("<div class='playerStatHeader'>Casual statistics</div>");
this.appendStats(casual);
$("#playerStats").append("<div class='playerStatHeader'>Competitive statistics</div>");
this.appendStats(competitive);
}
},
appendStats:function (stats) {
var entries = stats.getElementsByTagName("entry");
if (entries.length == 0) {
$("#playerStats").append("<i>You have not played any games counting for this statistics</i>");
} else {
var table = $("<table class='tables'></table>");
table.append("<tr><th>Format name</th><th>Deck name</th><th># of wins</th><th># of losses</th><th>% of wins</th></tr>");
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
table.append("<tr><td>" + entry.getAttribute("format") + "</td><td>" + entry.getAttribute("deckName") + "</td><td>" + entry.getAttribute("wins") + "</td><td>" + entry.getAttribute("losses") + "</td><td>" + entry.getAttribute("perc") + "</td></tr>");
}
$("#playerStats").append(table);
}
}
});

View File

@@ -1,11 +1,10 @@
var StatsUI = Class.extend({
communication:null,
formatDialog:null,
init:function (url) {
this.communication = new GempLotrCommunication(url,
function (xhr, ajaxOptions, thrownError) {
});
function (xhr, ajaxOptions, thrownError) {
});
var now = new Date();
@@ -18,16 +17,16 @@ var StatsUI = Class.extend({
var that = this;
$(".getStats", $("#statsParameters")).click(
function () {
var startDay = $(".startDay", $("#statsParameters")).prop("value");
var period = $("option:selected", $(".period", $("#statsParameters"))).prop("value");
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");
}
})
});
that.communication.getStats(startDay, period, that.loadedStats, {
"400":function () {
alert("Invalid parameter entered");
}
})
});
},
loadedStats:function (xml) {