Skip to content

Commit

Permalink
[RazortoothRTC#39] number of questions change color if not O, score f…
Browse files Browse the repository at this point in the history
…or each students operational, best score in gold
  • Loading branch information
chrqls committed Jun 13, 2014
1 parent 0d083af commit 909af60
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 26 deletions.
4 changes: 3 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ exports.handleSendShowResultsPut = function(req, res) {
});
}
game.setCurrentMessage(message);
return res.sendText(HTTP_STATUS_OK, OK);

// We return all the messages to calculate the results
return res.sendJSON(HTTP_STATUS_OK, game.messages.past);
};

exports.handleCurrentSessionDataGet = function(req, res) {
Expand Down
104 changes: 92 additions & 12 deletions static/js/smileteacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/

var VERSION = '0.8.3';
var VERSION = '0.8.4';

// Interval of time used to update the GlobalViewModel
var DELAY_UPDATE_BOARD = 5000;
Expand Down Expand Up @@ -195,6 +195,7 @@ GlobalViewModel.redirectView = function() {
case 'START_SHOW':
$('.see_results').addClass('hidden');
$('.retake').removeClass('hidden');
calculateAndShowResults(dataAll);
break;

case 'QUESTION':
Expand All @@ -204,7 +205,6 @@ GlobalViewModel.redirectView = function() {
addStudent(dataAll[i]); break;
case 'ANSWER':
questionsAnsweredByStudent(dataAll[i].IP); break;
default: break;
}
}
switchSection(section);
Expand Down Expand Up @@ -490,6 +490,10 @@ GlobalViewModel.removeQuestionFromSession = function() {

var amount = $(this).find('td[smile=number_of_questions] span');
amount.text(parseInt(amount.text())-1);
if(amount.text() === '0') {
amount.removeClass('sticker_positive');
amount.addClass('sticker_null');
}
}
});
}
Expand Down Expand Up @@ -562,7 +566,7 @@ GlobalViewModel.saveNewIQSet = function() {
"NAME":GlobalViewModel.questions()[i].author,
"Q":GlobalViewModel.questions()[i].question,
"A":GlobalViewModel.questions()[i].answer,
"IP":GlobalViewModel.questions()[i].ip,
"IP":"No IP address",
"O4":GlobalViewModel.questions()[i].options[3],
"O3":GlobalViewModel.questions()[i].options[2],
"O2":GlobalViewModel.questions()[i].options[1],
Expand Down Expand Up @@ -656,6 +660,10 @@ function addQuestion(question) {

var amount = $(this).find('td[smile=number_of_questions] span');
amount.text(parseInt(amount.text())+1);
if(parseInt(amount.text()) > 0) {
amount.removeClass('sticker_null');
amount.addClass('sticker_positive');
}
}
});
}
Expand Down Expand Up @@ -746,8 +754,9 @@ function updateGVM() {
absoluteAlert('New question from <b>'+dataAll[i].NAME+'</b>!',DELAY_NORMAL);
}
break;
case 'ANSWER':
questionsAnsweredByStudent(dataAll[i].IP,true); break;
case 'ANSWER':
questionsAnsweredByStudent(dataAll[i].IP,true);
break;
}
}

Expand Down Expand Up @@ -784,6 +793,76 @@ function updateGVM() {
});
}

function calculateAndShowResults(dataAll) {

// Getting /smile/all
//var dataAll = JSON.parse(smile_all());

// Variables to fill
var students_results = [];
var answers;
var size_Q;
var scores = [];
var best_score = 0;

// Extracting results
for(var i=0; i<dataAll.length; i++) {

switch(dataAll[i].TYPE) {

case 'ANSWER':
var studentResults = {};
studentResults.IP = dataAll[i].IP;
studentResults.MYANSWER = dataAll[i].MYANSWER;

students_results.push(studentResults);
break;

case 'START_SHOW':
answers = dataAll[i].RANSWER;
size_Q = dataAll[i].NUMQ;
break;
}
}

// Getting percents
for(var i=0; i<students_results.length; i++) {

var points = 0;
var score = {};
score.IP = students_results[i].IP;

for(var j=0; j<answers.length; j++) {

if(parseInt(students_results[i].MYANSWER[j]) === answers[j]) {
points++;
}
}
score.SCORE = 100*points/size_Q;
if(score.SCORE > best_score) best_score = score.SCORE;
scores.push(score);
}

// Injecting scores into students table
$('table#students tr').each(function(index) {
for(var i=0; i<scores.length; i++) {
if($(this).find('td[smile=ip_of_student] input[type=hidden]').val() === scores[i].IP) {

var html;

if(scores[i].SCORE === best_score)
html = '<span class="gold_score">';
else html = '<span class="score">';

html += scores[i].SCORE+'<span style="font-size:14px">%</span></span>'

$(this).find('.score_container').html(html);
}
}
});
}

