Пропустить остаток времени, если участник дает n правильных ответов (jspsych) - PullRequest
0 голосов
/ 14 февраля 2020

У меня есть n испытаний в сроки. Правильные ответы записываются как атрибуты данных. Я хочу пропустить оставшуюся часть графика, если участник предоставил фиксированное количество правильных ответов. Это требует условного, но мой не работает.

var if_node = {
    timeline: [test_procedure],
    conditional_function: function(){
          var data = jsPsych.data.get()
          var correct_count = data.filter({correct: true}).count();
          return correct_count < 2
          }
    }

Воспроизводимый код ниже (нужен jspsych-6).

<!DOCTYPE html>
<html>
  <head>
    <title>My experiment</title>
    <script src="jspsych-6/jspsych.js"></script>
    <script src="jspsych-6/plugins/jspsych-html-keyboard-response.js"></script>
    <script src="jspsych-6/plugins/jspsych-html-button-response.js"></script>
    <link href="jspsych-6/css/jspsych.css" rel="stylesheet" type="text/css"></link>
  </head>
  <body></body>
  <script>

    /* create timeline */
    var timeline = [];

    /* test trials */

    var test_stimuli = [
      { word: "table", data: { false_word: '0' } },
      { word: "tfble", data: { false_word: '1' } },
      { word: "tablw", data: { false_word: '1' } }
    ];

    var trial = {
        type: ["html-button-response"],
        stimulus: jsPsych.timelineVariable('word'),
        choices: ["real", "fake"],
        margin_vertical: "0px",
        margin_horizontal: "8px",
        response_ends_trial: true,
        post_trial_gap: [500],
        data: jsPsych.timelineVariable('data'),
        on_finish: function(data){
          data.correct = data.false_word == data.button_pressed
        }
    };

    var test_procedure = {
      timeline: [trial],
      timeline_variables: test_stimuli
    }
    //timeline.push(test_procedure);

    var if_node = {
    timeline: [test_procedure],
    conditional_function: function(){
          var data = jsPsych.data.get()
          var correct_count = data.filter({correct: true}).count();
          return correct_count < 2
          }
    }

    timeline.push(if_node);

    /* start the experiment */
    jsPsych.init({
      timeline: timeline,
      on_finish: function() {
        jsPsych.data.displayData();
      }
    });
  </script>
</html>
...