def POST(self, worker_id, game_number):
     # First make sure the user hasn't already customized
     
     game_id = model.get_game_id(worker_id, game_number)
     print "checking current game status"
     check = model.check_current_game_status(worker_id, game_id)
     if check:
         raise web.seeother('/error/5?worker_id=' + worker_id)
     
     
     post_data = web.input()
     selections = post_data.selections
     ## Put the selections into a dict
     
     temp = selections.split(',')
     data = {}
     i = 1
     while i < 6:
         try:
             data[i] = temp[i-1]
         except IndexError:
             data[i] = "NULL"
         i += 1
     
     condition = model.get_condition(worker_id)   
     
     game_data = model.get_game_data(game_id)
     #game_number = model.get_games_played(worker_id) + 1
     game_number = int(game_number)
     prediction_quality = model.get_prediction_quality(worker_id, game_id)
     model.update_prediction_start_custom(worker_id, data, prediction_quality)
     
     raise web.seeother("/view_prediction/" + worker_id + "/" + str(game_number))
 def GET(self, worker_id):
     condition = model.get_condition(worker_id)
     if condition > 1:
         raise web.seeother('/error/3')
     survey_questions = {
         "helpful": {"question": "How helpful was the simulator?", "low": "Not at all helpful", "high": "Very helpful"},
         "accurate": {"question": "How accurate do you think the simulator was at predicting the outcome of games?", "low": "Not at all accurate", "high": "Very accurate"},
         "important": {"question": "How important were the simulator's predictions in informing your predictions?" , "low": "Not at all important", "high": "Very important"},
         "control": {"question": "I was able to control the accuracy of the simulator" , "low": "Strongly Disagree", "high": "Strongly Agree"},
     }
     
     customize_questions = {
         "information": {"question": "The information I provided to the simulator was helpful." , "low": "Strongly Disagree", "high": "Strongly Agree"},
         "effort": {"question": "How much effort was required to customize the simulator?", "low": "No effort", "high": "A very high level of effort"}
     }
     
     elm_question = {
         "prompt": "When performing this task, I was...",
         "elm_a": "... extending a good deal of cognitive effort",
         "elm_b": "... resting my mind",
         "elm_c": "... doing my best to think about making the best prediction",
         "low": "Strongly Disagree",
         "high": "Strongly Agree"
     }
     
     return render_main.survey(worker_id, survey_questions, customize_questions, elm_question, condition)
 def GET(self, worker_id, game_number):
     #var_names_batting = {"ba": "Batting Average", "runs": "Runs", "H":"Hits", "2B":"2B", "3B":"3B", "HR":"Home Runs", "OBP":"On-Base Percentage", "SLG":"Slugging Percentage", "BB":"Walks", "SB":"Stolen Bases", "RBI":"Runs Batted In"}
     #var_names_team_pitching = {"ERAp": "Earned Run Average", "BBp":"Walks", "SOp":"Strikeouts", "HRp":"Home Runs"}
     #var_names_starter_pitching = {"Wsp":"Wins", "Lsp":"Losses", "ERAsp":"Earned Run Average", "Hsp": "Hits", "SOsp":"Strikeouts", "HRsp":"Home Runs", "IPsp":"Innings Pitched"}
     
     #worker_id = web.input(worker_id='').worker_id
     condition = model.get_condition(worker_id)
     if condition > 1:
         # If a condition isn't returned, redirect to an error page
         raise web.seeother('/error/3')
     
     # Returns an int with the id number of the next game, or None if 12 games have been played
     #game_number = model.get_games_played(worker_id) + 1
     game_number = int(game_number)
     game_id = model.get_game_id(worker_id, game_number)
     if not game_id:
         raise web.seeother('/survey/' + worker_id)
     game_data = model.get_game_data(game_id)
     
     # First, check to see if there is an existing prediction entry for this user with this game
     check1 = model.check_for_existing_prediction_record(worker_id, game_id)
     
     if check1 != 0:
         check2 = model.check_current_game_status(worker_id, game_id)
         
         if not check2:
             if condition == 1:
                 raise web.seeother('/customize_simulator/' + worker_id + "/" + str(game_number))
             else:
                 print "check2 caught"
                 return render_game.game_overview(worker_id, condition, game_data, var_names_batting, var_names_team_pitching, var_names_starter_pitching, game_number)
             
         else:
             raise web.seeother('/view_prediction/' + worker_id + "/" + str(game_number))
         
         
     
     
     
     ## If all games have been played, redirect to the survey
     #if not game_id:
     #    model.update_stage(worker_id)
     #    raise web.seeother('/survey/' + worker_id)
     #    
     ##Figure out if this game has already begun, and if so, redirect to the correct point in the game
     #status_check = model.get_current_game_status(worker_id, game_id)
     #if status_check == 2:
     #    raise web.seeother("/view_prediction/" + worker_id)
         
     ## create an entry in the predictions table for this game and this user
     #if status_check == 0:
     #    model.create_prediction_entry(worker_id, game_id)
     
     model.create_prediction_entry(worker_id, game_id)
     if condition == 1:
         raise web.seeother('/customize_simulator/' + worker_id + "/" + str(game_number))
     else:
         return render_game.game_overview(worker_id, condition, game_data, var_names_batting, var_names_team_pitching, var_names_starter_pitching, game_number)
 def GET(self, worker_id, game_number):
     condition = model.get_condition(worker_id)
     
     if condition > 1:
         raise web.seeother('/error/3')
     
     #game_number = model.get_games_played(worker_id) + 1
     game_number = int(game_number)
     game_id = model.get_game_id(worker_id, game_number)
     game_data = model.get_game_data(game_id)
     prediction_quality = model.get_prediction_quality(worker_id, game_id)
     if condition == 0:
         model.update_prediction_start_fixed(worker_id, prediction_quality)
     return render_game.predictions(worker_id, condition, game_data, var_names_batting, var_names_team_pitching, var_names_starter_pitching, prediction_quality, game_number)  
 def GET(self, worker_id):
     #worker_id = web.input(worker_id='').worker_id
     
     # figure out which condition the user has been assigned to
     
     condition = model.get_condition(worker_id)
     
     if condition > 1:
         # If a condition isn't returned, redirect to an error page
         raise web.seeother('/error/3')
         
     model.update_instructions_views(worker_id)
     
     
     return render_main.instructions(worker_id, condition)
 def GET(self):
     
     worker_id = web.input(worker_id='').worker_id
     condition = model.get_condition(worker_id)
     
     model.update_quiz_tries(worker_id)
     
     # Prevent question 7 from being available to non-customizable users
     if condition == 1:
         max_question_number = 8
     elif condition > 1:
         raise web.seeother('/error/3')
     else:
         max_question_number = 6
     questions_to_display = random.sample(range(1,max_question_number+1), 3)
     questions = {
         1: {
             "question": "How many games will you make predictions for?",
             "a" : "6",
             "b" : "8",
             "c" : "10",
             "d" : "12"
         },
         2: {
             "question": "How many points do the simulator's predictions score on average?",
             "a" : "10",
             "b" : "21",
             "c" : "15",
             "d" : "17"
         },
         3:
             {
             "question": "If you wager 5 confidence points, and you earn 16 points from your prediction, how many additional points do you earn?",
             "a" : "15",
             "b" : "0",
             "c" : "5",
             "d" : "10"
         },
         4:
             {
             "question": "If you predict Away: 7 | Home: 2 and the final score is Away: 5 | Home: 6, how many points do you earn for your prediction?",
             "a" : "0",
             "b" : "10",
             "c" : "4",
             "d" : "9"
         },
         5:
             {
             "question": "The statistics about the teams are ...",
             "a" : "... totals from the last 5 games.",
             "b" : "... totals and averages from the current season up to the day of the game.",
             "c" : "... totals from the past 5 seasons.",
             "d" : "... averages for the past 5 seasons."
         },
         6:
             {
             "question": "Which of the following statements is FALSE?",
             "a" : "You will be shown statistical information about each of the teams prior to making your predictions.",
             "b" : "You will not be shown the names of the teams",
             "c" : "You will be shown your scores for the game within 1 week through a bonus payment made to your MTurk account",
             "d" : "The simulator's prediction always scores exactly 15 points"
         },
         7:
             {
             "question": "Which of the following statements is TRUE?",
             "a": "You will NOT have the opportunity to customize the simulator's algorithm",
             "b": "You can select six statistical comparisons for the simulator to focus on",
             "c": "The simulator's performance can be improved by customizing it to give more weight to more important categories",
             "d": "By default, the simulator treats winning percentage as the most important statistical comparison between the teams"
             },
         8:
         	{
         	"question": "Which of the following statements is FALSE?",
         	"a": "By default, the simulator treats all statistical comparisons between the teams equally",
         	"b": "A statistical category that you have selected to customize the simulator is given more weight in the simulation than one that you have not chosen",
         	"c": "A statistical category that you have placed at #1 in your list is given more weight than a category at #3 in your list in the simulation",
         	"d": "By default, the records of each team is given the most weight in the simulation"
         	}
     }
     
     
     return render_main.quiz(worker_id, questions, questions_to_display)