Last active
January 5, 2020 20:34
-
-
Save rogeriochaves/cd1c82efaf9081d4817ce24c05e45d7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
questions_so_far = [] | |
answers_so_far = [] | |
@app.route('/') | |
def index(): | |
global questions_so_far, answers_so_far | |
question = request.args.get('question') | |
answer = request.args.get('answer') | |
if question and answer: | |
questions_so_far.append(int(question)) | |
answers_so_far.append(float(answer)) | |
probabilities = calculate_probabilites(questions_so_far, answers_so_far) | |
print("probabilities", probabilities) | |
questions_left = list(set(questions.keys()) - set(questions_so_far)) | |
if len(questions_left) == 0: | |
result = sorted( | |
probabilities, key=lambda p: p['probability'], reverse=True)[0] | |
return render_template('index.html', result=result['name']) | |
else: | |
next_question = random.choice(questions_left) | |
return render_template('index.html', question=next_question, question_text=questions[next_question]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment