Exemplo 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
Exemplo n.º 2
0
def makeSession(sname, qid):
    """makes a table called sname+RESPONSES.Tables have a username
    column, a column corresponding to a question to record a grade
    and and columns to record responses.
    quiz id: Q+<integer>
    quiz question: Qqq <-- concatenate digit
    quiz choice Qqq "choice" IDC <-- concatenate choice id
    """
    if isInTable("sessions", "name", sname):
        return False

    # I'm not sure why these lines aren't already applied,
    # but they're added here to speed things up
    gdbk.query("PRAGMA journal_mode=off")
    gdbk.query("PRAGMA synchronous=off")
    #
    qblocks = questions.getQblocks(qid)
    qlist = map(cq.clkrQuestion, qblocks)
    sqlstring = "CREATE TABLE {0}(username TEXT)".format(sname)
    gdbk.query(sqlstring)

    qcounter = 0
    for clq in qlist:
        basename = "Q" + str(qcounter)
        totcol = basename + "total"
        addFloatCol(sname, basename)  # new check if works
        addFloatCol(sname, totcol)
        cd = clq.getChoiceDict()
        for i in cd:
            colname = basename + i
            addIntCol(sname, colname)
        qcounter += 1

    qstr = questions.getQuizQuestions(qid)
    gdbk.insert("sessions", name=sname, quiz=qid, questions=qstr)
Exemplo n.º 3
0
 def POST(self):
     validateInstructor()
     i = web.input()
     quiz = i['quiz']
     newqlist = i['quizlist']
     newqlist = cleanCSL(newqlist)        
     questions.setQuizQuestions(quiz,newqlist)
     hits = questions.getQblocks(quiz)
     hits = map(cq.clkrQuestion,hits)
     return render.assemble(mathpre,quiz,hits,newqlist)
Exemplo 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