def getuncommons(answers): answerchoices = (AnswerChoiceModel.get_all()) cnt = Counter() for answer in answers: cnt[answer] = 0 for answerchoice in answerchoices: if answerchoice.best_answer_id in answers: cnt[answerchoice.best_answer_id] += 1 if len(cnt) > 1: return [cnt.most_common()[-1][0],cnt.most_common()[-2][0]] else: return False
def getotheranswers(userID,questionID): allanswers = (AnswerModel.get_all()) allanswerchoices = (AnswerChoiceModel.get_all()) validAnswers = [] for currentanswer in allanswers: # if relevant answer and not submitted by the current user if currentanswer.userID != userID and currentanswer.questionID == questionID: shouldadd = True for currentanswerchoice in allanswerchoices: # if answer was not rated before by the current user if (currentanswerchoice.best_answer_id == currentanswer.id or currentanswerchoice.other_answer_id == currentanswer.id) and currentanswerchoice.user_id == userID: break else: validAnswers.append(currentanswer.id) return validAnswers