From c59d186d392498b3b3cbc25a45e37b868dc21dc9 Mon Sep 17 00:00:00 2001 From: Brad Miller Date: Fri, 18 Feb 2022 14:44:09 -0800 Subject: [PATCH] Clean - respond to group suggestions * change button text and add feedback after answering * make countdown more obvious * fix duplicate peers * reset question for vote 2 --- controllers/peer.py | 31 +++++++++++++++++-------------- static/js/peer.js | 33 ++++++++++++++++++++++++--------- views/peer/peer_question.html | 25 ++++++++++++++++++------- 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/controllers/peer.py b/controllers/peer.py index 826f06a27..cf9307d85 100644 --- a/controllers/peer.py +++ b/controllers/peer.py @@ -91,7 +91,7 @@ def _get_current_question(assignment_id, get_next): idx = assignment.current_index a_qs = db(db.assignment_questions.assignment_id == assignment_id).select( - orderby=db.assignment_questions.sorting_priority + orderby=[db.assignment_questions.sorting_priority, db.assignment_questions.id] ) logger.debug(f"idx = {idx} len of qs = {len(a_qs)}") if idx > len(a_qs) - 1: @@ -310,21 +310,24 @@ def _broadcast_peer_answers(correct, incorrect): for p1, p2 in r.hgetall(f"partnerdb_{auth.user.course_name}").items(): p1 = p1.decode("utf8") partner_list = json.loads(p2) + pdict = {} for p2 in partner_list: ans = answers.get(p2, None) - # create a message to p1 to put into the publisher queue - # it seems odd to not have a to field in the message... - # but it is not necessary as the client can figure out how it is to - # based on who it is from. - mess = { - "type": "control", - "from": p2, - "message": "enableChat", - "broadcast": False, - "answer": ans, - "course_name": auth.user.course_name, - } - r.publish("peermessages", json.dumps(mess)) + pdict[p2] = ans + # create a message from p1 to put into the publisher queue + # it seems odd to not have a to field in the message... + # but it is not necessary as the client can figure out how it is to + # based on who it is from. + mess = { + "type": "control", + "from": p1, + "to": p1, + "message": "enableChat", + "broadcast": False, + "answer": json.dumps(pdict), + "course_name": auth.user.course_name, + } + r.publish("peermessages", json.dumps(mess)) def clear_pairs(): diff --git a/static/js/peer.js b/static/js/peer.js index 92da4b53d..6d2388116 100644 --- a/static/js/peer.js +++ b/static/js/peer.js @@ -41,10 +41,17 @@ function connect(event) { let count = 10; let itimerid = setInterval(async function () { if (count > 0) { + messarea.style.color = "red"; messarea.innerHTML = `

Finish Up only ${count} seconds remaining

`; count = count - 1; } else { - messarea.innerHTML = `

Please Give an explanation for your answer

Then discuss your answer with your partner

`; + messarea.style.color = "black"; + // hide the discussion + let discPanel = document.getElementById("discussion_panel"); + if (discPanel) { + discPanel.style.display = "none"; + } + messarea.innerHTML = `

Please Give an explanation for your answer

Then discuss your answer with your group members

`; window.mcList[currentQuestion].submitButton.disabled = true; window.mcList[currentQuestion].disableInteraction(); clearInterval(itimerid); @@ -65,9 +72,11 @@ function connect(event) { break; case "enableVote": window.mcList[currentQuestion].submitButton.disabled = false; + window.mcList[currentQuestion].submitButton.innerHTML = "Submit"; window.mcList[currentQuestion].enableInteraction(); messarea = document.getElementById("imessage"); messarea.innerHTML = `

Time to make your 2nd vote

`; + $("[type=radio]").prop("checked", false); break; case "enableNext": let butt = document.getElementById("nextqbutton"); @@ -81,16 +90,22 @@ function connect(event) { discPanel.style.display = "block"; } let peerlist = document.getElementById("peerlist"); - let newpeer = document.createElement("p"); const ordA = 65; - let currAnswer = String.fromCharCode(ordA + parseInt(mess.answer)); - newpeer.innerHTML = `Your partner, ${mess.from}, answered ${currAnswer}`; - peerlist.appendChild(newpeer); + adict = JSON.parse(mess.answer); let peersel = document.getElementById("peersel"); - let peeropt = document.createElement("option"); - peeropt.value = mess.from; - peeropt.innerHTML = mess.from; - peersel.appendChild(peeropt); + for (const key in adict) { + let currAnswer = String.fromCharCode(ordA + adict[key]); + let newpeer = document.createElement("p"); + newpeer.innerHTML = `${key} answered ${currAnswer}`; + peerlist.appendChild(newpeer); + let peeropt = document.createElement("option"); + peeropt.value = key; + peeropt.innerHTML = key; + peersel.appendChild(peeropt); + peersel.addEventListener("change", function () { + $(".ratingradio").prop("checked", false); + }); + } break; default: console.log("unknown control message"); diff --git a/views/peer/peer_question.html b/views/peer/peer_question.html index 607128910..92e7fb7e5 100644 --- a/views/peer/peer_question.html +++ b/views/peer/peer_question.html @@ -27,11 +27,11 @@

Peer Instruction Question

{{=XML(current_question['htmlsrc'])}}