x

Các chương chính

  1. Đám mây LimeSurvey vs LimeSurvey CE
  2. LimeSurvey Cloud - Hướng dẫn bắt đầu nhanh
  3. LimeSurvey CE - Lắp đặt
  4. Cách thiết kế một cuộc khảo sát tốt (Hướng dẫn)
  5. Bắt đầu
  6. Cấu hình LimeSurvey
  7. Cấu hình LimeSurvey
  8. Giới thiệu - Khảo sát
  9. Xem menu khảo sát
  10. Xem cấu trúc khảo sát
  11. Giới thiệu - Câu hỏi
  12. Introduction - Question Groups
  13. Introduction - Surveys - Management
  14. Survey toolbar options
  15. Multilingual survey
  16. Quick start guide - ExpressionScript
  17. Advanced features
  18. General FAQ
  19. Troubleshooting
  20. Workarounds
  21. License
  22. Version change log
  23. Plugins - Advanced
 Actions

ExpressionScript Engine - Quick start guide/vi: Difference between revisions

From LimeSurvey Manual

Maren.fritz (talk | contribs)
Created page with "Lưu ý rằng bạn không sử dụng dấu ngoặc nhọn khi nhập phương trình liên quan."
Maren.fritz (talk | contribs)
Created page with "===Xem / Chỉnh sửa Mức độ liên quan ở cấp độ nhóm==="
Line 68: Line 68:




===Viewing / Editing Group-Level Relevance===
===Xem / Chỉnh sửa Mức độ liên quan ở cấp độ nhóm===




Let's focus now on another example - a simple census survey. To download it, click on the following link: [[Media:LS3_group_relevance.zip|Census survey example]].  
Bây giờ chúng ta hãy tập trung vào một ví dụ khác - một cuộc điều tra dân số đơn giản. Để tải xuống, hãy nhấp vào liên kết sau: [[Media:LS3_group_relevance.zip|Ví dụ khảo sát điều tra dân số]].  


The first page asks how many people live with you and stores that in the "cohabs" variable. This page is only shown if you have more than one cohabitant (it is shown for the second person cohabitating with you). Also, p2name, p2age. p2sum are displayed only if the question before each of them contains a response.
The first page asks how many people live with you and stores that in the "cohabs" variable. This page is only shown if you have more than one cohabitant (it is shown for the second person cohabitating with you). Also, p2name, p2age. p2sum are displayed only if the question before each of them contains a response.

Revision as of 09:08, 12 January 2024


Hướng dẫn bắt đầu nhanh

Trong LimeSurvey, bạn có thể tùy chỉnh thêm khảo sát của mình thông qua việc sử dụng ExpressionScript (viết tắt: ES). Sidenote: "ExpressionScript được đặt tên là Trình quản lý biểu thức (EM) trong phiên bản trước. Nếu bạn đọc Trình quản lý biểu thức ở đâu đó thì đó chỉ là tên cũ của ES."

ES có thể được sử dụng để chỉ định những điều sau:

  1. Navigation/Branching - cho phép câu trả lời của người trả lời thay đổi thứ tự hiển thị câu hỏi;
  2. Tailoring/Piping - giúp bạn diễn đạt câu hỏi (chẳng hạn như đề cập đến câu trả lời trước hoặc câu liên hợp dựa trên độ tuổi hoặc giới tính của đối tượng của bạn) hoặc cách tạo báo cáo tùy chỉnh (như điểm đánh giá hoặc lời khuyên phù hợp);
  3. Xác thực - đảm bảo rằng câu trả lời vượt qua các tiêu chí nhất định, như giá trị tối thiểu và tối đa hoặc một mẫu đầu vào nhất định.

ES cung cấp một cách trực quan để xác định logic cho từng tính năng đó. Gần như bất cứ thứ gì bạn có thể viết dưới dạng phương trình toán học tiêu chuẩn đều là một biểu thức hợp lệ.

ES hiện cung cấp quyền truy cập vào 70 chức năng và có thể dễ dàng mở rộng để hỗ trợ nhiều hơn. Nó cũng cho phép bạn truy cập các biến

bằng cách sử dụng tên biến mà con người có thể đọc được (chứ không phải tên SGQA).

Các phần sắp tới sẽ trình bày những vị trí chính mà ES được sử dụng.


Mức độ liên quan (Kiểm soát điều hướng/phân nhánh)

Một số khảo sát sử dụng "Goto Logic", chẳng hạn như nếu bạn trả lời Câu hỏi 1 bằng tùy chọn C, bạn sẽ được chuyển hướng đến Câu hỏi 5. Cách tiếp cận này rất hạn chế vì rất khó để xác nhận nó. Hơn nữa, nó dễ bị hỏng khi bạn phải sắp xếp lại các câu hỏi. Mặt khác, ES sử dụng Phương trình liên quan Boolean để chỉ định tất cả các điều kiện mà theo đó một câu hỏi có thể hợp lệ. Nếu câu hỏi có liên quan thì câu hỏi sẽ được hiển thị, nếu không, câu hỏi đó sẽ không được áp dụng và giá trị "NULL" được lưu trữ trong cơ sở dữ liệu.

Lưu ý: Điều này tương tự như những gì có thể được thực hiện thông qua Trình soạn thảo điều kiện, nhưng ES cho phép bạn dễ dàng chỉ định các tiêu chí phức tạp và mạnh mẽ hơn nhiều (và cho phép bạn sử dụng tên biến thay vì định danh SGQA).




Để hiểu rõ hơn về khái niệm liên quan, chúng ta hãy tập trung vào cuộc khảo sát sau đây tính toán Chỉ số khối cơ thể (BMI) của những người trả lời khảo sát. Để tải xuống, hãy nhấp vào liên kết sau: Ví dụ khảo sát chỉ số khối cơ thể.

