def POST(self, object_id): '''Updates object_id with the newly selected answers to questions.''' inputs = web.input() for question_id in inputs: answer = inputs[question_id] if answer in ['yes','no']: value = eval('game.' + answer) * game.RETRAIN_SCALE # STRONGLY weights values learned this way model.update_data(object_id, question_id, value) raise web.seeother('/data')
def POST(self, object_id): '''Updates object_id with the newly selected answers to questions.''' inputs = web.input() for question_id in inputs: answer = inputs[question_id] if answer in ['yes', 'no']: value = eval( 'game.' + answer ) * game.RETRAIN_SCALE # STRONGLY weights values learned this way model.update_data(object_id, question_id, value) raise web.seeother('/data')
def learn(asked_questions, object_id): '''Updates the data for the correct object based on information in asked_questions. Also updates times played for the object and stores the playlog.''' for question in asked_questions: current_weight = model.get_value(object_id, question) if not(current_weight): current_weight = 0 new_weight = current_weight + asked_questions[question] model.update_data(object_id, question, new_weight) model.update_times_played(object_id) model.record_playlog(object_id, asked_questions, True)
def POST(self): '''Processes the learning form and learns the correct character and new question.''' inputs = web.input() name = inputs.get('name') if name == "new": name = inputs.get('new_character') question = inputs.get('question', '') if question: new_question_answer = inputs.get('new_question_answer') if new_question_answer in ['yes', 'no', 'unsure']: answer = eval('game.' + new_question_answer) * game.NEW_QUESTION_SCALE # strongly weights new answer else: answer = game.unsure if question.strip() != '' and not (model.get_question_by_text( question.strip())): # makes sure the question is not already in the database new_question_id = model.add_question(question) else: new_question = model.get_question_by_text(question.strip()) # if question already in DB, returns question. else returns None. if new_question: new_question_id = new_question.id else: new_question_id = None if name: new_object_id = game.learn_character(session.asked_questions, name) else: new_object_id = None if new_question_id and new_object_id: model.update_data(new_object_id, new_question_id, answer) reset_game() # resets game data and starts a new game raise web.seeother('/')
def POST(self): """Processes the learning form and learns the correct character and new question.""" inputs = web.input() name = inputs.get("name") if name == "new": name = inputs.get("new_character") question = inputs.get("question", "") if question: new_question_answer = inputs.get("new_question_answer") if new_question_answer in ["yes", "no", "unsure"]: answer = eval("game." + new_question_answer) * game.NEW_QUESTION_SCALE # strongly weights new answer else: answer = game.unsure if question.strip() != "" and not (model.get_question_by_text(question.strip())): # makes sure the question is not already in the database new_question_id = model.add_question(question) else: new_question = model.get_question_by_text(question.strip()) # if question already in DB, returns question. else returns None. if new_question: new_question_id = new_question.id else: new_question_id = None if name: new_object_id = game.learn_character(session.asked_questions, name) else: new_object_id = None if new_question_id and new_object_id: model.update_data(new_object_id, new_question_id, answer) reset_game() # resets game data and starts a new game raise web.seeother("/")
def POST(self): '''Processes the learning form and learns the correct character and new question.''' inputs = web.input() name = inputs.get('name') if name == "new": name = inputs.get('new_character') question = inputs.get('question', '') if question: new_question_answer = inputs.get('new_question_answer') if new_question_answer in ['yes','no','unsure']: answer = eval('game.' + new_question_answer) * game.NEW_QUESTION_SCALE # strongly weights new answer else: answer = game.unsure if question.strip() != '' and not(model.get_question_by_text(question.strip())): # makes sure the question is not already in the database new_question_id = model.add_question(question) else: new_question = model.get_question_by_text(question.strip()) # if question already in DB, returns question. else returns None. if new_question: new_question_id = new_question.id else: new_question_id = None if name: new_object_id = game.learn_character(session.asked_questions, name) else: new_object_id = None if new_question_id and new_object_id: model.update_data(new_object_id, new_question_id, answer) reset_game() # resets game data and starts a new game raise web.seeother('/')