Example #1
0
def done():
    question_type = [x[0] for x in conn.execute(select([Questions.c.question_type]).\
            select_from(StudentsTest.join(Questions,
                 Questions.c.question_id == StudentsTest.c.question_id)).\
        where(StudentsTest.c.student_id == flask.session['userid'])).fetchall()]
    if 'multiple_choice' in question_type:
        return flask.render_template('doneA.html')
    elif 'heuristic' in question_type:
        return flask.render_template('doneB.html')
    else:
        asdf
Example #2
0
def training_answers():
    params = request.args

    #update order number
    flask.session['order'] = flask.session['order'] + 1

    #data
    order = params['order']
    graph1 = flask.session['graph1']
    student_test_id = flask.session['student_test_id']
    student_id = flask.session['userid']

    if flask.session['question_type'] == 'rating':
        answer_id = params['rating1']
    else:
        answer1 = params['best1']
        #figure out answer
        if answer1 == 'optionA':
            answer_id = flask.session['answer1']
        elif answer1 == 'optionB':
            answer_id = flask.session['answer2']
        elif answer1 == 'optionC':
            answer_id = flask.session['answer3']
        elif answer1 == 'optionD':
            answer_id = flask.session['answer4']
        elif answer1 == 'optionE':
            answer_id = flask.session['answer5']


    answer_list = [(answer_id,graph1)]

    #write to db
    #update complete row in StudentsTest table
    r = conn.execute(StudentsTest.update().\
                     where(StudentsTest.c.student_test_id == student_test_id).\
                     values(complete='yes'))

    conn.execute(Results.insert(), [{
                      'student_id':student_id,
                      'student_test_id':student_test_id,
                      'answer':answer[0],
                      'graph_id':answer[1],
                      } for answer in answer_list])

    #get next question
    # question_json = first_question()
    # return question_json
    return flask.jsonify(result={"status": 200})
Example #3
0
def get_question(order):
    progress, graph_id, questions, question_type, answers, complete, dataset, student_test_id, question_id = conn.execute(select([Students.c.progress,
                                            StudentsTest.c.graph_id,
                                            Questions.c.question,
                                            Questions.c.question_type,
                                            Answers.c.answer,
                                            StudentsTest.c.complete,
                                            StudentsTest.c.dataset,
                                            StudentsTest.c.student_test_id,
                                            Questions.c.question_id]).\
                                select_from(StudentsTest.join(Students,
                                            Students.c.student_id == StudentsTest.c.student_id).\
                                join(Questions,
                                     Questions.c.question_id == StudentsTest.c.question_id)).\
                            where(and_(StudentsTest.c.student_id == flask.session['userid'],
                                  StudentsTest.c.test == Students.c.progress,
                                  StudentsTest.c.order == order))).fetchone()
    return progress, graph_id, questions, question_type, answers, complete, dataset, student_test_id, question_id
Example #4
0
def pretest_answers():
    params = request.args

    #update order number
    flask.session['order'] = flask.session['order'] + 1

    #data
    best1 = params['best1']
    best2 = params['best2']
    best3 = params['best3']
    order = params['order']
    graph1 = flask.session['graph1']
    graph2 = flask.session['graph2']
    graph3 = flask.session['graph3']
    student_test_id = flask.session['student_test_id']
    student_id = flask.session['userid']

    try:
        best4 = params['best4']
        answer_list = [(best1,graph1),(best2,graph2),(best3,graph3),(best4,'na')]
    except:
        answer_list = [(best1,graph1),(best2,graph2),(best3,graph3)]

    #write to db
    #update complete row in StudentsTest table
    r = conn.execute(StudentsTest.update().\
                     where(StudentsTest.c.student_test_id == student_test_id).\
                     values(complete='yes'))

    conn.execute(Results.insert(), [{
                      'student_id':student_id,
                      'student_test_id':student_test_id,
                      'answer':answer[0],
                      'graph_id':answer[1],
                      } for answer in answer_list])

    #get next question
    # question_json = first_question()
    # return question_json
    return flask.jsonify(result={"status": 200})
Example #5
0
def first_question():
    userid = flask.session['userid']

    try:
        order = flask.session['order']
    except:
        order = 1

    try:
        progress, graph_id, question, question_type, answers, complete, dataset, student_test_id,question_id = get_question(order)
    except:
        complete = 'yes'
        progress = conn.execute(select([Students.c.progress]).\
                                where(Students.c.student_id == flask.session['userid'])).fetchone()
        progress = progress[0]

    #check to make sure they have not done the question before
    if complete == 'yes':
        #this means the question has already been completed
        order_list = conn.execute(select([StudentsTest.c.order]).\
                             select_from(StudentsTest.join(Students,
                                         Students.c.student_id == StudentsTest.c.student_id)).\
                             where(and_(StudentsTest.c.student_id == flask.session['userid'],
                                   StudentsTest.c.complete == 'no',
                                   StudentsTest.c.test == Students.c.progress))).fetchall()

        order_list = sorted(order_list)

        if len(order_list) >= 1:
            progress, graph_id, question, question_type, answers, complete, dataset, student_test_id, question_id = get_question(order_list[0][0])
        else:
            #the section has been completed, update progress and return to home page
            #update order back to start
            flask.session['order'] = 1
            progress_list = ['pre_test', 'training', 'post_test']
            ix = progress_list.index(progress) + 1
            if ix == len(progress_list):
                new_progress = 'complete'
            else:
                new_progress = progress_list[ix]
            r = conn.execute(Students.update().\
                             where(Students.c.student_id == flask.session['userid']).\
                             values(progress=new_progress))
            #return to homepage
            if new_progress == 'complete':
                return flask.jsonify(progress='done')
            else:
                return flask.jsonify(progress='next')

    #put the student_test_id in session
    flask.session['student_test_id'] = student_test_id
    flask.session['order'] = order
    flask.session['question_type'] = question_type

    #check which test
    if progress == 'pre_test' or progress == 'post_test':
        # query three graphs

        graph_list = conn.execute(select([Graphs.c.graph_location,
                                            Graphs.c.graph_id]).\
                                        where(Graphs.c.dataset == dataset)).fetchall()

        #randomly shuffle order of graphs
        shuffle(graph_list)

        #put graph id's in session
        flask.session['graph1'] = graph_list[0][1]
        flask.session['graph2'] = graph_list[1][1]
        flask.session['graph3'] = graph_list[2][1]


        return flask.jsonify(graph1='<img class=graph src=' + url_for('static',filename='graphs/'+str(graph_list[0][0])) + '>',
                             graph2='<img class=graph src=' + url_for('static',filename='graphs/'+str(graph_list[1][0])) + '>',
                             graph3='<img class=graph src=' + url_for('static',filename='graphs/'+str(graph_list[2][0])) + '>',
                             question=question,
                             question_type=question_type,
                             order=order,
                             progress=progress)

    elif progress == 'training':
        #get graph location
        graph_location = conn.execute(select([Graphs.c.graph_location]).\
                                        where(Graphs.c.graph_id == graph_id)).fetchall()

        #if it is a rating question just return graph
        if question_type == 'rating':
            flask.session['graph1'] = graph_id
            return flask.jsonify(graph1='<img class=graph src=' + url_for('static',filename='graphs/'+str(graph_location[0][0])) + '>',
                             question=question,
                             question_type=question_type,
                             order=order,
                             progress=progress)
        else:
            #get answers query
            answer_list = conn.execute(select([Answers.c.answer,
                                              Answers.c.answer_id]).\
                                        where(Answers.c.question_id == question_id)).fetchall()

            try:
                answer_list[0][1]
            except:
                if len(answer_list) >1:
                    longg
                elif len(answer_list) <= 1:
                    shortt

            if question_type == 'heuristic':
                #put graph id's in session
                flask.session['graph1'] = graph_id
                flask.session['answer1'] = answer_list[0][1]
                flask.session['answer2'] = answer_list[1][1]
                flask.session['answer3'] = answer_list[2][1]
                flask.session['answer4'] = answer_list[3][1]
                flask.session['answer5'] = answer_list[4][1]

                return flask.jsonify(graph1='<img src=' + url_for('static',filename='graphs/'+str(graph_location[0][0])) + ' height="500" width="500">',
                                     question=question,
                                     question_type=question_type,
                                     order=order,
                                     progress=progress,
                                     answer1=answer_list[0][0],
                                     answer2=answer_list[1][0],
                                     answer3=answer_list[2][0],
                                     answer4=answer_list[3][0],
                                     answer5=answer_list[4][0])

            else:
                #put graph id's in session
                flask.session['graph1'] = graph_id
                flask.session['answer1'] = answer_list[0][1]
                flask.session['answer2'] = answer_list[1][1]
                flask.session['answer3'] = answer_list[2][1]

                return flask.jsonify(graph1='<img src=' + url_for('static',filename='graphs/'+str(graph_location[0][0])) + ' height="500" width="500">',
                                     question=question,
                                     question_type=question_type,
                                     order=order,
                                     progress=progress,
                                     answer1=answer_list[0][0],
                                     answer2=answer_list[1][0],
                                     answer3=answer_list[2][0])