Phương trình liên quan được hiển thị bên dưới trong cột Mức độ liên quan sau tên biến. Các giá trị liên quan của trọng lượng, đơn vị cân nặng, chiều cao và đơn vị chiều cao đều là 1 (giá trị mặc định), nghĩa là những câu hỏi đó luôn được hiển thị. Tuy nhiên, mức độ liên quan của BMI là {!is_empty(height) và !is_empty(weight)}, nghĩa là BMI sẽ chỉ được tính nếu đối tượng nhập giá trị cho cả chiều cao và cân nặng (do đó tránh được nguy cơ mắc lỗi 0 ). Ngoài ra, câu hỏi "Báo cáo" chỉ được hiển thị nếu người trả lời trả lời cả bốn câu hỏi chính (chiều cao, đơn vị chiều cao, cân nặng, đơn vị cân nặng).



Lưu ý: Hình ảnh trên được lấy từ tệp logic khảo sát cho phép bạn tìm kiếm lỗi cú pháp trước khi kích hoạt khảo sát.


Mức độ liên quan được hiển thị và có thể chỉnh sửa khi:

  • bạn muốn xem/chỉnh sửa mức độ liên quan ở cấp độ câu hỏi
  • bạn muốn xem/chỉnh sửa mức độ liên quan ở cấp độ nhóm


Xem/Chỉnh sửa Mức độ liên quan ở cấp độ câu hỏi

Phương trình này tính toán Chỉ số khối cơ thể (BMI). Người ta chỉ hỏi người đó có nhập chiều cao và cân nặng của họ hay không.



Đây là màn hình chỉnh sửa câu hỏi "BMI".



Lưu ý rằng bạn không sử dụng dấu ngoặc nhọn khi nhập phương trình liên quan.


Xem / Chỉnh sửa Mức độ liên quan ở cấp độ nhóm

Bây giờ chúng ta hãy tập trung vào một ví dụ khác - một cuộc điều tra dân số đơn giản. Để tải xuống, hãy nhấp vào liên kết sau: Ví dụ khảo sát điều tra dân số.

The first page asks how many people live with you and stores that in the "cohabs" variable. This page is only shown if you have more than one cohabitant (it is shown for the second person cohabitating with you). Also, p2name, p2age. p2sum are displayed only if the question before each of them contains a response.



So, the group also has question-level relevance criteria, such that some questions only appear if you answered certain questions before them (e.g., p2age is displayed if p2name was answered). ES combines the Group and Question-level relevance for you. Questions in a group are only asked if the group as a whole is relevant. Then, only the subset of questions within the group that are relevant are asked.

Here is the screenshot for editing the group-level relevance of Cohabitant 2:



Note that you do not use the curly braces when you enter a relevance equation.

Tailoring/Piping

ES lets you easily do simple and complex conditional tailoring. Sometimes you just need a simple substitution, like saying, "You said you purchased [Product]. What did you like best about it?". Sometimes you need conditional substitution like "[Mr./Mrs.] [LastName], would you be willing to complete our survey?". In this case, you want to use "Mr. or Mrs." based on the person's gender. Other times you need even more complex substitution (such as based upon a mathematical computation). ES supports each of these types of tailoring/piping.


Conditional Equations

The Body Mass Index example shows the ability to compute a person's BMI, even while letting them enter their height and weight in two different units (cms vs inches and kgs vs lbs):



In this case, weightkg is {if(weightunits == "kg", weight, weight * 0.453592)}. This "if()" function means that if the subject enters the weight using kilograms, use that value, otherwise multiply the entered value (pounds is the alternative) by 0.453592 to convert it to kilograms. The heightm variable uses a similar approach to compute the person's height in meters (height in cms/100), even if he has entered his height in inches (1 meter=3.28084 inches).

BMI is computed as: {weightkg / (heightm * heightm)}.

Lastly, the report conditionally tailors the message for the subject, telling her what he entered. (e.g., "You said you are 2 meters tall and weight 70 kg.")

In the below image, weightstatus uses nested "if()" statements to categorize the person as underweight to severely obese. You can see its equation by checking its logic:



From the edit window for this question, you can see two things:

  1. Tailoring must surround expressions with curly braces
  2. Expressions can span multiple lines if, as in this case, you want to make it easier to read the nested conditional logic.



Tailored Questions, Answers, and Reports

Note: Dynamic tailoring may not work if answer options are made available in select boxes on the same question page. This results from the fact that tailoring inserts a <span> tag which is not valid inside select options.

The BMI report looks like this:



Here is the edit window for the same question.



Anything within curly braces is treated as an expression, being syntax-highlighted (color coded) in the prior image. If you have any typos (such as misspelled or undefined variable names or functions), ES would show an error. In our below example:

  • heightunit.shown is an undefined variable name (it is actually heightunits.shown) and
  • "rnd()" is an undefined function (the proper function name is "round()").

In both cases, the errors are located within a red box to make it easier to spot and fix them.



You can also see that you can quickly create complex reports, such as a table of entered values or tailored advice.

Please remember that all tailoring must surround expressions with curly braces so that LimeSurvey knows which parts of the question are free text and which should be parsed by the ExpressionScript engine.


Validation

ES controls how most of the advanced question options work. These control aspects like min/max numbers of answers, min/max individual values, min/max sum values, and checking that entered values match specified string patterns. Any value in one of those fields is considered an expression, so you can have min/max criteria with complex conditional relationships to other questions.

In all of these cases, since the advanced question attribute is always considered an expression, you do not use curly braces when specifying it.

The sample surveys page shows many working examples containing a variety of validation expressions.

ExpressionScript - presentation

To find out more about ExpressionScript and how you can use different expressions to enhance your survey, please click on the following link.