Playtest Recent Replays

Added a new readout to the Playtesting tab that shows the last 100 playtest games.
Overhauled the game history database access to utilize a POJO reader (sql2o) and a json serializer (gson).  The serialized output is piped to the client as json and converted to a table using a template library (json2html).  This pipeline is more or less what future client-server DB operations should look like, as it takes far less code to write and maintain.
This commit is contained in:
Christian 'ketura' McCarty
2021-03-27 20:18:38 -05:00
parent cf262ef78c
commit 934408755c
16 changed files with 1406 additions and 165 deletions

View File

@@ -27,6 +27,11 @@
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
<build>
<plugins>

View File

@@ -279,6 +279,18 @@ public class GempukkuHttpRequestHandler extends SimpleChannelInboundHandler<Full
sendResponse(ctx, request, response);
}
@Override
public void writeJsonResponse(String json) {
HttpHeaders headers = new DefaultHttpHeaders();
headers.set(CONTENT_TYPE, "application/json; charset=UTF-8");
if (json == null)
json = "{}";
// Build the response object.
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(json.getBytes(CharsetUtil.UTF_8)), headers, EmptyHttpHeaders.INSTANCE);
sendResponse(ctx, request, response);
}
@Override
public void writeByteResponse(byte[] bytes, Map<? extends CharSequence, String> headers) {
HttpHeaders headers1 = convertToHeaders(headers);

View File

@@ -12,6 +12,7 @@ public interface ResponseWriter {
public void writeFile(File file, Map<String, String> headers);
public void writeHtmlResponse(String html);
public void writeJsonResponse(String html);
public void writeByteResponse(byte[] bytes, Map<? extends CharSequence, String> headers);

View File

@@ -54,27 +54,27 @@ public class GameHistoryRequestHandler extends LotroServerRequestHandler impleme
for (GameHistoryEntry gameHistoryEntry : playerGameHistory) {
Element historyEntry = doc.createElement("historyEntry");
historyEntry.setAttribute("winner", gameHistoryEntry.getWinner());
historyEntry.setAttribute("loser", gameHistoryEntry.getLoser());
historyEntry.setAttribute("winner", gameHistoryEntry.winner);
historyEntry.setAttribute("loser", gameHistoryEntry.loser);
historyEntry.setAttribute("winReason", gameHistoryEntry.getWinReason());
historyEntry.setAttribute("loseReason", gameHistoryEntry.getLoseReason());
historyEntry.setAttribute("winReason", gameHistoryEntry.win_reason);
historyEntry.setAttribute("loseReason", gameHistoryEntry.lose_reason);
historyEntry.setAttribute("formatName", gameHistoryEntry.getFormatName());
String tournament = gameHistoryEntry.getTournament();
historyEntry.setAttribute("formatName", gameHistoryEntry.format_name);
String tournament = gameHistoryEntry.tournament;
if (tournament != null)
historyEntry.setAttribute("tournament", tournament);
if (gameHistoryEntry.getWinner().equals(resourceOwner.getName()) && gameHistoryEntry.getWinnerRecording() != null) {
historyEntry.setAttribute("gameRecordingId", gameHistoryEntry.getWinnerRecording());
historyEntry.setAttribute("deckName", gameHistoryEntry.getWinnerDeckName());
} else if (gameHistoryEntry.getLoser().equals(resourceOwner.getName()) && gameHistoryEntry.getLoserRecording() != null) {
historyEntry.setAttribute("gameRecordingId", gameHistoryEntry.getLoserRecording());
historyEntry.setAttribute("deckName", gameHistoryEntry.getLoserDeckName());
if (gameHistoryEntry.winner.equals(resourceOwner.getName()) && gameHistoryEntry.win_recording_id != null) {
historyEntry.setAttribute("gameRecordingId", gameHistoryEntry.win_recording_id);
historyEntry.setAttribute("deckName", gameHistoryEntry.winner_deck_name);
} else if (gameHistoryEntry.loser.equals(resourceOwner.getName()) && gameHistoryEntry.lose_recording_id != null) {
historyEntry.setAttribute("gameRecordingId", gameHistoryEntry.lose_recording_id);
historyEntry.setAttribute("deckName", gameHistoryEntry.loser_deck_name);
}
historyEntry.setAttribute("startTime", String.valueOf(gameHistoryEntry.getStartTime().getTime()));
historyEntry.setAttribute("endTime", String.valueOf(gameHistoryEntry.getEndTime().getTime()));
historyEntry.setAttribute("startTime", String.valueOf(gameHistoryEntry.GetStartDate().getTime()));
historyEntry.setAttribute("endTime", String.valueOf(gameHistoryEntry.GetEndDate().getTime()));
gameHistory.appendChild(historyEntry);
}
@@ -94,22 +94,22 @@ public class GameHistoryRequestHandler extends LotroServerRequestHandler impleme
for (GameHistoryEntry gameHistoryEntry : playerGameHistory) {
Element historyEntry = doc.createElement("historyEntry");
historyEntry.setAttribute("winner", gameHistoryEntry.getWinner());
historyEntry.setAttribute("loser", gameHistoryEntry.getLoser());
historyEntry.setAttribute("winner", gameHistoryEntry.winner);
historyEntry.setAttribute("loser", gameHistoryEntry.loser);
historyEntry.setAttribute("winReason", gameHistoryEntry.getWinReason());
historyEntry.setAttribute("loseReason", gameHistoryEntry.getLoseReason());
historyEntry.setAttribute("winReason", gameHistoryEntry.win_reason);
historyEntry.setAttribute("loseReason", gameHistoryEntry.lose_reason);
historyEntry.setAttribute("formatName", gameHistoryEntry.getFormatName());
historyEntry.setAttribute("formatName", gameHistoryEntry.format_name);
historyEntry.setAttribute("winnerRecordingLink", "http://www.gempukku.com/gemp-lotr/game.html?replayId="+gameHistoryEntry.getWinner()+"$"+gameHistoryEntry.getWinnerRecording());
historyEntry.setAttribute("winnerDeckName", gameHistoryEntry.getWinnerDeckName());
historyEntry.setAttribute("winnerRecordingLink", "http://www.gempukku.com/gemp-lotr/game.html?replayId="+gameHistoryEntry.winner+"$"+gameHistoryEntry.win_recording_id);
historyEntry.setAttribute("winnerDeckName", gameHistoryEntry.winner_deck_name);
historyEntry.setAttribute("loserRecordingLink", "http://www.gempukku.com/gemp-lotr/game.html?replayId="+gameHistoryEntry.getLoser()+"$"+gameHistoryEntry.getLoserRecording());
historyEntry.setAttribute("loserDeckName", gameHistoryEntry.getLoserDeckName());
historyEntry.setAttribute("loserRecordingLink", "http://www.gempukku.com/gemp-lotr/game.html?replayId="+gameHistoryEntry.loser+"$"+gameHistoryEntry.lose_recording_id);
historyEntry.setAttribute("loserDeckName", gameHistoryEntry.loser_deck_name);
historyEntry.setAttribute("startTime", dateFormat.format(new Date(gameHistoryEntry.getStartTime().getTime())));
historyEntry.setAttribute("endTime", dateFormat.format(new Date(gameHistoryEntry.getEndTime().getTime())));
historyEntry.setAttribute("startTime", dateFormat.format(new Date(gameHistoryEntry.GetStartDate().getTime())));
historyEntry.setAttribute("endTime", dateFormat.format(new Date(gameHistoryEntry.GetEndDate().getTime())));
gameHistory.appendChild(historyEntry);
}
@@ -134,15 +134,15 @@ public class GameHistoryRequestHandler extends LotroServerRequestHandler impleme
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (GameHistoryEntry gameHistoryEntry : playerGameHistory) {
String winnerLink = "http://www.gempukku.com/gemp-lotr/game.html?replayId=" + gameHistoryEntry.getWinner() + "$" + gameHistoryEntry.getWinnerRecording();
String loserLink = "http://www.gempukku.com/gemp-lotr/game.html?replayId=" + gameHistoryEntry.getLoser() + "$" + gameHistoryEntry.getLoserRecording();
String winnerLink = "http://www.gempukku.com/gemp-lotr/game.html?replayId=" + gameHistoryEntry.winner + "$" + gameHistoryEntry.win_recording_id;
String loserLink = "http://www.gempukku.com/gemp-lotr/game.html?replayId=" + gameHistoryEntry.loser + "$" + gameHistoryEntry.lose_recording_id;
sb.append("<tr>");
sb.append("<td rowspan='2'>" + dateFormat.format(new Date(gameHistoryEntry.getStartTime().getTime())) + "</td><td rowspan='2'>" + dateFormat.format(new Date(gameHistoryEntry.getEndTime().getTime())) + "</td>");
sb.append("<td>" + gameHistoryEntry.getWinner() + "</td><td>" + gameHistoryEntry.getWinReason() + "</td><td>" + gameHistoryEntry.getWinnerDeckName() + "</td><td><a target='_blank' href='" + winnerLink + "'>Replay</a></td>");
sb.append("<td rowspan='2'>" + dateFormat.format(new Date(gameHistoryEntry.GetStartDate().getTime())) + "</td><td rowspan='2'>" + dateFormat.format(new Date(gameHistoryEntry.GetEndDate().getTime())) + "</td>");
sb.append("<td>" + gameHistoryEntry.winner + "</td><td>" + gameHistoryEntry.win_reason + "</td><td>" + gameHistoryEntry.winner_deck_name + "</td><td><a target='_blank' href='" + winnerLink + "'>Replay</a></td>");
sb.append("</tr>");
sb.append("<tr>");
sb.append("<td>" + gameHistoryEntry.getLoser() + "</td><td>" + gameHistoryEntry.getLoseReason() + "</td><td>" + gameHistoryEntry.getLoserDeckName() + "</td><td><a target='_blank' href='" + loserLink + "'>Replay</a></td>");
sb.append("<td>" + gameHistoryEntry.loser + "</td><td>" + gameHistoryEntry.lose_reason + "</td><td>" + gameHistoryEntry.lose_reason + "</td><td><a target='_blank' href='" + loserLink + "'>Replay</a></td>");
sb.append("</tr>");
}

View File

@@ -9,11 +9,9 @@ import com.gempukku.lotro.common.ApplicationConfiguration;
import com.gempukku.lotro.db.LeagueDAO;
import com.gempukku.lotro.db.PlayerDAO;
import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.db.vo.GameHistoryEntry;
import com.gempukku.lotro.draft2.SoloDraftDefinitions;
import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.CardSets;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
import com.gempukku.lotro.game.Player;
import com.gempukku.lotro.game.*;
import com.gempukku.lotro.game.formats.LotroFormatLibrary;
import com.gempukku.lotro.hall.HallServer;
import com.gempukku.lotro.league.*;
@@ -25,6 +23,7 @@ import io.netty.handler.codec.http.QueryStringDecoder;
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.google.gson.Gson;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -35,11 +34,13 @@ import java.util.*;
public class PlaytestRequestHandler extends LotroServerRequestHandler implements UriRequestHandler {
private PlayerDAO _playerDAO;
private GameHistoryService _gameHistoryService;
private Gson JsonConvert = new Gson();
public PlaytestRequestHandler(Map<Type, Object> context) {
super(context);
_playerDAO = extractObject(context, PlayerDAO.class);
_gameHistoryService = extractObject(context, GameHistoryService.class);
}
@Override
@@ -50,6 +51,8 @@ public class PlaytestRequestHandler extends LotroServerRequestHandler implements
removeTesterFlag(request, responseWriter);
} else if (uri.equals("/getTesterFlag") && request.getMethod() == HttpMethod.GET) {
getTesterFlag(request, responseWriter);
} else if (uri.equals("/getRecentReplays") && request.getMethod() == HttpMethod.POST) {
getRecentReplays(request, responseWriter);
} else {
throw new HttpProcessingException(404);
}
@@ -102,4 +105,20 @@ public class PlaytestRequestHandler extends LotroServerRequestHandler implements
}
}
private void getRecentReplays(HttpRequest request, ResponseWriter responseWriter) throws Exception {
HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request);
try {
String format = getFormParameterSafely(postDecoder, "format");
int count = Integer.parseInt(getFormParameterSafely(postDecoder, "count"));
final List<GameHistoryEntry> gameHistory = _gameHistoryService.getGameHistoryForFormat(format, count);
responseWriter.writeJsonResponse(JsonConvert.toJson(gameHistory));
} finally {
postDecoder.destroy();
}
}
}

View File

@@ -42,6 +42,8 @@
<script type="text/javascript" src="js/gemp-022/gameUi.js"></script>
<script type="text/javascript" src="js/gemp-022/gameAnimations.js"></script>
<script type="text/javascript" src="js/gemp-022/merchantUi.js"></script>
<script type="text/javascript" src="js/lib/json2html/json2html.js"></script>
<audio id="gamestart" src="/gemp-lotr/fanfare_x.mp3" type="audio/mpeg" preload="metadata"></audio>

View File

@@ -12,5 +12,58 @@
<p>If you have any questions or would like to discuss our card design decisions in-depth, then feel free to join us <a href="https://lotrtcgpc.net/discord">on the PC Discord server</a>.</p>
<br>
Last 100 Playtest Replays:
<div id="replays">
<table id="tblReplays" class="gameHistory">
<thead>
<tr>
<th>Format</th>
<th>Winner</th>
<th>Loser</th>
<th>Win Reason</th>
<th>Loss Reason</th>
<th>Winner Replay</th>
<th>Loser Replay</th>
<th>Started</th>
<th>Ended</th>
</tr>
</thead>
</table>
</div>
</div>
<script>
function drawTable(json) {
const template = {"<>":"tr","html": [
{"<>":"td","html":"${format_name}"},
{"<>":"td","html":"${winner}"},
{"<>":"td","html":"${loser}"},
{"<>":"td","html":"${win_reason}"},
{"<>":"td","html":"${lose_reason}"},
{"<>":"td","html":function() {
return "<a href=\"" + window.location.origin + "/gemp-lotr/game.html?replayId=" + this.winner + "$" + this.win_recording_id + "\">Replay link</a>";
}},
{"<>":"td","html":function() {
return "<a href=\"" + window.location.origin + "/gemp-lotr/game.html?replayId=" + this.loser + "$" + this.lose_recording_id + "\">Replay link</a>";
}},
{"<>":"td","html":function() { return new Date(this.start_date).toLocaleString('sv'); }},
{"<>":"td","html":function() { return new Date(this.end_date).toLocaleString('sv'); }},
]};
$("#tblReplays").json2html(json,template);
}
hall.comm.getRecentReplays("PLAYTEST", 100, function(json){drawTable(json);}, hall.hallErrorMap());
drawTable();
</script>

