def run_all_trials(): # runs all the trials and writes out all data into a json string saved to results.json trials = db.get_all_trials() trialsData = {} # bits and pieces to let us print out something interesting trialNum = 0 totalTrialNum = len(trials) times = [] smallTrials = {}; # the main loop that analyzes each trial also check time to run and whether the trial is shorter than expected for trial in trials: if len(trial['moves']) < 40: smallTrials[trial["_id"]] = len(trial['moves']); startTime = time.time() print "Runnning trial", trialNum, "of", totalTrialNum trial = compare_trial(trial["_id"], move_probability) # clean the trial so that it is serializable trial['_id'] = str(trial['_id']) trial['image_set'] = str(trial['image_set'].id) trial.pop('init_state') endTime = time.time() totalTime = endTime - startTime print "Completed trial", trialNum, "in", totalTime, "seconds" print "" times.append(totalTime) trialNum += 1 # print out some information about the calculation print "Done!" print "Average time per trial: ", sum(times)/totalTrialNum, "seconds" print "The following trials were smaller than expected: " for key, value in smallTrials.iteritems(): print "\tTrial", key, "with", value, "moves" # find a results file that does not yet exist base = "./results" name = base number = 0 while os.path.exists(name + ".json"): name = base + str(number) number += 1 print "Saving results in", name, ".json" f = open(name + ".json", 'w') json.dump(trials, f) f.close()
def run_all_trials_for_params(): # runs all the trials and writes out all data into a json string saved to results.json trials = db.get_all_trials() trialsData = {} for trial in trials: trial = compare_trial(trial['_id'], find_params_for_move) # find a results file that does not yet exist base = "./results" name = base number = 0 while os.path.exists(name + ".json"): name = base + str(number) number += 1 f = open(name + ".json", 'w') json.dump(trials, f) f.close()