Exemplo n.º 1
0
def get_load_static(valid_experiments, url_prefix="", unique=True):
    '''get_load_static
    return the scripts and styles as <link> and <script> to embed in a page directly
    :param unique: return only unique scripts [default=True]
    '''
    loadstring = ""
    for valid_experiment in valid_experiments:
        experiment = load_experiment(valid_experiment)
        css, js = get_stylejs(experiment, url_prefix=url_prefix)
        loadstring = "%s%s%s" % (loadstring, js, css)
    if unique == True:
        scripts = loadstring.split("\n")
        scripts_index = list(np.unique(scripts, return_index=True))[1]
        # This ensures that scripts are loaded in same order as specified in config.json
        unique_scripts = [scripts[idx] for idx in sorted(scripts_index)]
        loadstring = "\n".join(unique_scripts)
    return loadstring
Exemplo n.º 2
0
def get_load_static(valid_experiments,url_prefix="",unique=True):
    '''get_load_static
    return the scripts and styles as <link> and <script> to embed in a page directly
    :param unique: return only unique scripts [default=True]
    '''
    loadstring = ""
    for valid_experiment in valid_experiments:
        experiment = load_experiment(valid_experiment)
        css,js = get_stylejs(experiment,url_prefix=url_prefix)
        loadstring = "%s%s%s" %(loadstring,js,css)        
    if unique == True:
        scripts = loadstring.split("\n")
        scripts_index = numpy.unique(scripts,return_index=True)[1]
        # This ensures that scripts are loaded in same order as specified in config.json
        unique_scripts = [scripts[idx] for idx in sorted(scripts_index)]
        loadstring = "\n".join(unique_scripts)
    return loadstring
Exemplo n.º 3
0
def get_experiment_html(experiment,
                        experiment_folder,
                        url_prefix="",
                        deployment="local"):
    '''get_experiment_html
    return the html template to test a single experiment
    :param experiment: the loaded config.json for an experiment (json)
    :param experiment_folder: the experiment folder, needed for reading in a survey
    :param url_prefix: prefix to put before paths, in case of custom deployment
    :param deployment: deployment environment, one of docker, docker-preview, or local [default]
    '''

    css, js = get_stylejs(experiment, url_prefix)
    validation = ""

    # JsPsych experiment
    if experiment[0]["template"] in ["jspsych"]:
        html = ""
        runcode = get_experiment_run(
            experiment, deployment=deployment)[experiment[0]["exp_id"]]
        template_base = "experiment"

    # HTML survey
    elif experiment[0]["template"] in ["survey"]:
        html, validation = generate_survey(experiment, experiment_folder)
        runcode = ""
        template_base = "survey"

    # Phaser game
    elif experiment[0]["template"] in ["phaser"]:
        html = ""
        runcode = experiment[0]["deployment_variables"]["run"]
        template_base = "phaser"

    exp_template = "%s/templates/%s.html" % (get_installdir(), template_base)

    # Make substitutions
    exp_template = "".join(open(exp_template, "r").readlines())
    exp_template = sub_template(exp_template, "{{js}}", js)
    exp_template = sub_template(exp_template, "{{css}}", css)
    exp_template = sub_template(exp_template, "{{run}}", runcode)
    exp_template = sub_template(exp_template, "{{html}}", html)
    exp_template = sub_template(exp_template, "{{validation}}", validation)
    exp_template = sub_template(exp_template, "{{exp_id}}",
                                experiment[0]["exp_id"])
    return exp_template
Exemplo n.º 4
0
def get_experiment_html(experiment,experiment_folder,url_prefix="",deployment="local"):
    '''get_experiment_html
    return the html template to test a single experiment
    :param experiment: the loaded config.json for an experiment (json)
    :param experiment_folder: the experiment folder, needed for reading in a survey
    :param url_prefix: prefix to put before paths, in case of custom deployment
    :param deployment: deployment environment, one of docker, docker-preview, or local [default]
    '''

    css,js = get_stylejs(experiment,url_prefix)
    validation = ""

    # JsPsych experiment
    if experiment[0]["template"] in ["jspsych"]:
        html = ""
        runcode = get_experiment_run(experiment,deployment=deployment)[experiment[0]["exp_id"]]
        template_base = "experiment"

    # HTML survey
    elif experiment[0]["template"] in ["survey"]:
        html,validation = generate_survey(experiment,experiment_folder)
        runcode = ""
        template_base = "survey"

    # Phaser game
    elif experiment[0]["template"] in ["phaser"]:
        html = ""
        runcode = experiment[0]["deployment_variables"]["run"]
        template_base = "phaser"


    exp_template = "%s/templates/%s.html" %(get_installdir(),template_base)

    # Make substitutions
    exp_template = "".join(open(exp_template,"r").readlines())
    exp_template = sub_template(exp_template,"{{js}}",js)
    exp_template = sub_template(exp_template,"{{css}}",css)
    exp_template = sub_template(exp_template,"{{run}}",runcode)
    exp_template = sub_template(exp_template,"{{html}}",html)
    exp_template = sub_template(exp_template,"{{validation}}",validation)
    exp_template = sub_template(exp_template,"{{exp_id}}",experiment[0]["exp_id"])
    return exp_template