Skip to content

Commit

Permalink
Merge pull request #41 from isa-group/feature/#35-Random-Exercises
Browse files Browse the repository at this point in the history
Feature/#35 random exercises
  • Loading branch information
davbrican authored Nov 17, 2021
2 parents fc8e7e9 + fa5b93d commit 5ca0a43
Showing 1 changed file with 66 additions and 26 deletions.
92 changes: 66 additions & 26 deletions consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,41 +192,71 @@ async function executeSession(sessionName, io) {

var exercise = listExercises[num2Send];

if (exercise.type == "PAIR" || participant1.nextExercise) {
io.to(participant1.socketId).emit("newExercise", {
data: {
maxTime: exercise.time,
exerciseDescription: exercise.description,
exerciseType: exercise.type,
inputs: exercise.inputs,
solutions: exercise.solutions,
testLanguage: testLanguage,
}
});
if ((exercise.type == "PAIR" && participant1.visitedPExercises.length < listExercises.length) || (exercise.type == "INDIVIDUAL" && participant1.visitedIExercises.length < listExercises.length)) {
if (exercise.type == "PAIR" || participant1.nextExercise) {
io.to(participant1.socketId).emit("newExercise", {
data: {
maxTime: tests[testNumber].testTime,
exerciseDescription: exercise.description,
exerciseType: exercise.type,
inputs: exercise.inputs,
solutions: exercise.solutions,
testLanguage: testLanguage,
}
});

io.to(participant1.socketId).emit("customAlert", {
data: {
message: "New exercise beggins"
}
});
}
}
if (exercise.type == "PAIR" || participant2.nextExercise) {
io.to(participant2.socketId).emit("newExercise", {
if ((exercise.type == "PAIR" && participant2.visitedPExercises.length < listExercises.length) || (exercise.type == "INDIVIDUAL" && participant2.visitedIExercises.length < listExercises.length)) {
if (exercise.type == "PAIR" || participant2.nextExercise) {
io.to(participant2.socketId).emit("newExercise", {
data: {
maxTime: tests[testNumber].testTime,
exerciseDescription: exercise.description,
exerciseType: exercise.type,
inputs: exercise.inputs,
solutions: exercise.solutions,
testLanguage: testLanguage,
}
});

io.to(participant2.socketId).emit("customAlert", {
data: {
message: "New exercise beggins"
}
});
}
}
/*
else {
io.to(participant1.socketId).emit("customAlert", {
data: {
maxTime: exercise.time,
exerciseDescription: exercise.description,
exerciseType: exercise.type,
inputs: exercise.inputs,
solutions: exercise.solutions,
testLanguage: testLanguage,
message: "There are no more exercises left"
}
});
}
*/


if (listExercises[num2Send].type == "PAIR") {
participant1.visitedPExercises.push(num2Send);
participant1.save();
participant2.visitedPExercises.push(num2Send);
participant2.save();
} else {
participant1.visitedIExercises.push(num2Send);
participant1.save();
participant2.visitedIExercises.push(num2Send);
participant2.save();
if (participant1.nextExercise) {
participant1.visitedIExercises.push(num2Send);
participant1.save();
}
if (participant2.nextExercise) {
participant2.visitedIExercises.push(num2Send);
participant2.save();
}
}
}
p++;
Expand Down Expand Up @@ -280,7 +310,6 @@ async function executeSession(sessionName, io) {
lastSessionEvent.set(sessionName, event);
Logger.dbg("executeSession - lastSessionEvent saved", event[0]);


timer = tests[testNumber].time; //Resets the timer
session.exerciseCounter = 0;
Logger.dbg("executeSession - testCounter: " + session.testCounter + " of " + numTests + " , exerciseCounter: " + session.exerciseCounter + " of " + maxExercises);
Expand All @@ -307,7 +336,7 @@ async function executeSession(sessionName, io) {

io.to(participant1.socketId).emit("newExercise", {
data: {
maxTime: exercise.time,
maxTime: tests[testNumber].testTime,
exerciseDescription: exercise.description,
exerciseType: exercise.type,
inputs: exercise.inputs,
Expand All @@ -317,14 +346,25 @@ async function executeSession(sessionName, io) {
});
io.to(participant2.socketId).emit("newExercise", {
data: {
maxTime: exercise.time,
maxTime: tests[testNumber].testTime,
exerciseDescription: exercise.description,
exerciseType: exercise.type,
inputs: exercise.inputs,
solutions: exercise.solutions,
testLanguage: testLanguage,
}
});

io.to(participant1.socketId).emit("customAlert", {
data: {
message: "New exercise beggins"
}
});
io.to(participant2.socketId).emit("customAlert", {
data: {
message: "New exercise beggins"
}
});


if (exercise.type == "PAIR") {
Expand Down

0 comments on commit 5ca0a43

Please sign in to comment.