Actions

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

From LimeSurvey Manual

(Created page with "質問のどの部分がフリーテキストで、どの部分が式マネージャーで解析する必要があるかをLimeSurveyが判断するため、すべての式を...")
(Created page with "==検証==")
Line 150: Line 150:
質問のどの部分がフリーテキストで、どの部分が式マネージャーで解析する必要があるかをLimeSurveyが判断するため、すべての式を中括弧で囲む必要があります。
質問のどの部分がフリーテキストで、どの部分が式マネージャーで解析する必要があるかをLimeSurveyが判断するため、すべての式を中括弧で囲む必要があります。


==Validation==
==検証==





Revision as of 01:35, 5 September 2018


クイックスタートガイド

LimeSurveyでは、式マネージャー(EM)を使ってアンケートをカスタマイズすることができます。次のことを指定するときに使います。

  1. ナビゲーション/分岐 - 回答者の回答によって質問が表示される順番を変更します。
  2. テーラーリング/パイピング - 質問の文言調整(先行する回答の引用、数や性別による語句の変化など)、カスタムレポートの生成(評価点数、アドバイスの提示など)
  3. 検証 - 回答が条件(最大値、最小値、入力パターンなど)を満たすようにします。

式マネージャー(EM)では、各機能のロジックを指定する直感的な方法が提供されています。標準的な数式として書くことができるものは、ほとんどが有効な式になります。

EMは現在、70の関数が利用でき、より多くの機能をサポートするよう、簡単に拡張することができます。また、(SGQA名ではなく)人間が読める変数名を使用して変数にアクセスすることもできます。

以下のセクションで、式マネージャーを使う主な場面を紹介します。


関連(ナビゲーション制御/分岐)

アンケートによっては、"Gotoロジック"を使用して、質問1でCと答えた場合は質問5にジャンプしたりします。このアプローチは、検証が難しいため、大きな制約があります。また、質問を並べ替えるときにロジックが壊れやすくなってしまいます。一方、EMでは、質問が有効かどうかを決めるすべての条件を、ブール値の出現条件式を使用して指定します。質問が出現条件を満たす場合は質問が表示され、それ以外の場合は「適用外」となり、データベースにはNULL値が格納されます。

注意: これは条件エディターで実行できるものと似ていますが、EMではより複雑で強力な条件を簡単に指定でき、さらにSGQA名ではなく変数名を使用できます。




To better understand the relevance concept, let's focus on the following survey which computes the Body Mass Index (BMI) of survey respondents. To download it, click on the following link: Body Mass Index survey example.

The relevance equation is shown below in the Relevance column after the variable name. The relevance values of weight, weight_units, height, and height_units are all 1 (default value), meaning that those questions are always displayed. However, the relevance for BMI is {!is_empty(height) and !is_empty(weight)}, which means that BMI will only be computed if the subject enters a value for both height and weight (thereby avoiding the risk of getting a zero error). Also, question "Report" is only shown if the respondent answers all four main questions (height, heightunits, weight, weightunits).



Note: The above image comes from the survey logic file which allows you to look for syntax errors before activating the survey.


Relevance is shown and editable when:

  • you wish to view/edit question-level relevance
  • you wish to view/edit group-level relevance


質問レベルの関連の閲覧/編集

この式は、体格指数(BMI)を計算します。身長と体重を入力した場合のみ計算されます。



こちらが"BMI"質問の編集画面です。



出現条件式を入力するときは中括弧を使用しないようにしてください。


グループレベルの関連の閲覧/編集

Let's focus now on another example - a simple census survey. To download it, click on the following link: Census survey example.

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.



ご覧のように、グループには質問レベルの出現条件もあり、こうした質問は、先行する質問に回答したときにのみ表示されます(例:p2ageはp2nameに回答したときだけ表示する)。EMは、グループと質問レベルの出現条件を結合します。グループ内の質問は、グループ全体が出現条件を満たす場合にのみ表示されます。次に、グループ内で出現条件を満たす質問のみが表示されます。


その質問のグループレベルの出現条件を編集する画面は次のとおりです。



出現条件式を入力するときは中括弧を使用しないようにしてください。

カスタマイズ/パイプ

EM 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). EM supports each of these types of tailoring/piping.


条件式

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):



Here weightkg is {if(weightunits == "kg", weight, weight * 0.453592)}.  This "if()" function means that if the subject entered 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 entered his height in inches (1 meter=3.28084 inches).

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

最後に、回答者に対し、入力した内容を条件付きでカスタマイズして表示します。("身長2メートル、体重70キロと回答しました。")

上の画像では、weightstatusは入れ子の"if()"ステートメントを使用し、その人物がやせているのか肥満なのかを分類します。その式をロジックを確認して見ることができます。



この質問の編集ウィンドウから、次の2つのことがわかります。

  1. 中括弧で表現を囲む必要があります
  2. 式は、例えばこの例のように、ネストされた条件付きロジックを読みやすくするため、複数の行にまたがって記述することができます。


カスタマイズされた質問・解答・レポート

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:



同じ質問の編集ウィンドウです。



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), EM 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 surrounded by a red box to make it easier to spot and fix them.



また、入力された値の一覧やカスタマイズされたアドバイスなど、複雑なレポートをすばやく作成できます。

質問のどの部分がフリーテキストで、どの部分が式マネージャーで解析する必要があるかをLimeSurveyが判断するため、すべての式を中括弧で囲む必要があります。

検証

EM 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.  You continue to enter those advanced question options as usual.  However, now 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 option is always considered an expression, you do not use curly braces when specifying it.

The Sample Surveys pages show many working examples of using expressions for validations.


Expression Manager - presentation

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