Example #6
0
def create_student_data(sid_list, student_question_list, test, group):
    if test == 'pre_test' or test == 'post_test':
      question_list = [x[:3] for x in student_question_list]
    else:
      question_list = [x[3:] for x in student_question_list]
    for n, student in enumerate(question_list):
        student_id = sid_list[n]
        #count the order for each student per test
        order = 0
        for ix, graph in enumerate(student):
            student_test_id = int(str(student_id)+str(ix))
            dataset = graph[0]
            if dataset == 0:
                #not using 0 precursor for easier use in excel
                graph_id = graph[1] + 1
            else:
                graph_id = int(str(dataset)+str(graph[1]+1))
            if test == 'pre_test' or test == 'post_test':
                order += 1
                if dataset == 0:
                    question_id = 5
                else:
                    question_id = int(str(dataset)+str(5))
                #write row to db
                conn.execute(StudentsTest.insert(), {'student_id':student_id,
                                    'test':test,
                                    'graph_id':graph_id,
                                    'dataset':dataset,
                                    'question_id':question_id,
                                    'order':order,
                                    'complete':'no'})
            elif group == 'heuristic':
              for x in range(6,9):
                  order += 1
                  if dataset == 0:
                      question_id = x
                  else:
                      question_id = int(str(dataset)+str(x))
                  #write row to db
                  conn.execute(StudentsTest.insert(), {'student_id':student_id,
                                      'test':test,
                                      'graph_id':graph_id,
                                      'dataset':dataset,
                                      'question_id':question_id,
                                      'order':order,
                                      'complete':'no'})
            else:
                #multiple choice questions
                for x in range(3):
                    order += 1
                    if dataset == 0:
                        question_id = x + 1
                    else:
                        question_id = int(str(dataset)+str(x + 1))
                    #write row to db
                    conn.execute(StudentsTest.insert(), {'student_id':student_id,
                                    'test':test,
                                    'graph_id':graph_id,
                                    'dataset':dataset,
                                    'question_id':question_id,
                                    'order':order,
                                    'complete':'no'})
            if test == 'training':
              #only have rating question for training
              order += 1
              if dataset == 0:
                  question_id = 4
              else:
                  question_id = int(str(dataset)+str(4))
              #write row to db
              conn.execute(StudentsTest.insert(), {'student_id':student_id,
                                  'test':test,
                                  'graph_id':graph_id,
                                  'dataset':dataset,
                                  'question_id':question_id,
                                  'order':order,
                                  'complete':'no'})
Example #7
0
            if test == 'training':
              #only have rating question for training
              order += 1
              if dataset == 0:
                  question_id = 4
              else:
                  question_id = int(str(dataset)+str(4))
              #write row to db
              conn.execute(StudentsTest.insert(), {'student_id':student_id,
                                  'test':test,
                                  'graph_id':graph_id,
                                  'dataset':dataset,
                                  'question_id':question_id,
                                  'order':order,
                                  'complete':'no'})


#check for table and if it is there clear before writing to
if engine.dialect.has_table(engine.connect(), "students_test"):
    conn.execute(StudentsTest.delete())

#create all the student_test table data
for test in ['pre_test', 'training', 'post_test']:
    create_student_data(question_student_id_list, student_question_list, test, 'question')
    create_student_data(heuristic_student_id_list, student_question_list, test, 'heuristic')