表達式管理器抽樣調查
From LimeSurvey Manual
簡介
學習如何使用表達式管理器的最佳方法是使用工作示例並根據你的需要進行修改。
你可以在下面找到一組樣本調查,以演示(和測試)表達式管理器是如何用於增強你的調查。這些調查可以在安裝目錄下的docs/demosurveys文件夾中找到。
相關性,裁剪和方程式
綜述
以下示例計算每個受訪者的BMI(身體質量指數)。請參閱下面的示例中演示的功能。
EM功能演示
- 相關性 - 支持強大的條件邏輯;
- Piping / Tailoring - 提供管道或定製答案和問題元數據的能力;
- 動態裁縫 - 請注意,當您回答問題時,頁面上的報告會發生變化。
- 'Micro-Tailoring - 使用if()語句對句子和報告進行條件剪裁
- 方程式 - 一個新的問題類型,它允許您進行計算並將結果存儲在數據庫中,即使計算被隱藏
- 條件驗證 - 驗證諸如最小允許值之類的標準可以是有條件的 - 例如,基於等式。
截圖
此示例計算身體質量指數,計算你的體重和身高,以確定你是否超重。請注意,最初,你看到的只有四個強制性問題:
輸入信息後(你可以選擇是使用公制還是非公制單位),你會看到一份量身定製的報告,總結你輸入的內容,並告訴你的體重狀況:
下面是一個不同的示例,使用非公制單位來顯示結果如何動態變化:
在內部級別隱藏|方程式問題,將數據轉換為公制(如果需要),將公制高度、權重、BMI和權重狀態存儲在數據庫中,而無需自定義JavaScript 。
你可以在下一組示例中看到如何在定製報告中使用數學和其他功能。這是在輸入任何數據之前頁面的樣子。如果沒有輸入(或非數字)數據,則顯示空白單元格的條件邏輯,而不是顯示「NaN」或「除以零」。
輸入數字後,頁面上的報告會更改以顯示正在執行的計算及其結果。
此抽樣調查中還有許多其他示例。例如,下面的屏幕截圖顯示了你可以填寫動態相關性頁面的幾種方法之一。作為幫助文本說明,嘗試不同的年齡,特別是不合理的響應組合,以查看底部生成的有趣消息。另請注意,如果你說你有多個孩子,則會顯示「我希望你喜歡和X個孩子一起玩」,而不是說「我希望你喜歡和孩子一起玩」。這顯示了如何輕鬆地微調句子,使其與主題的性別和/或數量相匹配。你甚至可以根據性別和數量輕鬆地結合動詞和拒絕名詞。
下載
要訪問調查樣本,請單擊以下鏈接:LS3_em_tailoring.zip。
樣本人口普查
綜述
這是一個人口普查示例,詢問你家中有多少人。
It demonstrates how group-level relevance can make it easier to implement a "loop" of questions. After creating the group for Person 1, I exported the group. Since I used qcode variable names like p1_name instead of the SGQA code, I could use a text editor to quickly edit and re-import the group several times (e.g., it took about 10 seconds to edit and re-import each repeating group, ensuring that all variables had unique variables names and that the group-level logic was correct).
你還可以使用複製問題功能,但它不會像上面建議的那樣快。
這還顯示了如何防止完成消息出現,直到調查真正完成(例如,當所有需要的組完成時)。
EM功能演示
- 群組級別相關性 - 後續群組(人員1-5)僅顯示指定的同居者數量;
- 裁剪 - 最終報告總結每個同居者的人口統計數據;
- 漸進式問題顯示 - 無論是分組還是一體化模式,後續問題只會在前面的問題得到解答後立即顯示。
截圖
該調查生成一份定製報告,顯示指定數量的同居者的人口統計數據:
如果切換到一次一個問題模式,你會看到索引會定製問題。由於用戶說該人是女性,因此詢問「她的名字是什麼」。自從我們回答「瑪麗」之後,接下來的問題是「瑪麗多大了」?
下載
要下載調查樣本,請單擊此處:LS3_group_relevance.zip。
級聯陣列過濾器
綜述
該調查基於Joy Lane Research,LLC提供的調查設計。
截圖
以下請注意:
- Q02僅顯示在Q01中檢查的產品組(通過使用array_filter)
- Q02還顯示「另一產品」,文本輸入到Q01中的「其他電子」字段
- Q04僅顯示已檢查的Q02產品(因此陣列濾波器級聯)
- Q05僅顯示Q02中未在Q02中檢查的產品(使用級聯array_filter_exclude)
下載
點擊以下鏈接下載上述示例:LS2_cascading_array_filter survey example。
使用所有問題類型和屬性的管道/裁剪
綜述
如果你對如何命名變量(SGQA與Qcodes)感到困惑,那麼你並不孤單。雖然主要文檔描述了如何編寫Qcode變量名,但沒有什麼比在工作演示中看到它更好的了。此調查顯示了如何使用表達式管理器訪問問題屬性和響應。
內容
- 每個問題類型的示例
- 包含所有可以使用「其他」的問題類型,以便你可以看到它如何影響變量命名
- 接受默認值的所有問題類型的默認值
- 裁剪- 顯示所有16個可用EM點符號後綴的頁面外和頁面外報告。
- 這些報告顯示所有當前輸入的數據(因此,向你展示如何為用戶生成自己的可打印報告,而不是打印 - 答案屏幕)
- 正確的Qcode和SGQA命名所有變量
截圖
這是一項巨大的調查,因此我們選擇不包括屏幕截圖。相反,請下載並使用它。
下載
點擊以下鏈接下載調查:LS3_EM_question_attributes.lss
傳統驗證,重新設想
綜述
這演示了使用表達式的所有驗證類型以及它們如何影響支持驗證的每個問題類型。在許多情況下,驗證提示開始隱藏,僅在問題未通過驗證標準時出現(因此一旦問題通過驗證標準也會消失)。
驗證類型證明
- min_num_value_n - minimum value for an answer
- max_num_value_n - max value for an answer
- min_answers - minimum number of answers required
- max_answers maximum number of answers allowed
- multiflexible_min - minimum value allowed for an answer (for multiflexi numbers question type)
- multiflexible_max - maximum value allowed for an answer (for multiflexi numbers question type)
- min_num_value - minimum allowed sum across all answers for the question
- max_num_value - maximum allowed sum across all answers for the question
- equals_num_value - the sum across all answers for the question must equal this value
- validation - this is the regular expression validation for the question - it can apply to individual cells
截圖
Using new CSS styles, each validation type shows up a separate tip. If they are shown, they can be hidden via the hide_tip option. The default option is to show them with red font if the question fails the validation criteria, and green if it passes them:
A user cannot submit a page with validation errors. They will be immediately warned if they entered wrong information:
Validation can be applied to individual cells within an array, such as in this example where regular expression validations ensure that each entry is a properly formatted US phone number including area code.
Download
To download the above example, click on the following link: LS3_Validation_tests.zip.
Validation Equations
Overview
Sometimes you need custom validation that cannot be achieved using the traditional min/max criteria. For this, you will need to use the em_validation_q and em_validation_sq options which let you construct complex validation equations at the question and subquestion level, respectively.
EM Features Demonstrated
- em_validation_q - this is an equation that determines whether the whole question is valid
- em_validation_q_tip - this is the message to show if the question fails em_validation_q criteria
- em_validation_sq - this is the equation that determines whether each subquestion (array cell) is valid
- em_validation_sq_tip - this is the message to show if any of the subquestions is invalid.
In general, when em_validation_sq is used, if any cell is invalid, the background color for that cell turns red to indicate that there is an error.
Screenshots
This question ensures that you enter the ages of your children in descending order by applying this validation equation:
q1_sq1 >= q1_sq2 && q1_sq2 >= q1_sq3 && q1_sq3 >= q1_sq4
In the below example, the validation ensures that no more than 3 questions are answered on any given row by applying this validation equation:
(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= 3) && (sum(Test_B_1, Test_B_2, Test_B_3, Test_B_4, Test_B_5) <= 3) && (sum(Test_C_1, Test_C_2, Test_C_3, Test_C_4, Test_C_5) <= 3)
You can also write this as follows, LimeSurvey automatically converting it at run-time to the above-listed expression.
(sum(self.sq_A) <= 3) && (sum(self.sq_B) <= 3) && (sum(self.sq_C) <= 3)
Download
To download the survey sample used in the above examples, click on the following link: ls2_test_em_sq_validation.lss.
Subquestion relevance
Overview
This shows how array_filter and validation criteria can interact. For validations that apply to sums, only relevant (visible) values are considered.
EM Features Demonstrated
It also shows dynamic reporting of the numbers of questions answered in the core questions.
Screenshots
Changing the number of visible rows dynamically changes the sum. Marking a subquestion as being irrelevant doesn't clear its value. Rather, if it is irrelevant, its values don't contribute to any equation.
Note what happens when we check the "Fifth subquestion" for the first question "Which rows should appear below". Note that the sum for the second "Enter some numbers" question is now 5. Even though subquestion 5 for that question still has the value 14 (e.g., if you un-check the fifth subquestion, you will see the value of 14 again), that value does not contribute to the sum since it is currently irrelevant. All irrelevant data is cleared (NULLed in the database) on submit, but it stays available on the page in case users want or need to change their minds about answers.
Download
To download our example, click here: ls2_subquestion_relevance.lss.
Using Comma as Radix Separator (Decimal Point)
Overview
The ExpressionScript ensures that only valid numbers can be entered into numeric fields. If you enter an invalid number, you will be warned that something is wrong (e.g., in the case of the fruity theme, the whole question is "red-ed").
Note that the numeric values are always converted to using a period as the radix separator within the database. In this way, the statistical analyses will work appropriately.
To change the radix separator, access the Text elements options located under the Settings tab, and look for the decimal mark functionality.
Question Types Using Radix Separator
- Numerical input [N]
- Multiple numerical input [K]
- Array (Numbers) [:]
- Array (Texts) [;], when using the numbers_only attribute
- List (radio) [L], when using the other_numbers_only attribute
- Short free text [S], when using the numbers_only attribute
- Multiple short text [Q], when using the numbers_only attribute
- Multiple choice [M], when using the other_numbers_only attribute
- Multiple choice with comments [P], when using the other_numbers_only attribute
Screenshots
You may note in the below screenshots that comma can be used as a radix separator.
Download
To download the above example, click on the following link: ls2_comma_as_radix_separator.lss.
Randomization Groups
Overview
This survey demonstrates how to make use of the random_group attribute.
If this attribute is used, each time you start the survey, the question order is randomized. However, once the survey is started, the randomization order remains fixed, even if you change languages.
Screenshots
Let's check together the below example. The first random question on the page will either be Q1 , Q4, or Q7. The second randomized question on the page will either be Q2, Q5, or Q8.
Here is the randomization generated the first time I tested this survey.
A different randomization was generated the second time I tested the survey.
But, when I switched to French (without re-starting the survey), the randomization order remained intact.
Download
To download the above example, click on the following link: Randomization_Group_Test.lss
Randomly Ask One Question Per Group
Overview
This survey shows how you can configure a survey to randomly display one question per group. In it, there are 5 groups of 6 questions each. At the outset, in Group 0, five hidden Equation questions, called ask1-ask5, are populated. Each one has the value of {floor(rand(1,6.9999))} in the question text field, which means that the variables ask1-ask5 will each have a value between 1 and 6. Then, each question in the group has a relevance equation like "ask1==N" where N is the Nth question in the group (so the third question in group 1 has the relevance equation "ask1==3").
This survey works equally well in survey-at-a-time, group-by-group, and question-by-question modes. Since the randomization is set in the first group, and that group is effectively hidden (since all of the ask1-ask5 questions are hidden), the randomization stays the same for the subject; but each different subject will have a distinct randomization.
Features Demonstrated
- Equation question type
- Randomization functions
- Conditional (if) function
Screenshots
This is Group0, which uses the Equation question type to select random values from 1 to 6 for each group (except the last group, which has only 4 questions). Note that the "if()" function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.
This Group shows how the variable (ask4) from Group0 is used to control which question is visible within the fourth group.
Download
To download the above survey example, click here: Random questions within a group survey example.
Randomly Ask A Specific Number Of Questions In A Group (a subset of the questions)
Overview
This survey shows how to ask a random subset of questions in a group. For example, show 5 random questions out of 10 questions located within a group.
The survey has one group containing 10 questions. All questions are assigned the same randomization group name. As a result, they will be displayed in a random order on page load. Each question is given a relevance equation that the sum of the "relevanceStatus" of all other questions in the group is less than the number of questions you want to show. Since relevanceStatus is assigned as questions are rendered, this effectively totals the number of preceding questions.
So, in our 5 out of 10 example, the equation for Q1 would be:
sum(Q2.relevanceStatus, Q3.relevanceStatus, Q4.relevanceStatus, Q5.relevanceStatus, Q6.relevanceStatus, Q7.relevanceStatus, Q8.relevanceStatus, Q9.relevanceStatus, Q10.relevanceStatus) LT 5
For Q2, it would be:
sum(Q1.relevanceStatus, Q3.relevanceStatus, Q4.relevanceStatus, Q5.relevanceStatus, Q6.relevanceStatus, Q7.relevanceStatus, Q8.relevanceStatus, Q9.relevanceStatus, Q10.relevanceStatus) LT 5
And so on...
Features Demonstrated
Download
To download the above example, click on the following link: Random 5 out of 10 survey example.
Rating User-Entered List of Products
Overview
The below example shows how you can ask users to list a set of products that interest them, and then have them rate those products.
EM Features Demonstrated
- Tailoring answers - when rating products, the labels come from the comment field of the preceding multiple choice question
- Tailoring scales - many advanced questions options, like scale headings, can also be tailored.
Screenshots
This image shows that even though only products 1,3, and 5 were selected, only those 3 are displayed (using the array_filter attribute). Moreover, the row labels in the second question are either the product numbers (if nothing is entered into the comment field) or the contents of the comment fields.
This image shows how the tailored answers are specified:
Here is the Show Logic File for that question, which lets us verify that the conditional logic works as desired (e.g., to see whether there are any syntax errors):
The next image shows a group in which you specify a 5 point rating scale (Options 1-5), the title of the scale, and the products you want to rate. The final question shows that each of the parts of the array question can be tailored:
The next image shows the logic file view of the last question. As you can observe, the subquestions, answers, and scale headers can be tailored.
Download
To download the survey example from above, click on the following link: Rating user-entered list of products survey example.