Actions

StatFunctions: Difference between revisions

From LimeSurvey Manual

m (Detail on true/false)
(6 intermediate revisions by the same user not shown)
Line 5: Line 5:
Functions for the expression manager to count some statistics data :
Functions for the expression manager to count some statistics data :


* statCount(QuestionCode.sgqa[, submitted = 1]) : count the number of already submitted answered questions by QuestionCode. You can count the number of submitted (= completed) surveys with statCount('sid') for example.
* statCount(QuestionCode.sgqa[, submitted = 1][, self = true]) : count the number of already submitted answered questions by QuestionCode. You can count the number of submitted (= completed) surveys with statCount('sid') for example.
* statCountIf(QuestionCode.sgqa, value[, submitted = 1]) : count the number of responses where answer to question QuestionCode equals value. The comparison uses [https://www.yiiframework.com/doc/api/1.1/CDbCriteria#compare-detail Yii compare], you can use <, >, >=, <=, <> operator at start of your value.
* statCountIf(QuestionCode.sgqa, value[, submitted = 1][, self = true]) : count the number of responses where answer to question QuestionCode equals value. The comparison uses [https://www.yiiframework.com/doc/api/1.1/CDbCriteria#compare-detail Yii compare], you can use <, >, >=, <=, <> operator at start of your value.


You can find an example of the usage of these 2 functions in: [https://github.com/LimeSurvey/LimeSurvey/blob/master/tests/data/surveys/survey_archive_statCountFunctionsTest.lsa survey_archive_statCountFunctionsTest] inside the test directory.
You can find an example of the usage of these 2 functions in: [https://github.com/LimeSurvey/LimeSurvey/blob/master/tests/data/surveys/survey_archive_statCountFunctionsTest.lsa survey_archive_statCountFunctionsTest] inside the test directory.
Line 14: Line 14:
This plugin uses the [[ExpressionManagerStart]] plugin and it creates two functions. These 2 functions don't use javascript, so the check is done only when the respondent moves ahead in the survey.
This plugin uses the [[ExpressionManagerStart]] plugin and it creates two functions. These 2 functions don't use javascript, so the check is done only when the respondent moves ahead in the survey.


Expression script don't have true and false as reserved word, then this 12 strings are checked as variables name. You must use 1, 0 or the result of an expression for the second parameter. remind than "false" is evaluated a true in boolean.
Expression script don't have true and false as reserved word, then this strings are checked as variables name. You can use 1, 0 or the result of an expression for the second parameter. remind than "false" is evaluated a true in boolean.


{{Alert|Before using these functions : the plugin must be activated in [[Plugin_manager#General|Plugin Manager]].}}
{{Alert|Before using these functions : the plugin must be activated in [[Plugin_manager#General|Plugin Manager]].}}
Line 22: Line 22:
* count number of submitted response : {statCount("id")}
* count number of submitted response : {statCount("id")}
* count number of responses (submitted or not) : {statCount("id", 0)}
* count number of responses (submitted or not) : {statCount("id", 0)}
* number of responses where respondent stopped at page 1 : {statCountIf("lastepage", 1, 0)}
* number of responses where respondent stopped at page 1 : {statCountIf("lastpage", 1, 0)}
* number of submitted responses with startlanguage "en" : {statCountIf("startlanguage", "en", 1)}
* number of submitted responses with startlanguage "en" : {statCountIf("startlanguage", "en", 1)}
* number not completed responses to this survey : {sum(statCount("id", 0),statCount("id")*-1)}
* number not completed responses to this survey : {sum(statCount("id", 0),statCount("id")*-1)}
* number of responses submitted in 2022 : {statCountIf("submitted", ">=2022-01-01")}
* number of responses submitted in 2022 : {statCountIf("submitted", ">=2022-01-01")}
* number of submitted responses with Y at a YesNo question title {statCountIf(YesNo.sgqa, "Y")}
* number of responses (submitted or not) with Answer A1  at a Q01 question title {statCountIf(Q01.sgqa, "A1", 0)}
* Validate unicity on a short text question (not submitted) {statCountIf(self.sgqa, self.NAOK, 0, 1)} (only when move next page)


[[Category:Plugins]][[Category:Core Plugins]]
[[Category:Plugins]][[Category:Core Plugins]]

Revision as of 18:39, 11 October 2022

 Hint: This features is available starting in version 4.1.0


Usage

Functions for the expression manager to count some statistics data :

  • statCount(QuestionCode.sgqa[, submitted = 1][, self = true]) : count the number of already submitted answered questions by QuestionCode. You can count the number of submitted (= completed) surveys with statCount('sid') for example.
  • statCountIf(QuestionCode.sgqa, value[, submitted = 1][, self = true]) : count the number of responses where answer to question QuestionCode equals value. The comparison uses Yii compare, you can use <, >, >=, <=, <> operator at start of your value.

You can find an example of the usage of these 2 functions in: survey_archive_statCountFunctionsTest inside the test directory.

This plugin uses the ExpressionManagerStart plugin and it creates two functions. These 2 functions don't use javascript, so the check is done only when the respondent moves ahead in the survey.

Expression script don't have true and false as reserved word, then this strings are checked as variables name. You can use 1, 0 or the result of an expression for the second parameter. remind than "false" is evaluated a true in boolean.

  Before using these functions : the plugin must be activated in Plugin Manager.


Example

  • count number of submitted response : {statCount("id")}
  • count number of responses (submitted or not) : {statCount("id", 0)}
  • number of responses where respondent stopped at page 1 : {statCountIf("lastpage", 1, 0)}
  • number of submitted responses with startlanguage "en" : {statCountIf("startlanguage", "en", 1)}
  • number not completed responses to this survey : {sum(statCount("id", 0),statCount("id")*-1)}
  • number of responses submitted in 2022 : {statCountIf("submitted", ">=2022-01-01")}
  • number of submitted responses with Y at a YesNo question title {statCountIf(YesNo.sgqa, "Y")}
  • number of responses (submitted or not) with Answer A1 at a Q01 question title {statCountIf(Q01.sgqa, "A1", 0)}
  • Validate unicity on a short text question (not submitted) {statCountIf(self.sgqa, self.NAOK, 0, 1)} (only when move next page)