Esempio n. 1
0
def tallyAnswers(session, qnumber):
    """
    Counts the responses to a question and returns a dictionary
    """
    quizID = getEntry("sessions", "quiz", "name", session)
    qblock = questions.getQblocks(quizID)[qnumber]
    clkq = cq.clkrQuestion(qblock)
    basename = "Q" + str(qnumber)
    results = {}
    choices = clkq.getChoices()
    total = 0

    # count total number of entries (some students may be absent)
    bob = gdbk.select(session, what=basename)
    for i in bob:
        if not (i[basename] == None):
            total += 1
    results["Total responses"] = total

    # add up individual selections
    for i in choices:
        name = i
        choice = basename + i
        bob = gdbk.select(session, what=choice)
        selected = 0
        for i in bob:
            if i[choice] == 1:
                selected += 1
        results[name + "count"] = selected
        if total == 0:
            perc = 0
        else:
            perc = int(float(selected) / float(total) * 100)
        results[name] = perc
    return results
Esempio n. 2
0
def giveClickerQuestion(session,page):
    """
    Returns the clickerquestion corresponding to a page on 
    a session
    """
    qstr = gradebook.getSessionQuestions(session)
    print qstr
    qlist = qstr.split(',')
    qid=qlist[page]
    qblock = getQuestion(qid)
    return cq.clkrQuestion(qblock)
Esempio n. 3
0
 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)
Esempio n. 4
0
def getStudentSelections(student, session, qnumber):
    """
    Returns a list of answerids of the student's selection
    """
    quizID = getEntry("sessions", "quiz", "name", session)
    qblock = questions.getQblocks(quizID)[qnumber]
    clkq = cq.clkrQuestion(qblock)
    basename = "Q" + str(qnumber)
    choices = clkq.getChoices()
    selections = []
    sqldic = {"where": 'username = "******"'.format(student)}
    row = gdbk.select(session, **sqldic)[0]
    for c in choices:
        if row[basename + c] == 1:
            selections.append(c)
    return selections
Esempio n. 5
0
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
Esempio n. 6
0
 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)
Esempio n. 7
0
 def barfClq(self):
     "produces a clickerquestion, not very elegantly though"
     return cq.clkrQuestion(self.writeQblock())