コード例 #1
0
ファイル: experiment.py プロジェクト: lalitkumarj/NEXT-psych
def run_experiment(experiment_id):
    # Get the appropriate app manager resource
    app_resource = app_manager.get_app_resource(current_experiment.app_id)

    # Run the experiment using this app resource
    response_dict = app_resource.run_experiment(current_experiment)

    if 'exp_uid' in response_dict.keys() and 'exp_key' in response_dict.keys():
        current_experiment.set_exp_uid(response_dict['exp_uid'])
        current_experiment.set_exp_key(response_dict['exp_key'])
        current_experiment.set_perm_key(response_dict['perm_key']) 
    else:
        flash("Failed to change experiment status to running.")
        return redirect(url_for('experiment._experiment', experiment_id = current_experiment.id))

    # Get the experiment info and store it in our current model
    url = "http://"+config.NEXT_BACKEND_HOST+":"+config.NEXT_BACKEND_PORT+"/api/experiment"
    response = requests.get(url+"/"+current_experiment.exp_uid+"/"+current_experiment.exp_key)
    current_experiment.set_info(eval(response.text))
    
    # Now that we have an exp_uid and exp_key, we can do the target mapping. This needs some error handling here.
    create_target_mapping_dict = {}
    create_target_mapping_dict['app_id'] = current_experiment.app_id
    create_target_mapping_dict['exp_uid'] = current_experiment.exp_uid
    create_target_mapping_dict['exp_key'] = current_experiment.exp_key
    # Do this more cleanly. The problem is that mongoengine fields can't be json serialized.
    create_target_mapping_dict['target_blob'] = [mongo_to_dict(doc) for doc in current_experiment.target_set.targets]
    url = "http://"+config.NEXT_BACKEND_HOST+":"+config.NEXT_BACKEND_PORT+"/api/targets/createtargetmapping"
    response = requests.post(url,
                             json.dumps(create_target_mapping_dict),
                             headers={'content-type':'application/json'})
    # This should only be done if we can confirm that all the previous steps worked.
    current_experiment.set_status('running')
    return redirect(url_for('experiment._experiment', experiment_id = current_experiment.id))
コード例 #2
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def get_participant_responses():
    url = "http://" + current_user.next_backend_global_host + ":" + config.NEXT_BACKEND_GLOBAL_PORT
    app_resource = app_manager.get_app_resource(current_experiment.app_id)
    participant_responses = app_resource.get_formatted_participant_data(
        current_experiment, url)
    return "\n".join(participant_responses), 200, {
        'Content-Disposition': 'attachment',
        'Content-Type': 'text/csv; charset=utf-8'
    }
コード例 #3
0
def new_experiment_details(app_id):

    # initialize form with base form of NewExperimentForm
    class NewExperimentForm_params(NewExperimentForm):
        pass

    # query the app_manager for app specific params
    app_resource = app_manager.get_app_resource(app_id)

    # This is an html string containing the necessary app params.
    app_params_template, app_params_form = app_resource.get_experiment_params()
    
    # associate app_params_form to form.params
    NewExperimentForm_params.params = FormField(app_params_form)
    form = NewExperimentForm_params()

    # Update the target set selections
    target_set_names = [target.name for target in current_project.target_sets]

    # Is exposing the target id a potential security hole?
    target_set_ids = [target.id for target in current_project.target_sets]
    form.target_set.choices = zip(target_set_ids, target_set_names)    

    # check if form is validated
    if form.validate_on_submit():
        # do app specific processing, returns false if processing fails
        if form.params.process_experiment_params():
            name = form.name.data
            description = form.description.data
            instructions = form.instructions.data; 
            debrief = form.debrief.data
            params  = form.params.data
            target_set = form.target_set.data
            query_tries = form.query_tries.data
            query_duration = form.query_duration.data
            experiment = Experiment(
                name=name,
                description = description,
                instructions = instructions,
                debrief = debrief,
                app_id = app_id,
                params=params,
                target_set=target_set,
                query_tries = query_tries,
                query_duration = query_duration
            )
            experiment.save()
            

            # Add experiment to the current project
            current_project.add_experiment(experiment)
            return redirect(url_for('experiment._experiment', experiment_id=experiment.id))

    # render app params form template with the new composited form
    app_params_html = render_template(app_params_template, form=form.params)
    return render_template("new_experiment_details.html", form=form, app_params_html=app_params_html)