View File

@@ -642,6 +642,21 @@ var GempLotrCommunication = Class.extend({
});
},
getRecentReplays:function (format, count, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/playtesting/getRecentReplays",
cache:false,
data:{
format:format,
count:count
},
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
dataType:"json"
});
},
getStatus:function (callback, errorMap) {
$.ajax({
type:"GET",

View File

@@ -0,0 +1,23 @@
The MIT License
Copyright (c) 2021 JSON2HTML. https://json2html.com/
=======
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,79 @@
json2html
------------------
json2html is an open source javascript library that uses js templates to render JSON objects into HTML.
Build lightning fast, interactive client side templates using nothing but javascript.
Free to use under the MIT license.
<a href='http://www.json2html.com'>www.json2html.com</a> for full documentation.
Features
--------------
+ Native JS templates that can be read within the browser or node.js and don't require compilation
+ One template for both the client and server
+ Interactive with embedded events directly in your templates
+ 100% Javascript so no need to learn any new syntax, use inline js functions for complex logic
Example
--------------
```javascript
json2html.render(
[
{"name": "Justice League", "year":2021},
{"name": "Coming 2 America", "year":2021}
],
{"<>": "li", "html":[
{"<>": "span", "text": "${name} (${year})"}
]});
```
Will render the following html
```html
<li>
<span>Justice League (2021)</span>
</li>
<li>
<span>Coming 2 America (2021)</span>
</li
```
jQuery
=========
Use seemlessly with jQuery, oh did we also mention that you can embed events in your template? Forget attaching your events after you've rendered your templates.
```javascript
{"<>":"button","text":"Click Me","onclick":funciton(e){
alert("You just clicked this");
}};
```
Will render into the following html and will alert when clicked :)
```html
<button>Click Me</button>
```
Node.js
=========
Use your temlpates seemlessly on Node.js (sorry no events here)
Installation
------------
npm install node-json2html
Usage
-----
```javascript
const json2html = require('node-json2html');
let html = json2html.transform([{'male':'Bob','female':'Jane'},{'male':'Rick','female':'Ann'}],{"<>":"div","html":"${male} likes ${female}"});
```
<a href='http://www.json2html.com'>www.json2html.com</a> for full documentation.

File diff suppressed because it is too large Load Diff

View File

@@ -73,5 +73,15 @@
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.sql2o</groupId>
<artifactId>sql2o</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>
</project>

View File

@@ -2,6 +2,7 @@ package com.gempukku.lotro.db;
import com.gempukku.lotro.db.vo.GameHistoryEntry;
import com.gempukku.lotro.game.Player;
import org.sql2o.Sql2o;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -42,38 +43,47 @@ public class DbGameHistoryDAO implements GameHistoryDAO {
}
public List<GameHistoryEntry> getGameHistoryForPlayer(Player player, int start, int count) {
try {
try (Connection connection = _dbAccess.getDataSource().getConnection()) {
try (PreparedStatement statement = connection.prepareStatement("select winner, loser, win_reason, lose_reason, win_recording_id, lose_recording_id, format_name, tournament, winner_deck_name, loser_deck_name, start_date, end_date from game_history where winner=? or loser=? order by end_date desc limit ?, ?")) {
statement.setString(1, player.getName());
statement.setString(2, player.getName());
statement.setInt(3, start);
statement.setInt(4, count);
try (ResultSet rs = statement.executeQuery()) {
List<GameHistoryEntry> result = new LinkedList<GameHistoryEntry>();
while (rs.next()) {
String winner = rs.getString(1);
String loser = rs.getString(2);
String winReason = rs.getString(3);
String loseReason = rs.getString(4);
String winRecordingId = rs.getString(5);
String loseRecordingId = rs.getString(6);
String formatName = rs.getString(7);
String tournament = rs.getString(8);
String winnerDeckName = rs.getString(9);
String loserDeckName = rs.getString(10);
Date startDate = new Date(rs.getLong(11));
Date endDate = new Date(rs.getLong(12));
GameHistoryEntry entry = new GameHistoryEntry(winner, winReason, winRecordingId, loser, loseReason, loseRecordingId, formatName, tournament, winnerDeckName, loserDeckName, startDate, endDate);
result.add(entry);
}
return result;
}
}
try {
Sql2o db = new Sql2o(_dbAccess.getDataSource());
try (org.sql2o.Connection conn = db.open()) {
String sql = "select winner, loser, win_reason, lose_reason, win_recording_id, lose_recording_id, format_name, tournament, winner_deck_name, loser_deck_name, start_date, end_date from game_history where winner=:playerName or loser=:playerName order by end_date desc limit :start, :count";
List<GameHistoryEntry> result = conn.createQuery(sql)
.addParameter("playerName", player.getName())
.addParameter("start", start)
.addParameter("count", count)
.executeAndFetch(GameHistoryEntry.class);
return result;
}
} catch (SQLException exp) {
throw new RuntimeException("Unable to get count of player games", exp);
} catch (Exception ex) {
throw new RuntimeException("Unable to retrieve game history for player", ex);
}
}
@Override
public List<GameHistoryEntry> getGameHistoryForFormat(String format, int count) {
try {
Sql2o db = new Sql2o(_dbAccess.getDataSource());
try (org.sql2o.Connection conn = db.open()) {
String sql = "SELECT winner, loser, win_reason, lose_reason, win_recording_id, lose_recording_id, format_name, tournament, winner_deck_name, loser_deck_name, start_date, end_date " +
" FROM game_history " +
" WHERE format_name LIKE :format" +
" ORDER BY end_date DESC LIMIT :count";
List<GameHistoryEntry> result = conn.createQuery(sql)
.addParameter("format", "%" + format + "%")
.addParameter("count", count)
.executeAndFetch(GameHistoryEntry.class);
return result;
}
} catch (Exception ex) {
throw new RuntimeException("Unable to retrieve game history by format", ex);
}
}
@@ -182,39 +192,24 @@ public class DbGameHistoryDAO implements GameHistoryDAO {
@Override
public List<GameHistoryEntry> getLastGames(String requestedFormatName, int count) {
try {
try (Connection connection = _dbAccess.getDataSource().getConnection()) {
try (PreparedStatement statement = connection.prepareStatement(
"select winner, loser, win_reason, lose_reason, win_recording_id, lose_recording_id, format_name, " +
"tournament, winner_deck_name, loser_deck_name, start_date, end_date from game_history " +
"where format_name=? order by end_date desc limit ?")) {
statement.setString(1, requestedFormatName);
statement.setInt(2, count);
try (ResultSet rs = statement.executeQuery()) {
List<GameHistoryEntry> result = new LinkedList<GameHistoryEntry>();
while (rs.next()) {
String winner = rs.getString(1);
String loser = rs.getString(2);
String winReason = rs.getString(3);
String loseReason = rs.getString(4);
String winRecordingId = rs.getString(5);
String loseRecordingId = rs.getString(6);
String formatName = rs.getString(7);
String tournament = rs.getString(8);
String winnerDeckName = rs.getString(9);
String loserDeckName = rs.getString(10);
Date startDate = new Date(rs.getLong(11));
Date endDate = new Date(rs.getLong(12));
GameHistoryEntry entry = new GameHistoryEntry(winner, winReason, winRecordingId, loser, loseReason, loseRecordingId, formatName, tournament, winnerDeckName, loserDeckName, startDate, endDate);
result.add(entry);
}
return result;
}
}
try {
Sql2o db = new Sql2o(_dbAccess.getDataSource());
try (org.sql2o.Connection conn = db.open()) {
String sql = "select winner, loser, win_reason, lose_reason, win_recording_id, lose_recording_id, format_name, " +
"tournament, winner_deck_name, loser_deck_name, start_date, end_date from game_history " +
"where format_name=:formatName order by end_date desc limit :count";
List<GameHistoryEntry> result = conn.createQuery(sql)
.addParameter("formatName", requestedFormatName)
.addParameter("count", count)
.executeAndFetch(GameHistoryEntry.class);
return result;
}
} catch (SQLException exp) {
throw new RuntimeException("Unable to get list of games", exp);
} catch (Exception ex) {
throw new RuntimeException("Unable to retrieve last games", ex);
}
}

View File

@@ -14,6 +14,8 @@ public interface GameHistoryDAO {
public int getGameHistoryForPlayerCount(Player player);
public List<GameHistoryEntry> getGameHistoryForFormat(String format, int count);
public int getActivePlayersCount(long from, long duration);
public int getGamesPlayedCount(long from, long duration);

View File

@@ -3,83 +3,38 @@ package com.gempukku.lotro.db.vo;
import java.util.Date;
public class GameHistoryEntry {
private String _winner;
private String _loser;
private String _winReason;
private String _loseReason;
public int id;
private String _winnerRecording;
private String _loserRecording;
public String winner;
public String loser;
private String _formatName;
private String _tournament;
private String _winnerDeckName;
private String _loserDeckName;
public String win_reason;
public String lose_reason;
private Date _startTime;
private Date _endTime;
public String win_recording_id;
public String lose_recording_id;
public GameHistoryEntry(String winner, String winReason, String winnerRecording, String loser, String loseReason, String loserRecording, String formatName, String tournament, String winnerDeckName, String loserDeckName, Date startTime, Date endTime) {
_winner = winner;
_winReason = winReason;
_winnerRecording = winnerRecording;
_loser = loser;
_loseReason = loseReason;
_loserRecording = loserRecording;
_formatName = formatName;
_tournament = tournament;
_winnerDeckName = winnerDeckName;
_loserDeckName = loserDeckName;
_startTime = startTime;
_endTime = endTime;
public long start_date;
public long end_date;
public String format_name;
public String winner_deck_name;
public String loser_deck_name;
public String tournament;
public Date GetStartDate()
{
return new Date(start_date);
}
public String getLoser() {
return _loser;
public Date GetEndDate()
{
return new Date(end_date);
}
public String getLoseReason() {
return _loseReason;
}
public String getLoserRecording() {
return _loserRecording;
}
public String getWinner() {
return _winner;
}
public String getWinnerRecording() {
return _winnerRecording;
}
public String getWinReason() {
return _winReason;
}
public String getFormatName() {
return _formatName;
}
public String getTournament() {
return _tournament;
}
public String getWinnerDeckName() {
return _winnerDeckName;
}
public String getLoserDeckName() {
return _loserDeckName;
}
public Date getEndTime() {
return _endTime;
}
public Date getStartTime() {
return _startTime;
}
}

View File

@@ -40,6 +40,10 @@ public class GameHistoryService {
return _gameHistoryDAO.getGameHistoryForPlayer(player, start, count);
}
public List<GameHistoryEntry> getGameHistoryForFormat(String format, int count) {
return _gameHistoryDAO.getGameHistoryForFormat(format, count);
}
public List<GameHistoryEntry> getTrackableGames(int count) {
return _gameHistoryDAO.getLastGames("Second Edition", count);
}