Beispiel #1
0
def get_stats():
   user_guesses0 = UserGuess.select().where(UserGuess.quiz_type==0)
   user_guesses1 = UserGuess.select().where(UserGuess.quiz_type==1)
   v0 = gen_stats(user_guesses0)
   v1 = gen_stats(user_guesses1)
   template = jinja_env.get_template("stats.html")
   return template.render(views=[v0, v1], enumerate=enumerate)
Beispiel #2
0
def submit_guesses():
   data = json.loads(request.forms.get("data"))
   answers = data['answers']
   quiz_type = data['type']
   num_correct = 0
   total = len(answers) 
   for guess in answers:
       UserGuess.create(guess=int(guess['answer']), comment=guess['comment_id'], quiz_type=quiz_type)
       actual_count = Comment.select().where(Comment.c_id == guess['comment_id'])[0].upvotes
       num_correct += 1 if detect_group(actual_count) == int(guess['answer']) else 0
   return json.dumps({"num_correct": num_correct, "total": total})
Beispiel #3
0
def data_split(num_train, num_test):
    test_comments = [ug.comment for ug in UserGuess.select().join(Comment, on=(Comment.c_id == UserGuess.comment)).join(Submission, on=(Comment.submission == Submission.s_id))]
    train_comments = training_comments((comment.c_id for comment in test_comments))
    tr_num_data, te_num_data = [], []
    tr_corpuses, te_corpuses = [], []
    comments_read = set()

    for comment in train_comments:
        comments_read.add(comment.c_id)
        data, corpus = create_row(comment) 
        tr_num_data.append(data)
        tr_corpuses.append(corpus)

    tr_num_data = random.sample(tr_num_data, num_train)
    tr_corpuses = random.sample(tr_corpuses, num_train)

    for comment in test_comments:
       if comment.c_id not in comments_read:
           comments_read.add(comment.c_id)
           data, corpus = create_row(comment) 
           te_num_data.append(data)
           te_corpuses.append(corpus)

    te_num_data = random.sample(te_num_data, num_test)
    te_corpuses = random.sample(te_corpuses, num_test)
    res_num_data = np.vstack((tr_num_data, te_num_data))
    res_corpuses = np.vstack((tr_corpuses, te_corpuses))
        
    return (res_num_data, res_corpuses)