Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

store user's tapping time in limesurvey

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #242843 by ligiasilva
store user's tapping time in limesurvey was created by ligiasilva
Hello everyone!

I'd like to ask users to tap a button while listening to music and store the time interval between those tappings to later calculate their average tapping speed.
Previously I had asked for help here to create two buttons (start and stop) so that users could enter a time interval with them. They pressed start, counted some time, and then pressed stop. That created 2 date events stored as short text and the difference between them, in milliseconds, was calculated and stored as an equation in another question. This worked fine with this code, for the buttons

<p>How long do you think the music lasted for? Please use the start and stop buttons to recriate the time interval you think the music lasted for. </p>
<button class="btn btn-success" id="button1" onclick="dateevent1()" type="button">start</button><button class="btn btn-danger" id="button2" onclick="dateevent2()" type="button">stop</button><script type="text/javascript" charset="utf-8">
      $(document).ready(function(){

            // Verstecke den „Weiter“-Button
            //$('#button2').hide();
    });

function dateevent1(){
  var thisQuestion = $('#question{QID}');
  var date1 = Date.now();
  $('input[type=text]:eq(0)', thisQuestion).val(date1);
  $('#button1').hide();
  $('#button2').show();
}
function dateevent2(){
  var thisQuestion = $('#question{QID}');
  var date2 = Date.now();
  $('input[type=text]:eq(1)', thisQuestion).val(date2);
  $('#ls-button-submit').trigger('click'); 
}

</script>
<style type="text/css">#question{QID} .answer-container {
  display: none;
}
</style>

and this code for storing the difference in another equation question. The time was: {(reprodretrosptempo_SQ002-reprodretrosptempo_SQ001)} milliseconds.

Now, I tried to edit the first piece of code to create a new date event for each tapping. I don't need the system to calculate the average tapping speed, just store a new short answer for each tapping with the date. Is this possible? I assumed a variable N that would increase one point after recording each tapping, but does not seem to work. Can anyone help me with this? Here is the code I've edited for the tapping feature

<p>While you are listening tap on the 'TAP' button, to the pulse you feel that most naturally fits the music.</p>
<br />
<button id="tapbutton" onclick="tapping()" type="button">TAP</button>
<script type="text/javascript" charset="utf-8">
      $(document).ready(function(){

            // Verstecke den „Weiter“-Button
            //$('#button2').hide();
    });

function tapping(){
  var thisQuestion = $('#question{QID}');
  var date = Date.now();
  var n = 0;
  $('input[type=text]:eq(n)', thisQuestion).val(date);
  n++;
</script>


Thank you

Lígia

Please help us help you and fill where relevant:

Your LimeSurvey version:  LimeSurvey Community Edition
Version 3.28.49+230215
Own server or LimeSurvey hosting:
Survey theme/template:
==================
(Write here your question/remark)

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #242873 by tpartner
Replied by tpartner on topic store user's tapping time in limesurvey
How many taps will you allow? If using a multiple-short-text, you will need to have a sub-question for every tap.

Can you attach a small sample survey (.lss file) containing only the relevant question?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #242876 by ligiasilva
Replied by ligiasilva on topic store user's tapping time in limesurvey
Hi tpartner, thanks for replying.

In the best scenario I'd like to leave the number of tappings open, with a minimum of 5 required, and let the total number of tappings be stored as a dynamic response to the user's choice. Would any other kind of question allow that? Or I can just use multiple short answers, create many short answers, and assume they'd never use them all. The idea is to have them tap while listening to a short audio (about 30 sec maximum, at 120 bpm). I would never expect much more than 120 tappings, even assuming they tap to double the musical tempo.

In the attached file is the group of questions I need to do.

Also, quick question, could you help me on why the css styling to center the tap button does not work?

Thanks for the help!

 

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #242880 by tpartner
Replied by tpartner on topic store user's tapping time in limesurvey
If you use separate sub-questions you will need to predefine a sub-question for every possible tap. This could take up many columns in the database.

An alternative would be to load the timestamps, separated by commas into a long-text question.

Regarding the button style, it is invalid CSS syntax.

This:

Code:
<style type="text/css">
 
  #tapbutton {
    Text-align: centre;
  }
</style>

Should be this:

Code:
<style type="text/css">
 
  #tapbutton {
    text-align: center;
  }
</style>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #242934 by ligiasilva
Replied by ligiasilva on topic store user's tapping time in limesurvey
Hello tpartner

Thanks for the help. 
Yes, that would become a huge database with a lot of columns.
So I changed it to a long free text. But I think I must change something else as it isn't storing anything. I don't know how to refer to the input area in the long text answer, I guess it may have to do with the  $('input[type=text]:eq(0)', thisQuestion).val(date); line but I don't know how to do this. I need that input field to be added a new date after each tapping with something like a comma separating them, as you suggested (not the later tapping replacing the previous ones).
Could you help me with this? Sorry to bother and thanks already!

Now the CSS worked. Created a div to place the button as what I really wanted was to center the button, not the text inside it. Thanks a lot!

I'm adding the survey again.
Here is what I have now in that question:

<p>While you are listening tap on the 'TAP' button, to the pulse you feel that most naturally fits the music.</p>
 

<div id="buttonplacement">
  <button id="tapbutton" onclick="tapping()" type="button">TAP</button>
</div>
<script type="text/javascript" charset="utf-8">
      $(document).ready(function(){

            // Verstecke den „Weiter“-Button
            //$('#button2').hide();
    });

  function tapping() {
  var thisQuestion = $('#question{QID}');
  var date = Date.now();
  $('input[type=text]:eq(0)', thisQuestion).val(date);
  }
</script>
  
</script>
<style type="text/css">#question{QID} .answer-container {
  display: none;}
  #buttonplacement {
  text-align: center;
 }
</style>

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #242936 by tpartner
Replied by tpartner on topic store user's tapping time in limesurvey
I am away from my computer today so it will be Monday at least.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #242939 by ligiasilva
Replied by ligiasilva on topic store user's tapping time in limesurvey
No problem, of course. You're already doing a lot. Take your time, and have a nice weekend!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #242968 by tpartner
Replied by tpartner on topic store user's tapping time in limesurvey
This script will load the textarea with a comma-separated list of the timestamps as the button is clicked.

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
    var thisTextarea = $('textarea.form-control:eq(0)', thisQuestion);
 
    // Initiate an array for the timestamps
    var timestamps = [];
    if($.trim($(thisTextarea).val()) != '') {
      timestamps = $.trim($(thisTextarea).val()),split(',');
    }    
 
    // Listener on the button
    $('#tapbutton').on('click', function(e) {
      var newTimeStamp = Date.now();
 
      // Add the new timestamp to the array
      timestamps.push(newTimeStamp);
 
      // Load the question textarea
      $(thisTextarea).val(timestamps).trigger('keyup');
    });
  });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...8669.lss
File Size:20 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #243119 by ligiasilva
Replied by ligiasilva on topic store user's tapping time in limesurvey
Thanks a lot, tpartner! It seems to be working fine, great. I'll integrate your solution into the whole experiment. I'd never find this solution in time for my project as it is way more complicated than I imagined at the beginning. Really thank you very much.

My expertise is more in music, so if I can in any situation help you (and Joffm!, who already helped me with another issue in this PhD project) with any musical issue please let me know. I'd be glad to retribute you both the help!

Take care, thanks

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
2 years 3 weeks ago #243376 by DenisChenu
Replied by DenisChenu on topic store user's tapping time in limesurvey
I am always amazed by Tony who offers professional solutions for free on the forum.

Thanks a lot Tony!

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose