Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Average of a group

Average of a group 3 years 3 months ago #64459

  • sofos
  • sofos's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
hi, im new in limesurvey, first sorry for my poor english, im building a survey that measure the level of quality of a hospital. In order to do this there are question divided by groups, the user that fill the survey test every question from 1 to 5 (1 poor 5 excelent). I do this and works well. The issue is that i need to evaluate the average of every group. in the irc chat they sugest me to do a hiden question calculate the average and fill it wit that value, i search in the forum and i found
this two post.

second post
and

primer post

but im totally lost with all that code, im not js programmer.

i attach my test survey.

thanks in advance.

File Attachment:

File Name: limesurvey_survey_81925.lss
File Size: 40 KB
Last Edit: 3 years 3 months ago by sofos.
The administrator has disabled public write access.

Re: Average of a group 3 years 3 months ago #64496

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
1) Set up your survey to use JavaScript.

2) Add a short-text question to each group (we'll hide them with JavaScript).

3) Add the following script to the source of each short-text question.

The script hides the short-text question and, when the next/submit button is clicked, loads it with an average of checked radio values. This script will work with multiple arrays in a group but there can only be one short-text per group.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Hide the hidden question
		$('.text-short').hide();
 
		// Interrupt the Next/Submit function
		$('form#limesurvey').submit(function(){
 
			// Override the built-in "disable navigation buttons" feature
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
			// Calculate an average score from the checked radio values
			var score = 0;
			$('tbody[id^="javatbd"] input.radio:checked').each(function(i){
				score = score + Number($(this).val());  
			});
			score = score / $('tbody[id^="javatbd"] input.radio:checked').length;
 
			// Load the hidden score question
			$('.text-short input.text').val(score);
 
			return true;
 
		});
 
	});
 
</script>

I have modified group 1 of your survey to include a short-text and the script above. You can copy it to the other groups.

File Attachment:

File Name: limesurvey_survey_81925_TONY.lss
File Size: 47 KB
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 3 months ago by tpartner.
The administrator has disabled public write access.

Re: Average of a group 3 years 3 months ago #64509

  • sofos
  • sofos's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
hi, thank you for the fast replay, you are a monster :), but when i generate the graphics in the report,it just show the number of surveys submited. is there a way to fix this?, thanks again :)
Last Edit: 3 years 3 months ago by sofos.
The administrator has disabled public write access.

Re: Average of a group 3 years 3 months ago #64510

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
I didn't realize you were trying to use the built-in reporting. I assumed you were going to analyze with SPSS or something. You can't display reporting on text questions.

The only way to do it in LS reporting would be to populate hidden radios or dropdowns with the average. It gets kind of messy - the hidden questions would need all possible averages..

Additionally, I found an error in my script (it gives a total, not an average). Use this one.

File Attachment:

File Name: limesurvey_survey_81925_TONY_v2.lss
File Size: 47 KB
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Average of a group 3 years 3 months ago #64511

  • sofos
  • sofos's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
oh thx, for replay, i only need integers numbers from 1 to 5 to evaluate the quality of service, i don't need real numbers just 5 posibilities. sorry i didn't exlplain this at the beginning. how i populate the hidden radios?, thx in advance.
The administrator has disabled public write access.

Re: Average of a group 3 years 3 months ago #64512

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
So, you want to round the average to the nearest whole integer?
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Average of a group 3 years 3 months ago #64513

  • sofos
  • sofos's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
it's the way we measure the quality of a service. just integers.
for example:
1.poor
2.bad
3.aceptable.
4 good
5 very good.
The administrator has disabled public write access.

Re: Average of a group 3 years 3 months ago #64528

  • sofos
  • sofos's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
hi, i just change some parts of your code, searching in the template.css (with grep) i just change text-short to choice-5-pt-radio. And watching in the code you kindly post here i change input.text with input.radio, my question is where i found all properties like input.text, input.radio?, many thanks for all help that you provided to me.
Group 1 score <script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Hide the hidden question
		$('.choice-5-pt-radio').hide();
 
		// Interrupt the Next/Submit function
		$('form#limesurvey').submit(function(){
 
			// Override the built-in "disable navigation buttons" feature
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
			// Calculate a score from the checked radio values
			var score = 0;
			$('tbody[id^="javatbd"] input.radio:checked').each(function(i){
				score = score + Number($(this).val()); 
			});
                        score = score / $('tbody[id^="javatbd"] input.radio:checked').length;
                        score = Math.round( score );
			// Load the hidden score question
			$('.choice-5-pt-radio input.radio').val(score);
 
			return true;
 
		});
 
	});
 
</script>
Last Edit: 3 years 3 months ago by sofos. Reason: ortography, im not english speaker
The administrator has disabled public write access.

Re: Average of a group 3 years 3 months ago #64532

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
...my question is where i found all properties like input.text, input.radio?
You can use a tool like Firebug for Firefox to explore the elements.

If you replace the hidden short-text with a hidden 5-point-radio, you can use this script. The script rounds the average to the nearest integer and the clicks the corresponding radio button in the 5-point-radio.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Hide the hidden question
		$('.text-short').hide();
 
		// Interrupt the Next/Submit function
		$('form#limesurvey').submit(function(){
 
			// Override the built-in "disable navigation buttons" feature
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
			// Calculate an average score from the checked radio values
			var score = 0;
			$('tbody[id^="javatbd"] input.radio:checked').each(function(i){
				score = score + Number($(this).val());  
			});
			score = Math.round(score / $('tbody[id^="javatbd"] input.radio:checked').length);
 
			// Load the hidden score question
			$('.choice-5-pt-radio input.radio[value="'+score+'"]').attr('checked', 'checked');
 
			return true;
 
		});
 
	});
 
</script>

And the updated survey:

File Attachment:

File Name: limesurvey_survey_81925_TONY_v3.lss
File Size: 42 KB
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: sofos

Re: Average of a group 3 years 3 months ago #64597

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
In LimeSurvey 1.92, there will be an easier way that will work for any question type.

Say you have 9 questions, named q1-q9. To get the average of them, you would create a new Question of type Equation (let's call it 'avg'). If you want to compute a running average and either show it on the same or a subsequent page, you would use this equation (within the Question text field)
{round(q1.NAOK,q2.NAOK,q3.NAOK,...,q9.NAOK)}

If you only want avg to be computed once all of the questions are answered, you would use the equation
{round(q1,q2,q3,...,q9)}

You could then show the value by, for example, creating a new Question called 'report' which provides the score and a message of whether it is better, worse, or equal to average:
Your average score is {ans}.  That is {if(ans>3,'better than average',if(ans<3),'worse than average','average')}.

For more information, see this discussion about Expression Manager
Last Edit: 3 years 3 months ago by TMSWhite.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.433 seconds
Donation Image