def set_next_users_parameters(repo, selector, course_id): # pass here if not using BO if not USE_PSITURK_AND_BAYESIAN_OPT: print "lol" return """@type repo: DataInterface """ if DO_BASELINE: #uncomment this to do 1 at a time #if psiturk_hit_check(repo): # extend_hit(repo) extend_hit(repo) etc_resources.append_to_log("Attempting to set next user's parameters for: " + course_id, repo) print("Attempting to set next user's parameters for: " + course_id + "\n") try: #find current experiment exps = repo.get_experiments(course_id) now = int(time.time()) exp = None for e in exps: if e['start_time'] < now and e['end_time'] > now: exp = e if exp is None: etc_resources.append_to_log("NO current experiment found for Bayesian Optimization on course: " + course_id + ". Exiting...", repo) print("WOAH! No current experiment found for Bayesian Optimization\n") return #get list of skills up in this business skills = repo.get_skills(course_id) if 'None' in skills: skills.remove('None') users = repo.get_subjects(course_id, exp['experiment_name']) #get trajectories trajectories = get_blobs_with_params(repo, selector, course_id, users, skills) etc_resources.append_to_log(str(len(users)) + " User trajectories found on course: " + course_id + ", running BO on these now.", repo) ########## start new thread to run Bayesian Optimization # This is important- BO could take a while and the thread running here needs to be serving the REST api # thread.start_new_thread(run_BO, (trajectories, course_id)) ######## Now we're running BO on a totally different server response = requests.post('http://'+BO_SERVER_HOST+':9000/api/v1/misc/RunBO/course/' + course_id, data=json.dumps({'trajectories': trajectories}), headers=headers) etc_resources.append_to_log("BO server said: " + str(response.json()), repo) except DataException as e: print(str(e) + "\n") except SelectException as e: print(str(e) + "\n") except Exception as e: etc_resources.append_to_log("Crud. Some uncaught exception happened: " + str(e), repo) raise e
def extend_hit(repo): try: hitid = repo.get("__HITID__") etc_resources.append_to_log("Hit ID to extend: " + str(hitid), repo) except Exception as e: etc_resources.append_to_log("Hit ID not found :(") return False try: r = mturk_conn.extend_hit(hitid, assignments_increment=1) etc_resources.append_to_log("mturk_conn.extend_hit() returned: " + str(r), repo) r = mturk_conn.extend_hit(hitid, expiration_increment=3600 * 3) print str(r) etc_resources.append_to_log("mturk_conn.extend_hit() returned: " + str(r), repo) except Exception as e: etc_resources.append_to_log("Exception extending hit: " + str(e), repo) return False return True