Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
Clean - respond to group suggestions
Browse files Browse the repository at this point in the history
* change button text and add feedback after answering
* make countdown more obvious
* fix duplicate peers
* reset question for vote 2
  • Loading branch information
bnmnetp committed Feb 18, 2022
1 parent cbfe623 commit c59d186
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
31 changes: 17 additions & 14 deletions controllers/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down
33 changes: 24 additions & 9 deletions static/js/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ function connect(event) {
let count = 10;
let itimerid = setInterval(async function () {
if (count > 0) {
messarea.style.color = "red";
messarea.innerHTML = `<h3>Finish Up only ${count} seconds remaining</h3>`;
count = count - 1;
} else {
messarea.innerHTML = `<h3>Please Give an explanation for your answer</h3><p>Then discuss your answer with your partner</p>`;
messarea.style.color = "black";
// hide the discussion
let discPanel = document.getElementById("discussion_panel");
if (discPanel) {
discPanel.style.display = "none";
}
messarea.innerHTML = `<h3>Please Give an explanation for your answer</h3><p>Then discuss your answer with your group members</p>`;
window.mcList[currentQuestion].submitButton.disabled = true;
window.mcList[currentQuestion].disableInteraction();
clearInterval(itimerid);
Expand All @@ -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 = `<h3>Time to make your 2nd vote</h3>`;
$("[type=radio]").prop("checked", false);
break;
case "enableNext":
let butt = document.getElementById("nextqbutton");
Expand All @@ -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");
Expand Down
25 changes: 18 additions & 7 deletions views/peer/peer_question.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ <h2>Peer Instruction Question</h2>
{{=XML(current_question['htmlsrc'])}}
</div>
<div id="discussion_panel" class='col-md-6' style="display: none">
<p>Your first answer <span id="first_answer"></span></p>
<p>Your answer <span id="first_answer"></span></p>
<div id="peerlist">
</div>
<p>Please explain your answer to your partner(s)</p>
<textarea id="messageText" rows="2" cols="33">
<p>Please discuss the answers with your group members</p>
<textarea id="messageText" rows="2" cols="40">
</textarea>
<button id="sendpeermsg" type="button" onclick="sendMessage()">Send</button>
<div>
Expand All @@ -43,13 +43,13 @@ <h2>Peer Instruction Question</h2>
<div class="form-group">
Please provide a confidential rating of <select id="peersel" name="peercel"></select>
peer's explanation<br />
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="poor"
<input class="form-check-input ratingradio" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="poor"
onclick="ratePeer(this)">
<label class="form-check-label" for="inlineRadio1">Poor</label>
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="good"
<input class="form-check-input ratingradio" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="good"
onclick="ratePeer(this)">
<label class="form-check-label" for="inlineRadio2">Good</label>
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3"
<input class="form-check-input ratingradio" type="radio" name="inlineRadioOptions" id="inlineRadio3"
value="excellent" onclick="ratePeer(this)">
<label class="form-check-label" for="inlineRadio3">Excellent</label>
</div>
Expand All @@ -64,7 +64,18 @@ <h2>Peer Instruction Question</h2>
document.addEventListener("DOMContentLoaded", function (event) {
setTimeout(connect, 1000);
});

$(document).bind("runestone:login-complete", function () {
setTimeout(function() {
$("[name='do answer']").text("Submit")
$("[name='do answer']").click(function() {
let currentText = $(this).text();
if (currentText.indexOf("Thanks") > 0 ) {
$(this).text("Submit")
} else {
$(this).text("Thanks, your answer is recorded.")}
})
}, 1000);
})
</script>

{{ end }}

0 comments on commit c59d186

Please sign in to comment.