Jump to content

Help:RiskDisplay: Difference between revisions

From RiskiPedia
Short note on why UI text is best done in the RiskModel
Use #expr instead of calculation/result
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
= Help:RiskDisplay =
= Help:RiskDisplay =


The <riskdisplay> tag displays the result of a risk model defined by a [[Help:RiskModel|RiskModel]], typically stored on a "/Data" subpage with related [[Help:RiskData|RiskData]] tables. For simple cases or debugging, it can use a direct calculation or custom text. See [[Help:RiskModel|RiskModel documentation]] for details on calculations and text formatting.
The <riskdisplay> tag displays the result of a risk model defined by a [[Help:RiskModel|RiskModel]], typically stored on a "/Data" subpage with related [[Help:RiskData|RiskData]] tables.


RiskDisplays are put on pages with [[Help:DropDown|DropDown]] or [[Help:RiskParameter|RiskParameter]] UI elements to allow users to choose different variables that affect the risk calculation(s).
RiskDisplays are put on pages with [[Help:DropDown|DropDown]] or [[Help:RiskParameter|RiskParameter]] UI elements to allow users to choose different variables that affect the risk calculation(s).


== Syntax ==
== Syntax ==
The <riskdisplay> tag requires one of these attributes:
The <riskdisplay> tag has one optional attribute:


* `model`: The name of a risk model defined by a <riskmodel> tag (preferred method).
* `model`: The name of a risk model defined by a <riskmodel> tag
* `calculation`: A mathematical expression, for simple cases or debugging.
 
Use either `model` or `calculation`, not both. Optional text inside the tag overrides the riskmodel's text.


