Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed generate_base so that it doesn't download experiment, survey … #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions expfactory/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def generate_base(battery_dest,tasks=None,experiment_repo=None,survey_repo=None,game_repo=None,
add_experiments=True,add_surveys=True,add_games=True,battery_repo=None,warning=True):
battery_repo=None,warning=True):
'''generate_base returns a folder with downloaded experiments, surveys, and battery, either specified by the user or a temporary directory, to be used by generate_local and generate (for psiturk)
:param battery_dest: [required] is the output folder for your battery. This folder MUST NOT EXIST.
:param battery_repo: location of psiturk-battery repo to use as a template. If not specified, will be downloaded to a temporary directory
Expand All @@ -25,30 +25,29 @@ def generate_base(battery_dest,tasks=None,experiment_repo=None,survey_repo=None,
:param tasks: a list of experiments and surveys, meaning the "exp_id" variable in the config.json, to include. This variable also conincides with the tasks folder name.
:param warning: show warnings when validating experiments (default True)
'''
if experiment_repo == None or battery_repo == None or survey_repo == None or game_repo == None:
tmpdir = custom_battery_download()
if experiment_repo == None:
experiment_repo = "%s/experiments" %(tmpdir)
if battery_repo == None:
battery_repo = "%s/battery" %(tmpdir)
if survey_repo == None:
survey_repo = "%s/surveys" %(tmpdir)
if game_repo == None:
game_repo = "%s/games" %(tmpdir)
repos = []
tmpdir = None
if battery_repo == None:
tmpdir = custom_battery_download(repos=['battery'])
battery_repo = "%s/battery" %(tmpdir)
if experiment_repo == None and survey_repo == None and game_repo == None:
tmpdir = custom_battery_download(tmpdir, ['experiments', 'surveys', 'games'])
experiment_repo = "%s/experiments" %(tmpdir)
survey_repo = "%s/surveys" %(tmpdir)
game_repo = "%s/games" %(tmpdir)


# Copy battery skeleton to destination
copy_directory(battery_repo,battery_dest)
valid_experiments = []
valid_surveys = []
valid_games = []
if add_experiments == True:
if experiment_repo is not None:
valid_experiments = get_experiments(experiment_repo,warning=warning)
if add_surveys == True:
if survey_repo is not None:
valid_surveys = get_experiments(survey_repo,warning=warning,repo_type="surveys")
if add_games == True:
if game_repo is not None:
valid_games = get_experiments(game_repo,warning=warning,repo_type="games")

# If the user wants to select a subset
if tasks != None:
valid_experiments = [x for x in valid_experiments if os.path.basename(x) in [os.path.basename(e) for e in tasks]]
Expand Down Expand Up @@ -81,14 +80,11 @@ def generate_local(battery_dest=None,subject_id=None,battery_repo=None,experimen

# We can only generate a battery to a folder that does not exist, to be safe
if not os.path.exists(battery_dest):

base = generate_base(battery_dest=battery_dest,
tasks=experiments,
experiment_repo=experiment_repo,
battery_repo=battery_repo,
warning=warning,
add_surveys=False)

warning=warning)
# We will output a local battery template (without psiturk)
template_exp = "%s/templates/localbattery.html" %get_installdir()
template_exp_output = "%s/index.html" %(battery_dest)
Expand All @@ -101,7 +97,6 @@ def generate_local(battery_dest=None,subject_id=None,battery_repo=None,experimen
custom_variables = dict()
custom_variables["exp"] = [("[SUB_SUBJECT_ID_SUB]",subject_id)]
custom_variables["load"] = [("[SUB_TOTALTIME_SUB]",time)]

# Fill in templates with the experiments
template_experiments(battery_dest=battery_dest,
battery_repo=base["battery_repo"],
Expand Down