コード例 #4
0
def new_experiment_details(app_id):

    # initialize form with base form of NewExperimentForm
    class NewExperimentForm_params(NewExperimentForm):
        pass

    # query the app_manager for app specific params
    app_resource = app_manager.get_app_resource(app_id)

    # This is an html string containing the necessary app params.
    app_params_template, app_params_form = app_resource.get_experiment_params()

    # associate app_params_form to form.params
    NewExperimentForm_params.params = FormField(app_params_form)
    form = NewExperimentForm_params()

    # Update the target set selections
    target_set_names = [target.name for target in current_project.target_sets]

    # Is exposing the target id a potential security hole?
    target_set_ids = [target.id for target in current_project.target_sets]
    form.target_set.choices = zip(target_set_ids, target_set_names)

    # check if form is validated
    if form.validate_on_submit():
        # do app specific processing, returns false if processing fails
        if form.params.process_experiment_params():
            name = form.name.data
            description = form.description.data
            instructions = form.instructions.data
            debrief = form.debrief.data
            params = form.params.data
            target_set = form.target_set.data
            query_tries = form.query_tries.data
            query_duration = form.query_duration.data
            experiment = Experiment(name=name,
                                    description=description,
                                    instructions=instructions,
                                    debrief=debrief,
                                    app_id=app_id,
                                    params=params,
                                    target_set=target_set,
                                    query_tries=query_tries,
                                    query_duration=query_duration)
            experiment.save()

            # Add experiment to the current project
            current_project.add_experiment(experiment)
            return redirect(
                url_for('experiment._experiment', experiment_id=experiment.id))

    # render app params form template with the new composited form
    app_params_html = render_template(app_params_template, form=form.params)
    return render_template("new_experiment_details.html",
                           form=form,
                           app_params_html=app_params_html)
コード例 #5
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def getquery(app_id, exp_uid, widget_key):
    # get experiment
    requested_experiment = Experiment.objects(exp_uid=exp_uid)[0]
    # query the app_manager for app specific params
    app_resource = app_manager.get_app_resource(requested_experiment.app_id)
    # This is an html string containing the necessary app dashboard.
    app_query_html = app_resource.get_query(app_id=app_id,
                                            exp_uid=exp_uid,
                                            widget_key=widget_key)

    return app_query_html
コード例 #6
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def getquery(app_id, exp_uid, widget_key):
    # get experiment
    requested_experiment = Experiment.objects(exp_uid=exp_uid)[0]
    # query the app_manager for app specific params
    app_resource = app_manager.get_app_resource(requested_experiment.app_id)
    # This is an html string containing the necessary app dashboard.
    app_query_html = app_resource.get_query(
                            app_id=app_id,
                            exp_uid = exp_uid,
                            widget_key = widget_key)

    return app_query_html
コード例 #7
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def _experiment(experiment_id):
    set_experiment(experiment_id=experiment_id)
    # Frontend base url needed for stats and widgets
    next_backend_url = "http://"+current_user.next_backend_global_host+":"+config.NEXT_BACKEND_GLOBAL_PORT
    # Frontend url needed for queries
    next_frontend_url = "http://"+config.NEXT_FRONTEND_GLOBAL_HOST+":"+config.NEXT_FRONTEND_GLOBAL_PORT
    # query the app_manager for app specific params
    app_resource = app_manager.get_app_resource(current_experiment.app_id)
    # This is an html string containing the necessary app dashboard.
    app_dashboard_html = app_resource.get_experiment_dashboard(current_experiment)
    return render_template('experiment.html',
                           experiment_id=experiment_id,
                           next_backend_url=next_backend_url,
                           next_frontend_url=next_frontend_url,
                           app_dashboard_html=app_dashboard_html)
コード例 #8
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def _experiment(experiment_id):
    set_experiment(experiment_id=experiment_id)
    # Frontend base url needed for stats and widgets
    next_backend_url = "http://" + current_user.next_backend_global_host + ":" + config.NEXT_BACKEND_GLOBAL_PORT
    # Frontend url needed for queries
    next_frontend_url = "http://" + config.NEXT_FRONTEND_GLOBAL_HOST + ":" + config.NEXT_FRONTEND_GLOBAL_PORT
    # query the app_manager for app specific params
    app_resource = app_manager.get_app_resource(current_experiment.app_id)
    # This is an html string containing the necessary app dashboard.
    app_dashboard_html = app_resource.get_experiment_dashboard(
        current_experiment)
    return render_template('experiment.html',
                           experiment_id=experiment_id,
                           next_backend_url=next_backend_url,
                           next_frontend_url=next_frontend_url,
                           app_dashboard_html=app_dashboard_html)
コード例 #9
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def edit(experiment_id):
    # initialize form with base form of NewExperimentForm
    class NewExperimentForm_params(NewExperimentForm):
        pass

    # query the app_manager for app specific params
    app_resource = app_manager.get_app_resource(current_experiment.app_id)

    # This is an html string containing the necessary app params.
    app_params_template, app_params_form = app_resource.get_experiment_params()

    # associate app_params_form to form.params
    NewExperimentForm_params.params = FormField(app_params_form)
    form = NewExperimentForm_params(obj=current_experiment)

    # render app params form template with the new composited form
    app_params_html = render_template(app_params_template, form=form.params)

    # Update the target set selections
    target_set_names = [target.name for target in current_project.target_sets]

    # Is exposing the target id a potential security hole?
    target_set_ids = [target.id for target in current_project.target_sets]
    form.target_set.choices = zip(target_set_ids, target_set_names)

    if form.validate_on_submit():
        # update all fields
        # Why do we use updates instead of saves?
        print form.params.data
        current_experiment.update(set__name=form.name.data)
        current_experiment.update(set__description=form.description.data)
        current_experiment.update(set__instructions=form.instructions.data)
        current_experiment.update(set__debrief=form.debrief.data)
        current_experiment.update(set__params=form.params.data)
        current_experiment.update(set__target_set=form.target_set.data)
        current_experiment.update(set__query_tries=form.query_tries.data)
        current_experiment.update(set__query_duration=form.query_duration.data)
        return redirect(
            url_for('experiment._experiment',
                    experiment_id=current_experiment.id))

    return render_template("edit_experiment_details.html",
                           form=form,
                           app_params_html=app_params_html)
コード例 #10
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def run_experiment(experiment_id):
    # Get the appropriate app manager resource
    app_resource = app_manager.get_app_resource(current_experiment.app_id)
    # Run the experiment using this app resource
    url = "http://" + current_user.next_backend_global_host + ":" + config.NEXT_BACKEND_GLOBAL_PORT + "/api/experiment"
    response_dict = app_resource.run_experiment(current_experiment, url)

    if 'exp_uid' in response_dict.keys() and 'exp_key' in response_dict.keys():
        current_experiment.set_exp_uid(response_dict['exp_uid'])
        current_experiment.set_exp_key(response_dict['exp_key'])
        current_experiment.set_perm_key(response_dict['perm_key'])
    else:
        flash("Failed to change experiment status to running.")
        return redirect(
            url_for('experiment._experiment',
                    experiment_id=current_experiment.id))

    # Get the experiment info and store it in our current model
    response = requests.get(url + "/" + current_experiment.exp_uid + "/" +
                            current_experiment.exp_key)
    current_experiment.set_info(eval(response.text))

    # Now that we have an exp_uid and exp_key, we can do the target mapping. This needs some error handling here.
    create_target_mapping_dict = {}
    create_target_mapping_dict['app_id'] = current_experiment.app_id
    create_target_mapping_dict['exp_uid'] = current_experiment.exp_uid
    create_target_mapping_dict['exp_key'] = current_experiment.exp_key

    # Do this more cleanly. The problem is that mongoengine fields can't be json serialized.
    create_target_mapping_dict['target_blob'] = [
        mongo_to_dict(doc) for doc in current_experiment.target_set.targets
    ]
    url = "http://" + current_user.next_backend_global_host + ":" + config.NEXT_BACKEND_GLOBAL_PORT + "/api/targets/createtargetmapping"
    response = requests.post(url,
                             json.dumps(create_target_mapping_dict),
                             headers={'content-type': 'application/json'})
    # This should only be done if we can confirm that all the previous steps worked.
    current_experiment.set_status('running')
    return redirect(
        url_for('experiment._experiment', experiment_id=current_experiment.id))
コード例 #11
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def edit(experiment_id):
    # initialize form with base form of NewExperimentForm
    class NewExperimentForm_params(NewExperimentForm):
        pass

    # query the app_manager for app specific params
    app_resource = app_manager.get_app_resource(current_experiment.app_id)

    # This is an html string containing the necessary app params.
    app_params_template, app_params_form = app_resource.get_experiment_params()

    # associate app_params_form to form.params
    NewExperimentForm_params.params = FormField(app_params_form)
    form = NewExperimentForm_params(obj=current_experiment)

    # render app params form template with the new composited form
    app_params_html = render_template(app_params_template, form=form.params)

    # Update the target set selections
    target_set_names = [target.name for target in current_project.target_sets]

    # Is exposing the target id a potential security hole?
    target_set_ids = [target.id for target in current_project.target_sets]
    form.target_set.choices = zip(target_set_ids, target_set_names)

    if form.validate_on_submit():
        # update all fields
        # Why do we use updates instead of saves?
        print form.params.data
        current_experiment.update(set__name=form.name.data)
        current_experiment.update(set__description=form.description.data)
        current_experiment.update(set__instructions=form.instructions.data)
        current_experiment.update(set__debrief = form.debrief.data)
        current_experiment.update(set__params=form.params.data)
        current_experiment.update(set__target_set=form.target_set.data)
        current_experiment.update(set__query_tries=form.query_tries.data)
        current_experiment.update(set__query_duration=form.query_duration.data)
        return redirect(url_for('experiment._experiment', experiment_id=current_experiment.id))

    return render_template("edit_experiment_details.html", form=form, app_params_html = app_params_html)
コード例 #12
0
ファイル: experiment.py プロジェクト: lalitkumarj/NEXT-psych
def get_participant_responses():
    app_resource = app_manager.get_app_resource(current_experiment.app_id)
    participant_responses = app_resource.get_formatted_participant_data(current_experiment)
    return "\n".join(participant_responses), 200, {'Content-Disposition':'attachment'}
コード例 #13
0
ファイル: experiment.py プロジェクト: aybuketurker/NEXT-psych
def get_participant_responses():
    url = "http://"+current_user.next_backend_global_host+":"+config.NEXT_BACKEND_GLOBAL_PORT
    app_resource = app_manager.get_app_resource(current_experiment.app_id)
    participant_responses = app_resource.get_formatted_participant_data(current_experiment, url)
    return "\n".join(participant_responses), 200, {'Content-Disposition':'attachment', 'Content-Type': 'text/csv; charset=utf-8'}