Basic syntax:
Basic syntax:
Line 19: Line 16:
Or with a direct calculation:
Or with a direct calculation:
<pre><nowiki>
<pre><nowiki>
<riskdisplay calculation="base_probability * exposure_factor">Your risk is about {result}%</riskdisplay>
<riskdisplay>Your risk is about {{#expr: {base_probability} * {exposure_factor} }}%</riskdisplay>
</nowiki></pre>
</nowiki></pre>


Line 25: Line 22:


# For most cases, use the &lt;riskdisplay&gt; tag with the `model` attribute to reference a &lt;riskmodel&gt;, typically defined on a "/Data" subpage with related RiskData tables. This uses the model’s calculation and text to be presented to the user. It is best to keep the text with the RiskModel, in case the RiskModel is changed.
# For most cases, use the &lt;riskdisplay&gt; tag with the `model` attribute to reference a &lt;riskmodel&gt;, typically defined on a "/Data" subpage with related RiskData tables. This uses the model’s calculation and text to be presented to the user. It is best to keep the text with the RiskModel, in case the RiskModel is changed.
# For simple cases or debugging, use the `calculation` attribute or include text inside the tag to override the model’s description. See [[Help:RiskModel|RiskModel documentation]] for calculation and text formatting details.
# For simple cases or debugging, include text inside the tag to override the model’s text. See [[Help:RiskModel|RiskModel documentation]] for text formatting details.


== Examples ==
== Examples ==
Line 39: Line 36:
Define a calculation for a simple case or debugging:
Define a calculation for a simple case or debugging:
<pre><nowiki>
<pre><nowiki>
<riskdisplay calculation="base_probability * exposure_factor">Your risk is {{One_In_N|{result}}}</riskdisplay>
<riskdisplay calculation="base_probability * exposure_factor">Your risk is {{One_In_N|{{#expr: {base_probability}*{exposure_factor} }} }}</riskdisplay>
</nowiki></pre>
</nowiki></pre>
This computes a result and displays it as "1 in X" (e.g., "1 in 10" for 0.1).
This computes a result and displays it as "1 in X" (e.g., "1 in 10" for 0.1).
=== Overriding Model Text ===
Override the model’s description with custom text:
<pre><nowiki>
<riskdisplay model="RiskScore">The weighted risk score is '''{result}''' points</riskdisplay>
</nowiki></pre>
This uses the "RiskScore" model’s calculation but displays the result with custom text.


=== Debugging with Detailed Text ===
=== Debugging with Detailed Text ===
Display raw and formatted results along with a variable for debugging:
Display raw and formatted results along with a variable for debugging:
<pre><nowiki>
<pre><nowiki>
<riskdisplay model="AccidentRisk">Raw probability: {result}
<riskdisplay>Raw probability: {{#expr: {base_probability}*{exposure_factor} }}
Human-friendly probability: {{One_In_N|{result}}}
Human-friendly probability: {{One_In_N|{{#expr: {base_probability}*{exposure_factor} }} }}
Odds-ratio: {distraction_odds_ratio}</riskdisplay>
</riskdisplay>
<riskdisplay>Base probability: {base_probability}</riskdisplay>
<riskdisplay>Exposure factor: {exposure_factor}</riskdisplay>
</nowiki></pre>
</nowiki></pre>
This uses the "AccidentRisk" model’s calculation, showing the raw `{result}`, a human-friendly version via <nowiki>{{One_In_N}}</nowiki>, and the `distraction_odds_ratio` variable.


== Notes ==
== Notes ==
* The `model` attribute is the preferred method, referencing a &lt;riskmodel&gt; typically defined on a "/Data" subpage.
* The `model` attribute is the preferred method, referencing a &lt;riskmodel&gt; typically defined on a "/Data" subpage.
* Use `calculation` or text inside the tag only for simple cases or debugging.
* Models can be defined on the current page or a "/Data" subpage.
* Models can be defined on the current page or a "/Data" subpage.
* Text formatting, including templates like <nowiki>{{One_In_N|{result}}}</nowiki>, is described in [[Help:RiskModel|RiskModel documentation]].
* Text formatting, including templates like <nowiki>{{One_In_N...}}</nowiki>, is described in [[Help:RiskModel|RiskModel documentation]].


== Troubleshooting ==
== Troubleshooting ==
* **Error: "riskdisplay: missing model= or calculation="** – Include either the `model` or `calculation` attribute.
* **Error: "riskdisplay: specify either model or calculation, not both"** – Use only one of `model` or `calculation`.
* **Error: "riskdisplay: can't find riskmodel named X"** – Ensure the `model` name matches a &lt;riskmodel&gt; on the current page or a "/Data" subpage.
* **Error: "riskdisplay: can't find riskmodel named X"** – Ensure the `model` name matches a &lt;riskmodel&gt; on the current page or a "/Data" subpage.
* **Result not displayed** – Check that the referenced model has a valid description, or if overriding, ensure the text includes the `{result}` placeholder. See [[Help:RiskModel|RiskModel documentation]] for details.
* **Result not displayed** – Check that the referenced model has a valid description, or if overriding, ensure the text includes the `{result}` placeholder. See [[Help:RiskModel|RiskModel documentation]] for details.


For related features, see [[Help:RiskModel|RiskModel documentation]] or [[Help:RiskData|RiskData documentation]].
For related features, see [[Help:RiskModel|RiskModel documentation]] or [[Help:RiskData|RiskData documentation]].

Latest revision as of 20:59, 17 September 2025

Help:RiskDisplay

The <riskdisplay> tag displays the result of a risk model defined by a RiskModel, typically stored on a "/Data" subpage with related RiskData tables.

RiskDisplays are put on pages with DropDown or RiskParameter UI elements to allow users to choose different variables that affect the risk calculation(s).

Syntax

The <riskdisplay> tag has one optional attribute:

  • `model`: The name of a risk model defined by a <riskmodel> tag

Basic syntax:

<riskdisplay model="heart_attack_risk" />

Or with a direct calculation:

<riskdisplay>Your risk is about {{#expr: {base_probability} * {exposure_factor} }}%</riskdisplay>

Usage

  1. For most cases, use the <riskdisplay> tag with the `model` attribute to reference a <riskmodel>, typically defined on a "/Data" subpage with related RiskData tables. This uses the model’s calculation and text to be presented to the user. It is best to keep the text with the RiskModel, in case the RiskModel is changed.
  2. For simple cases or debugging, include text inside the tag to override the model’s text. See RiskModel documentation for text formatting details.

Examples

Using a Risk Model

Display the result of a risk model named "heart_attack_risk":

<riskdisplay model="heart_attack_risk" />

This uses the calculation and description from the "heart_attack_risk" <riskmodel>, typically defined on a "/Data" subpage.

Using a Direct Calculation

Define a calculation for a simple case or debugging:

<riskdisplay calculation="base_probability * exposure_factor">Your risk is {{One_In_N|{{#expr: {base_probability}*{exposure_factor} }} }}</riskdisplay>

This computes a result and displays it as "1 in X" (e.g., "1 in 10" for 0.1).

Debugging with Detailed Text

Display raw and formatted results along with a variable for debugging:

<riskdisplay>Raw probability: {{#expr: {base_probability}*{exposure_factor} }}
Human-friendly probability: {{One_In_N|{{#expr: {base_probability}*{exposure_factor} }} }}
</riskdisplay>
<riskdisplay>Base probability: {base_probability}</riskdisplay>
<riskdisplay>Exposure factor: {exposure_factor}</riskdisplay>

Notes

  • The `model` attribute is the preferred method, referencing a <riskmodel> typically defined on a "/Data" subpage.
  • Models can be defined on the current page or a "/Data" subpage.
  • Text formatting, including templates like {{One_In_N...}}, is described in RiskModel documentation.

Troubleshooting

  • **Error: "riskdisplay: can't find riskmodel named X"** – Ensure the `model` name matches a <riskmodel> on the current page or a "/Data" subpage.
  • **Result not displayed** – Check that the referenced model has a valid description, or if overriding, ensure the text includes the `{result}` placeholder. See RiskModel documentation for details.

For related features, see RiskModel documentation or RiskData documentation.