// Very useful to redirect views if a message already exists
function typeExist(type) {

var answer = false;
Expand Down Expand Up @@ -837,7 +916,7 @@ function postMessage(type,values) {
async: false,

error: function(xhr, text, err) {
absoluteAlert('Unable to send START_MAKE phase', DELAY_NORMAL, 'trace');
absoluteAlert('Unable to send START_MAKE phase', DELAY_ERROR, 'trace', true);
},
success: function(data) {}
});
Expand All @@ -855,10 +934,10 @@ function postMessage(type,values) {
//async: false,

error: function(xhr, text, err) {
absoluteAlert('Unable to send START_SOLVE phase', DELAY_NORMAL, 'trace');
absoluteAlert('Unable to send START_SOLVE phase', DELAY_ERROR, 'trace', true);
},
success: function(data) {
absoluteAlert('START_SOLVE sent!', DELAY_NORMAL, 'green');
absoluteAlert('Your students can start answering questions.', DELAY_NORMAL, 'green');
}
});
break;
Expand All @@ -874,10 +953,11 @@ function postMessage(type,values) {
//async: false,

error: function(xhr, text, err) {
absoluteAlert('Unable to send START_SHOW phase', DELAY_NORMAL, 'trace');
absoluteAlert('Unable to send START_SHOW phase', DELAY_ERROR, 'trace', true);
},
success: function(data) {
absoluteAlert('START_SHOW sent!', DELAY_NORMAL, 'green');
success: function(dataAll) {
absoluteAlert('Your students can see the results now!', DELAY_NORMAL, 'green');
calculateAndShowResults(dataAll);
}
});
break;
Expand Down Expand Up @@ -929,7 +1009,7 @@ function postMessage(type,values) {
},
success: function(data) {
absoluteAlert('New iqset <i>"'+data.title+'"</i> saved!',DELAY_NORMAL,'green');
switchVisibilitySaveButton();
hideSaveForm();
}
});
break;
Expand Down
5 changes: 2 additions & 3 deletions static/smile-student.html
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,10 @@ <H3>
<label class="css-label" for="a4">Correct?</label>
</div>
</div>
<P>
<em>Rating:</em>
</P>


<!--
<p><em>Rating:</em></p>
<div id="star-rating">
<input data-bind="checked: rating" type="radio"
name="rating" class="rating" value="1" />
Expand Down
46 changes: 36 additions & 10 deletions static/smile-teacher.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,42 @@
border-bottom: 1px solid #EBE3BD;
}

section[smile=general-board] table#students .sticker {
section[smile=general-board] table#students .sticker_null {
color: white;
font-weight: bold;
background-color: #ffa938;
background-color: #ddd;
border: 1px solid #ccc;
border-radius: 3px;
padding: 2px 6px;
padding: 1px 7px;
font-size: 16px; }
section[smile=general-board] table#students .sticker_positive {
color: white;
font-weight: bold;
background-color: #ffca85;
border: 1px solid #ffa938;
border-radius: 3px;
padding: 1px 7px;
font-size: 16px;
}

section[smile=general-board] table#students .score_container {
font-size: 20px;
color: white;
font-weight:bold;
margin-right:15px;
width: 20px;
text-align: right;
}
section[smile=general-board] table#students .score {
text-shadow:0 0 3px #888;
}
section[smile=general-board] table#students .gold_score {
text-shadow:0 0 3px #ccac00;
}
section[smile=general-board] table#students .answered {
text-shadow:0 0 4px #47f286;
color:#29914f;
font-weight:bold;
}

/* -------
Expand All @@ -117,12 +147,6 @@
min-height: 200px;
}

.answered {
text-shadow:0 0 4px #47f286;
color:#29914f;
font-weight:bold;
}

.style_redRight {
color: #D22;
font-size: 12px;
Expand Down Expand Up @@ -269,6 +293,8 @@

<table id="students" data-bind="foreach: students" >
<tr style="height:30px">
<td class="score_container">
</td>
<td smile="name_of_student">
<input type="hidden" data-bind="attr: {value: name}" />
<span data-bind="text: name"></span>
Expand All @@ -278,7 +304,7 @@
<span data-bind="text: ip"></span>
</td>
<td smile="number_of_questions">
<span class="sticker">0</span>
<span class="sticker_null">0</span>
</td>
</tr>
</table>
Expand Down

0 comments on commit 909af60

Please sign in to comment.