Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f296930
Update the timer task setup.
zpChris Jun 18, 2021
a2164a3
Add createGameReport method and update corresponding data models.
zpChris Jun 19, 2021
bbc04bd
Resolve merge conflicts with ResultSetup and main.
zpChris Jun 22, 2021
5282463
Add TODO and helper methods.
zpChris Jun 25, 2021
e25a919
Merge branch 'main' of https://github.com/rocketden/main into Generat…
zpChris Jun 25, 2021
8c0ab51
Merge with multi-problem UI.
zpChris Jun 29, 2021
ddc34c1
Add logic to set data in submission report.
zpChris Jun 29, 2021
54d81fe
Add problem container variable and remaining game report statistics.
zpChris Jun 29, 2021
7f5d22a
Delay before creating the game report.
zpChris Jun 29, 2021
5530121
Add game report repository and save the object in the database.
zpChris Jun 29, 2021
913cf38
Update the saving functionality for users and accounts.
zpChris Jun 29, 2021
15aa1ed
Update column definitions to text.
zpChris Jun 30, 2021
cc3a0d4
Move utility tasks to the task folder.
zpChris Jun 30, 2021
56a73ec
Add the timer task for creating a game report.
zpChris Jun 30, 2021
0fbd919
Fix average test cases passed and total number of test cases.
zpChris Jun 30, 2021
ed5c3da
Remove old logs.
zpChris Jun 30, 2021
18e1f1c
Merge branch 'main' of https://github.com/rocketden/main into Generat…
zpChris Jul 3, 2021
0311bec
Merge branch 'main' of https://github.com/rocketden/main into Generat…
zpChris Jul 3, 2021
22eff98
Add file for creating game report.
zpChris Jul 4, 2021
56c580a
Add mockito annotations calls to fix methods, remove unnecessary checks.
zpChris Jul 4, 2021
0ae5741
Remove unnecessary tests and add check for create game report.
zpChris Jul 4, 2021
ee95904
Update the game management service tests.
zpChris Jul 5, 2021
54795e5
Remove unused variables.
zpChris Jul 5, 2021
3433138
Add verification of the relevant game report objects.
zpChris Jul 6, 2021
9dcabee
Update the submission helper to have only one test case.
zpChris Jul 6, 2021
4325c79
Add the overall problems solved and test cases passed statistics.
zpChris Jul 6, 2021
71f715c
Add a second incorrect attempt that factors only into attempt count.
zpChris Jul 6, 2021
f43d8ce
Add final test statistics and add explanatory top-level comment.
zpChris Jul 6, 2021
b22927e
Add the create two game reports test.
zpChris Jul 6, 2021
832341a
Add final test for game end type.
zpChris Jul 6, 2021
ed98efb
Remove unnecessary user repository save.
zpChris Jul 6, 2021
6cf7dd8
Add problem service delete method.
zpChris Jul 7, 2021
bd62778
Remove extraneous comment.
zpChris Jul 8, 2021
c972883
Resolve merge conflicts with main.
zpChris Jul 21, 2021
da88286
Create the new ReportService as well as modified the other correspond…
zpChris Jul 21, 2021
dabe142
Add problem repository to the report service to take care of deleted …
zpChris Jul 21, 2021
8ad55e7
Update submit service functionality to prevent submissions from occur…
zpChris Jul 26, 2021
7f52b25
Remove CreateGameReportTask class and call createGameReport directly.
zpChris Jul 28, 2021
056dd07
Fix reportService tests.
zpChris Jul 28, 2021
f3dc868
Update the removeProblem test API.
zpChris Jul 28, 2021
fe0bd95
Attempt initial implementation of createGameReportStarted.
zpChris Jul 28, 2021
72dd0a6
Test problem deletion in the ReportServiceTests class.
zpChris Aug 1, 2021
87d39b1
Split problem container and account additions to separate methods.
zpChris Aug 2, 2021
c743cfa
Further split up the createGameReport method into different methods.
zpChris Aug 2, 2021
2705ac5
Remove blank lines in createGameReport method.
zpChris Aug 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/com/codejoust/main/dao/GameReportRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.codejoust.main.dao;

import com.codejoust.main.model.report.GameReport;

import org.springframework.data.repository.CrudRepository;

