def get_quiz(): global question, lis, options, answer options.clear() question = "" answer = "" quiz = getQuestion() question = quiz['question'] answer = quiz['options'][quiz['answer']] for i in quiz['options'].keys(): options.append(quiz['options'][i])
def GET(self): wi = web.input() ID=wi['ID'] #return ID ID = str(ID) qblk = questions.getQuestion(ID) if qblk == None: return "Question not found. Did you save yet?" clq = cq.clkrQuestion(qblk) content = clq.showCorrect() pre = str(mathpre)+"\n<link href=\"/static/question.css\" rel=\"stylesheet\">" return render.bootstrap(pre,"Preview",content)
def handleSearch(): matchResult = match(activeUsers) if len(matchResult) != 0: firstUser = matchResult[0] secondUser = matchResult[1] roomId = matchResult[2] question = getQuestion() socketio.emit('matched', (firstUser, secondUser, question, roomId), room=firstUser['sid']) socketio.emit('matched', (secondUser, firstUser, question, roomId), room=secondUser['sid'])
def toggleChoice(student, session, qnumber, choice): """ Changes the value of a student choice and updates the grade at the same time. This is the method that works hardest, so database calls are minimized. Update is expensive. """ qustr = getSessionQuestions(session) quli = qustr.split(",") qid = quli[qnumber] qblock = questions.getQuestion(qid) clkq = cq.clkrQuestion(qblock) currentq = "Q" + str(qnumber) currentc = currentq + choice wherestring = 'username = "******"'.format(student) dbrow = gdbk.select(session, where=wherestring)[0] # First we toggle the value in the response area curEntry = dbrow[currentc] # return curEntry if curEntry == 1: curEntry = 0 else: curEntry = 1 # After toggling the entry we update the score curScore = dbrow[currentq] if curScore == None: curScore = 0 if clkq.checkAnswer(choice): print "Correct" grade = 1 else: print "Wrong" grade = -1 if curEntry == 1: curScore = curScore + grade else: curScore = curScore - grade total = clkq.getTotal() grade = max(float(curScore) / total, 0) wherestring = 'username = "******"'.format(student) updatedic = {"where": wherestring, currentc: curEntry, currentq: curScore, currentq + "total": grade} gdbk.update(session, **updatedic) return curEntry
def GET(self): #### #Require ID if none create #### username = validateInstructor() wi = web.input() if not "ID" in wi: pclq = pq.Question() pclq.addChoice() else: bob = questions.getQuestion(wi["ID"]) pclq = pq.Question() pclq.setID(wi["ID"]) if not bob == None:#set it to new clicker question clq = cq.clkrQuestion(bob) pclq.eatClq(clq) else: pclq.addChoice() return render.edit(pclq)
def getQuestion(self, user): # Have they specified a question? qNoStr = self.get_query_argument("qNo", default=None) if qNoStr: try: qNo = int(qNoStr) except ValueError: raise tornado.web.HTTPError( 400, "Invalid question number: %s" % (qNoStr)) if qNo > user.highestSolved + 1: raise tornado.web.HTTPError( 400, "Cannot request a question you've not earnt!") else: # Is this a registered user? if user: qNo = user.highestSolved + 1 if qNo > questions.lastQuestion(): qNo = questions.lastQuestion() print("qNo not set, using highest available qNo (%d)" % (qNo)) else: qNo = 1 return questions.getQuestion(qNo)
def selectQuestion(): question = getQuestion() return json.dumps({'question': question}), 200, { 'ContentType': 'application/json' }