Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Results in php script

Hi all,

I have a concern with the results of the experiment when is finished. The original experiment has a php script which says that:

<?php
// the $_POST[] array will contain the passed in filename and filedata
// the directory "data" must be writable by the server
$filename = "../data/".$_POST['filename'];
$data = $_POST['filedata'];
// write the file to disk
file_put_contents($filename, $data,FILE_APPEND);
?>


in the experiment file, it says that:

function that appends data to an existing file (or creates the file if it does not exist)

  function appendData(filename, filedata) {

    $.ajax({ // make sure jquery-1.7.1.min.js is loaded in the html header for this to work

      type: 'post',

      cache: false,

      url: 'php/save_data_append.php', // IMPORTANT: change the php script to link to the directory of your server where you want to store the data!

      data: {

        filename: filename,

        filedata: filedata

      },

    });

  };


According what I read in the JATOS web site

I have to append result data to the already sent

var resultData = { "a": 123, "b": 789, "c": 100};
jatos.appendResultData(resultData);

However, I think I am not doing it properly because I am still having error at the end of the experiment.

Does anybody has experimented something similar? How did you solved it?

Thanks a lot in advance for your help!

Comments

  • Hi!

    Can you please give us a bit more information so we can help you better:

    • What is the version of your JATOS?
    • What kind of error do you get? Where do you see those errors (Browser Dev Tools, JATOS, JATOS' logs)? Is there some error message you can post here?
    • Can you post the rest of your experiment's code or at least the part that involves jatos.js?

    Best,

    Kristian

  • Hi Kristian,

    Thank you very much for your answer and for your help!

    The version of JATOS is 3.5.5

    The error in the file I export when the experiment is completed (.txt file) aparently is because the experiment uses a php script to send the data back to the server after every trial.

    The part of the experiment which involves JATOS is the head:

    <head> <!-- import the jsPsych core library, specific plugins, jquery and some other scripts-->
    
      <title>Stop Signal Task</title> <!-- defines a title in the browser tab -->
    
      <script src="/assets/javascripts/jatos.js"></script>
    
      <script src="js/jspsych-6.0.5/jspsych.js"></script> <!-- jsPsych core library -->
    
      <script src="js/jspsych-6.0.5/plugins/jspsych-instructions.js"></script> <!-- plugins define specific tasks, e.g., presenting instructions -->
    
      <script src="js/jspsych-6.0.5/plugins/jspsych-html-keyboard-response.js"></script>
    
      <script src="js/jspsych-6.0.5/plugins/jspsych-survey-text-beta-6.1.js"></script> <!-- beta 6.1 version has the 'input required' function for text fields -->
    
      <script src="js/jspsych-6.0.5/plugins/jspsych-survey-multi-choice.js"></script>
    
      <script src="js/jspsych-6.0.5/plugins/jspsych-call-function.js"></script>
      <script src="js/jspsych-6.0.5/plugins/jspsych-fullscreen.js"></script>
    
      <script src="js/jquery-1.7.1.min.js"></script> <!-- the jquery library is used to communicate with the server (to store the data) through "AJAX" and PHP -->
    
      <script src="js/bowser.js"></script> <!-- a browser and operating system detector -->
    
      <script src="js/sprintf.js"></script> <!-- format variables in a string, used for customizable feedback strings in which the variables are not yet declared -->
      <script src="js/custom-stop-signal-plugin.js"></script> <!-- custom plugin for the main stop-signal trial based on the image-keyboard-response plugin -->
    
      <script src="js/jspsych-detect-held-down-keys.js"></script> <!-- custom plugin for detecting if a key is being held down -->
      <script src="configuration/experiment_variables.js"></script> <!-- parameters to configure the experiment -->
    
      <script src="configuration/text_variables.js"></script> <!-- holds all the text variables for easy modification/translation -->
    
      <link href="js/jspsych-6.0.5/css/jspsych.css" rel="stylesheet" type="text/css"></link> <!-- standard jsPsych css stylesheet -->
    
    </head>
    

    and at the end of the experiment.

     on_finish: function() {
    
          var resultJson = jsPsych.data.get().json();
          jatos.submitResultData(resultJson, jatos.startNextComponent);
    
          if (redirect_onCompletion){
    
           setTimeout("location.href = '" + redirect_link + "';",redirect_timeout); // redirect to another URL with a certain delay, only when redirect_onCompletion is set to 'true'
    
          }
        },
    
      })
    });
    
    </script>
    
    
  • krikri
    edited August 2020

    Hi!

    The error in the file I export when the experiment is completed (.txt file) aparently is because the experiment uses a php script to send the data back to the server after every trial.

    I'm confused: do you still use a PHP script or did you moved from PHP to JATOS? What is the error message in this .txt file?

    Then in your code: It's most likely not necessary to redirect in your on_finish - jatos.js does this for you if you set it up properly. Since you are using jsPsych I assume your experiment has only one component:

    jatos.onLoad(function() {
      jsPsych.init( {
        // do your experiment
    
        on_finish: function() {
          var resultJson = JSON.stringify(jsPsych.data.getData());
          jatos.submitResultData(resultJson, jatos.endStudy);
        }
      }
    });
    

    Then you can set up your redirect URL in your study properties in JATOS' UI: http://www.jatos.org/End-page-after-your-study-finished.html#3-study-properties-end-redirect-url-since-jatos-v351. Alternatively you can use jatos.endStudyAndRedirect: http://www.jatos.org/jatos.js-Reference.html#jatosendstudyandredirect.

    Best,

    Kristian

  • Thank you again Kristian for your help,

    The error It shows me is: Expression.Error: We cannot convert a value of type Record to type Text.

    I don´t know if I still using the PHP. If I am doing that, should I have to modify something here?

    function that appends data to an existing file (or creates the file if it does not exist)
    
      function appendData(filename, filedata) {
    
        $.ajax({ // make sure jquery-1.7.1.min.js is loaded in the html header for this to work
    
          type: 'post',
    
          cache: false,
    
          url: 'php/save_data_append.php', // IMPORTANT: change the php script to link to the directory of your server where you want to store the data!
    
          data: {
    
            filename: filename,
    
            filedata: filedata
    
          },
    
        });
    
      };
    

    or in the PHP script?

    <?php
    // the $_POST[] array will contain the passed in filename and filedata
    // the directory "data" must be writable by the server
    $filename = "../data/".$_POST['filename'];
    $data = $_POST['filedata'];
    // write the file to disk
    file_put_contents($filename, $data,FILE_APPEND);
    ?>
    

    Thank you again!

  • Hi!

    I'm not sure I understand your setup. You most likely need either JATOS or PHP scripts and not both. If you just want to send your experiment's result data to a server for safe keeping, both a valid ways. Unfortunately I have no clue about PHP.

    Best,

    Kristian

  • edited August 2020

    Hi, to add to this:

    What you want to do is append the results from each trial to the results stored in JATOS. As Kristian said, you don't need an extra PHP script for this. JATOS provides a javascript library (jatos.js) that does this for you.

    Because you have a jsPsych study, the best way to do this is to tell jsPsych to do the same couple of lines of code after each trial finishes (https://www.jspsych.org/overview/callbacks/#on_trial_finish). I'm no jsPsych expert but it will probably look something like this:

    jsPsych.init({
        timeline: timeline,
        //other options
        on_data_update: etc
        on_trial_finish: function(){
          var thisTrialsData = jsPsych.data.getLastTrialData();
          jatos.appendResultData(thisTrialsData);
        }
        // more other options
    }}
    

    If that works, please get rid of all the php scripts and calls to them, because they will just make everything more confusing. Also keep in mind two things:

    1. If you also include what Kristian recommended (this snippet here):
    on_finish: function() {
          var resultJson = JSON.stringify(jsPsych.data.getData());
          jatos.submitResultData(resultJson, jatos.endStudy);
        }
    

    you might end up with duplicate information (please try).

    1. When you append data after every trial (depending on how long your trials are), you have a lot of traffic of sending data to the server. Sometimes, slow or unstable internet connections can lead to problems here. JATOS has a timeout: if after trying to send the data for 15 seconds it doesn't succeed, it will re-try up to 4 times. If you're sending hundreds of trials like this you might end up having a queue of unsent data that will make your code (appear to) freeze. If this is the case, an option is to append data every 10 trials or so.
  • Hi @elisa and @kri

    I want to say thank you for all the help you provided me. I followed all the tips you gave me and now the experiment works good!

    Thank you again. All the Best!

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games