Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babe-project

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babe-project

Basic Architecture for Browser-based experiments (https://github.com/babe-project)

  • 0.0.9
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

_babe project

basic architecture for browser-based experiments

Creating a _babe experiment with _babe

Option 1: Download the _babe project package

  1. Download the _babe .zip

  2. Unzip and place the folder (babe-base-master) in the libraries/ folder of your experiment.

Your experiment's structure should look something like this:

experiment/
    + libraries/
        + babe-babe-master
            + \_babe.full.min.js
            + \_babe.min.js
            + ...
            + ...

_babe.full.min.js includes the dependencies that _babe uses (jQuery, Mustache and csv-js). There is no need to install and import jQuery, Mustache and csv-js.

_babe.min.js includes only the _babe package, the dependencies should be installed separately for _babe to work.

  1. Import _babe in your index.html

the full version: <script src="libraries/babe-base-master/_babe.full.min.js></script>

no-dependencies version: <script src="libraries/babe-base-master/_babe.min.js></script>

  1. Use _babe styles:

import _babe-styles in your index.html:

<link rel="stylesheet" type="text/css" href="libraries/babe-base-master/_babe-styles.css">

Option 2: Install with npm

You need npm installed on your machine. Here is more information on how to install npm

If you have npm installed, run the following command from your experiment's directory

npm install babe-project --save

Dependencies:

  • jQuery
  • Mustache
  • csv-js

Include _babe in your main .html file:

<link rel="stylesheet" type="text/css"  href="node_modules/babe-project/_babe-styles.css">

<script src="node_modules/mustache/mustache.min.js"></script>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/csv-js/csv.js"></script>
<script src="node_modules/babe-project/_babe.min.js></script>

Usage

_babe Initialisation

Use _babeInit() to create a _babe experiment.

_babeInit takes an object as a parameter with the following properties:

  • views_seq - a list of view objects in the sequence you want them to appear in your experiment. more info
  • deploy - an object with information about the deploy methods of your experiment. more info
  • progress_bar - an object with information about the progress bars in the views of your experiment. more info

Sample _babeInit call:

$("document").ready(function() {
    _babeInit({
        views_seq: [
            intro,
            instructions,
            practice,
            main,
            thanks
        ],
        deploy: {
            "experimentID": "4",
            "serverAppURL": "https://babe-demo.herokuapp.com/api/submit_experiment/",
            "deployMethod": "debug",
            "contact_email": "YOUREMAIL@wherelifeisgreat.you",
            "prolificURL": "https://app.prolific.ac/submissions/complete?cc=ABCD1234" 
        },
        progress_bar: {
            in: [
                "practice",
                "main"
            ],
            style: "default",
            width: 150
        }
    });
});

Views in _babe

_babe views get inserted in an html element with id main, you need to have an html tag (preferrably div or main) with id="main"

Sample index.html

<!DOCTYPE html>
<html>
    <head>
        ...
        ...
        ...
    </head>

    <body>
        <-- ask the participants to enable JavaScript in their browser -->
        <noscript>This task requires JavaScript. Please enable JavaScript in your browser and reload the page. For more information on how to do that, please refer to
            <a href='https://enable-javascript.com' target='_blank'>enable-javascript.com</a>
        </noscript>

        <!-- views are inserted in here -->
        <main id='main'>
            Loading...
        </main>

    </body>
</html>
_babe views

_babe provides several ready-made views which you can access form the _babeViews object.

Each _babe view function takes an object as a parameter with the following properties:

  • trials - the number of trials this view will appear

    • trial type views also have:

      • trial_type - the name of the trial type that will be in the final data (for example 'main binary choice');
      • data - a list of trials
    • other views also have:

      • title - the title in the view
      • text - the text in the view
      • buttonText - the text on the button that takes the user to the newxt view

Sample use of _babe views:

// your_js_file.js

const intro = _babeViews.intro({
    title: 'Welcome!',
    text: 'This is an experiment!',
    buttonText: 'Begin the experiment',
    trials: 1
});

const instructions = _babeViews.instructions({
    title: 'Instructions',
    text: 'Choose an answer',
    buttonText: 'Next',
    trials: 1
});

const main = _babeViews.forcedChoice({
    trial_type: 'main',
    data: main_trials,
    trials: 4
});

const thanks = _babeViews.thanks({
    title: 'Thank you for taking part in this experiment!',
    trials: 1
});

$("document").ready(function() {
    _babeInit({
        views_seq: [
            intro,
            instructions,
            main,
            thanks
        ],
        deploy: {
            "experimentID": "4",
            "serverAppURL": "https://babe-demo.herokuapp.com/api/submit_experiment/",
            "deployMethod": "debug",
            "contact_email": "YOUREMAIL@wherelifeisgreat.you",
            "prolificURL": "https://app.prolific.ac/submissions/complete?cc=ABCD1234"

        },
        progress_bar: {
            in: [
                "main"
            ],
            style: "default",
            width: 100
        }
    });
});
Creating your own views

You can also create your own views.

The views are functions that return an object with the following properties:

  • trials: number - the number of trials this view appears
  • CT: 0 - current trial, always starts from 0
  • name: string - the name of the view (the progress bar uses the name)
  • render: function - a function that renders the view
    • pass CT and _babe as parameters to render()

Add the data gathered from your custom trial type views to _babe.trial_data

Sample custom trial type view:

_babeViews.pressTheButton = function(config) {
    const _pressTheButton = {
        name: config.name,
        title: config.title,
        render(CT, _babe) {
            let startTime = Date.now();

            const viewTemplate =
            `<div class='view'>
                {{# title }}
                <h1 class="title">{{ title }}</h1>
                {{/ title }}
                <button id="the-button">Press me!</button>
            </div>`;

            $("#main").html(
                Mustache.render(viewTemplate, {
                    title: this.title
                })
            );

            $('#the-button').on('click', function(e) {
                _babe.trial_data.push({
                    trial_type: config.trial_type,
                    trial_number: CT+1,
                    RT: Date.now() - startTime
                });
                _babe.findNextView();
            });
        },
        CT: 0,
        trials: config.trials
    };

    return _pressTheButton;
};

const mainTrial = _babeViews.pressTheButton({
    name: 'buttonPress',
    title: 'How quickly can you press this button?',
    trial_type: 'main',
    trials: 1
});

$("document").ready(function() {
    _babeInit({
        ...
        views_seq: [
            ...
            mainTrial,
            ...
        ],
        ...
    });
});

Sample custom info view:

_babeViews.sayHello = function(config) {
    const _sayHello = {
        name: config.name,
        title: config.title,
        render(CT, _babe) {
            const viewTemplate =
            `<div class='view'>
                {{# title }}
                <h1 class="title">{{ title }}</h1>
                {{/ title }}
                <button id="hello-button">Hello back!</button>
            </div>`;

            $("#main").html(
                Mustache.render(viewTemplate, {
                    title: this.title
                })
            );

            $('#hello-button').on('click', function(e) {
                _babe.findNextView();
            });
        },
        CT: 0,
        trials: config.trials
    };

    return _sayHello;
};

const hello = _babeViews.sayHello({
    name: 'buttonPress',
    title: 'Hello!?',
    trials: 1
});

$("document").ready(function() {
    _babeInit({
        ...
        views_seq: [
            ...
            hello,
            ...
        ],
        ...
    });
});

Deploy configuration

The deploy config has the following properties:

  • experimentID - the experimentID is needed to recover data from the babe server app. You receive the experimentID when you create the experiment using the babe server app
  • serverAppURL - if you use the _babe server app, specify its URL here
  • deployMethod - use one of 'debug', 'localServer', 'MTurk', 'MTurkSandbox', 'Prolific', 'directLink'
  • contact_email - who to contact in case of trouble
  • prolificURL - the prolific completion URL if the deploy method is "Prolific"

Progress Bar

_babe provides the option to include progress bars in the views specified in the progress_bar.in list passed to _babeInit.

You can use one of the following 3 styles (include pictues)

  • separate - have separate progress bars in each views declared in progress_bar.in
  • default - have one progress bar throughout the whole experiment
  • chunks - have a separate progress chunk for each view in progress_bar.in

Use progress_bar.width to set the width (in pixels) of the progress bar or chunk

Sample progress bar

$("document").ready(function() {
    _babeInit({
        ...
        progress_bar: {
            in: [
                "practice",
                "main"
            ], // only the practice and the main view will have progress bars in this experiment
            style: "chunks", // there will be two chunks - one for the practice and one for the main view
            width: 100 // each one of the two chunks will be 100 pixels long
        }
    });
});

FAQs

Package last updated on 09 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc