def get_data(): query = Comment.select() num_data = [] corpuses = [] for comment in query: data, corpus = create_row(comment) num_data.append(data) corpuses.append(corpus) return (np.array(num_data), np.array(corpuses))
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})
def list(self): results = Comment.select(Comment.q.handled == False).reversed() return dict(title="BandRadar Comments", grid=datagrid, data=results)
def training_comments(test_ids, limit=None): test_set = set(test_ids) comments = Comment.select().join(Submission, on=(Comment.submission == Submission.s_id)) return filter(lambda comment: comment.c_id not in test_set, comments)
def from_group(group, groups=groups, num=3): """from_group(group[, groups=default_defs, num=3]) Returns list of num random rows from the comment table based on the a definition held in groups with identifier group""" return list(Comment.select().where(groups[group](Comment.upvotes)).order_by(fn.Rand()).limit(num))