public interface GameReportRepository extends CrudRepository<GameReport, Integer> {

GameReport findGameReportByGameReportId(String gameReportId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codejoust.main.dao;

import org.springframework.data.repository.CrudRepository;

import java.util.List;

import com.codejoust.main.model.problem.Problem;
import com.codejoust.main.model.problem.ProblemContainer;

// This will be AUTO IMPLEMENTED by Spring into a Bean called
// problemContainerRepository; CRUD refers Create, Read, Update, Delete
public interface ProblemContainerRepository extends CrudRepository<ProblemContainer, Integer> {
List<ProblemContainer> findAllByProblem(Problem problem);
}
4 changes: 4 additions & 0 deletions src/main/java/com/codejoust/main/dao/RoomRepository.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.codejoust.main.dao;

import java.util.List;

import com.codejoust.main.model.Room;

import org.springframework.data.repository.CrudRepository;
Expand All @@ -8,4 +10,6 @@ public interface RoomRepository extends CrudRepository<Room, Integer> {

// Auto generated by CrudRepository
Room findRoomByRoomId(String roomId);

List<Room> findByProblems_ProblemId(String problemId);
}
18 changes: 18 additions & 0 deletions src/main/java/com/codejoust/main/dto/game/SubmissionMapper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.codejoust.main.dto.game;

import com.codejoust.main.dto.problem.ProblemTestCaseDto;
import com.codejoust.main.game_object.PlayerCode;
import com.codejoust.main.game_object.Submission;
import com.codejoust.main.game_object.SubmissionResult;
import com.codejoust.main.model.report.CodeLanguage;
import com.codejoust.main.model.report.SubmissionReport;

import org.modelmapper.ModelMapper;

Expand Down Expand Up @@ -29,4 +33,18 @@ public static SubmissionResult toSubmissionResult(TesterResult testerResult, Pro
submissionResult.setInput(testCaseDto.getInput());
return submissionResult;
}

public static SubmissionReport toSubmissionReport(Submission submission) {
if (submission == null) {
return null;
}

SubmissionReport submissionReport = mapper.map(submission, SubmissionReport.class);

// Get and set the player code for this submission.
PlayerCode playerCode = submission.getPlayerCode();
submissionReport.setCode(playerCode.getCode());
submissionReport.setLanguage(CodeLanguage.fromString(submission.getPlayerCode().getLanguage().name()));
return submissionReport;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/codejoust/main/exception/TimerError.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public enum TimerError implements ApiError {

INVALID_DURATION(HttpStatus.BAD_REQUEST, "Please enter a valid duration between 1-60 minutes."),
NULL_SETTING(HttpStatus.BAD_REQUEST, "The game, associated game timer, room, room ID, and socket service must not be null.");
NULL_SETTING(HttpStatus.BAD_REQUEST, "The relevant game settings must not be null.");

private final HttpStatus status;
private final ApiErrorResponse response;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/codejoust/main/game_object/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ public class Game {

// Boolean to hold whether the host ended the game early
private Boolean gameEnded = false;

// Boolean to hold whether the process of creating the game report started
private Boolean createGameReportStarted = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class Submission {

private PlayerCode playerCode;

private int problemIndex;

private List<SubmissionResult> results;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/codejoust/main/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ public class Account {
private List<ProblemTag> problemTags = new ArrayList<>();

// List of tags associated with this problem
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}, fetch = FetchType.EAGER)
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@Setter(AccessLevel.PRIVATE)
@JoinColumn(name = "game_report_id")
@Fetch(value = FetchMode.SUBSELECT)
private List<GameReport> gameReports = new ArrayList<>();

@Enumerated(EnumType.STRING)
private AccountRole role = AccountRole.TEACHER;

public void addGameReport(GameReport gameReport) {
gameReports.add(0, gameReport);
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/codejoust/main/model/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,12 @@ public boolean isFull() {

return users.size() >= size;
}

public boolean addProblem(Problem problem) {
return problems.add(problem);
}

public boolean removeProblem(Problem problem) {
return problems.remove(problem);
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/codejoust/main/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -58,9 +59,13 @@ public class User {
private Room room;

// Thie list holds the submission group associated with the current room
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@Setter(AccessLevel.PRIVATE)
@Fetch(value = FetchMode.SUBSELECT)
@JoinColumn(name = "submission_group_reports_table_id")
private List<SubmissionGroupReport> submissionGroupReports = new ArrayList<>();

public void addSubmissionGroupReport(SubmissionGroupReport submissionGroupReport) {
submissionGroupReports.add(submissionGroupReport);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double-check, this isn't included in the UserDto right? Since it's only used for the report related stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right - this is not included in the standard UserDto class, nor will I add it there. I don't yet have a GameReportDto class as I've been working in the backend thus far, but I will add that at some point - I'll make another DTO class for the User object specifically for the report purposes, so it is only passed to the frontend when necessary.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
Expand All @@ -24,9 +25,11 @@ public class ProblemTestCase {
private Integer id;

@EqualsAndHashCode.Include
@Column(columnDefinition = "TEXT")
private String input;

@EqualsAndHashCode.Include
@Column(columnDefinition = "TEXT")
private String output;

@EqualsAndHashCode.Include
Expand All @@ -37,5 +40,6 @@ public class ProblemTestCase {
private Problem problem;

@EqualsAndHashCode.Include
@Column(columnDefinition = "TEXT")
private String explanation;
}
22 changes: 19 additions & 3 deletions src/main/java/com/codejoust/main/model/report/GameReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,26 @@ public class GameReport {
@EqualsAndHashCode.Include
private String gameReportId = UUID.randomUUID().toString();

@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@Setter(AccessLevel.PRIVATE)
@Fetch(value = FetchMode.SUBSELECT)
@JoinColumn(name = "problem_containers_table_id")
private List<ProblemContainer> problemContainers = new ArrayList<>();

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}, fetch = FetchType.EAGER)
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@Setter(AccessLevel.PRIVATE)
@JoinColumn(name = "users_table_id")
@Fetch(value = FetchMode.SUBSELECT)
@JoinColumn(name = "users_table_id")
private List<User> users = new ArrayList<>();

private int numTestCases;

// The average (mean) number of test cases passed.
private Double averageTestCasesPassed;

// The average (mean) number of problems solved.
private Double averageProblemsSolved;

// The start time of the game
private Instant createdDateTime;

Expand All @@ -59,4 +67,12 @@ public class GameReport {

// How the game ended.
private GameEndType gameEndType;

public void addProblemContainer(ProblemContainer problemContainer) {
problemContainers.add(problemContainer);
}

public void addUser(User user) {
users.add(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -31,9 +32,22 @@ public class SubmissionGroupReport {

private String gameReportId;

@OneToMany(fetch = FetchType.EAGER)
/**
* String to represent problems solved.
* Each index represents the problem index.
* 0 = Not Solved, 1 = Solved.
*/
private String problemsSolved;

private Integer numTestCasesPassed;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@Setter(AccessLevel.PRIVATE)
@Fetch(value = FetchMode.SUBSELECT)
@JoinColumn(name = "submission_reports_table_id")
private List<SubmissionReport> submissionReports = new ArrayList<>();

public void addSubmissionReport(SubmissionReport submissionReport) {
submissionReports.add(submissionReport);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.Instant;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand All @@ -21,10 +22,13 @@ public class SubmissionReport {
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

@Column(columnDefinition = "TEXT")
private String code;

private CodeLanguage language;

private int problemIndex;

// The time that the submission was received.
private Instant startTime;

Expand Down
26 changes: 15 additions & 11 deletions src/main/java/com/codejoust/main/service/GameManagementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.codejoust.main.model.Room;
import com.codejoust.main.model.User;
import com.codejoust.main.model.problem.Problem;
import com.codejoust.main.util.EndGameTimerTask;
import com.codejoust.main.task.EndGameTimerTask;
import com.codejoust.main.util.Utility;

import lombok.extern.log4j.Log4j2;
Expand All @@ -45,18 +45,24 @@ public class GameManagementService {
private final NotificationService notificationService;
private final SubmitService submitService;
private final ProblemService problemService;
private final ReportService reportService;
private final Map<String, Game> currentGameMap;

@Autowired
protected GameManagementService(RoomRepository repository, SocketService socketService,
LiveGameService liveGameService, NotificationService notificationService,
SubmitService submitService, ProblemService problemService) {
protected GameManagementService(RoomRepository repository,
SocketService socketService,
LiveGameService liveGameService,
NotificationService notificationService,
SubmitService submitService,
ProblemService problemService,
ReportService reportService) {
this.repository = repository;
this.socketService = socketService;
this.liveGameService = liveGameService;
this.notificationService = notificationService;
this.submitService = submitService;
this.problemService = problemService;
this.reportService = reportService;
currentGameMap = new HashMap<>();
}

Expand Down Expand Up @@ -106,7 +112,7 @@ public RoomDto startGame(String roomId, StartGameRequest request) {
public RoomDto playAgain(String roomId, PlayAgainRequest request) {
Game game = getGameFromRoomId(roomId);

if (!isGameOver(game)) {
if (!Utility.isGameOver(game)) {
throw new ApiException(GameError.GAME_NOT_OVER);
}

Expand Down Expand Up @@ -166,7 +172,7 @@ public void setStartGameTimer(Game game, Long duration) {
game.setGameTimer(gameTimer);

// Schedule the game to end after <duration> seconds.
EndGameTimerTask endGameTimerTask = new EndGameTimerTask(socketService, game);
EndGameTimerTask endGameTimerTask = new EndGameTimerTask(this, socketService, game);
gameTimer.getTimer().schedule(endGameTimerTask, duration * 1000);
}

Expand Down Expand Up @@ -209,7 +215,7 @@ public SubmissionDto submitSolution(String roomId, SubmissionRequest request) {

SubmissionDto submissionDto = submitService.submitSolution(game, request);

if (isGameOver(game)) {
if (Utility.isGameOver(game)) {
handleEndGame(game);
}

Expand Down Expand Up @@ -283,18 +289,16 @@ public GameDto manuallyEndGame(String roomId, EndGameRequest request) {
return gameDto;
}

protected void handleEndGame(Game game) {
public void handleEndGame(Game game) {
// Cancel all previously scheduled timers
GameTimer gameTimer = game.getGameTimer();
gameTimer.getTimer().cancel();

for (Timer timer : gameTimer.getNotificationTimers()) {
timer.cancel();
}
}

protected boolean isGameOver(Game game) {
return game.getGameEnded() || game.getAllSolved() || (game.getGameTimer() != null && game.getGameTimer().isTimeUp());
reportService.createGameReport(game);
}

// Update people's socket active status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.codejoust.main.dto.game.GameNotificationDto;
import com.codejoust.main.game_object.Game;
import com.codejoust.main.game_object.GameTimer;
import com.codejoust.main.util.NotificationTimerTask;
import com.codejoust.main.task.NotificationTimerTask;

import org.springframework.stereotype.Service;

Expand Down
Loading