Calculation
Calculation related column widgets.

Formula

Use this widget to display value calculated based on a formula. The formula shall be defined in the Default Value of the column.

Configuration

1
{
2
"rows": [ # (optional),
3
"column_sid", # The column sid of ForeignKey, ForeignKeys, NestedFields, optional
4
],
5
"counts": [ # (optional)
6
"table_sid__column_sid", # count based on table and column
7
"table_sid__column_sid__lte__date_created", # count includes the datetime
8
],
9
"formula": "", # (required), the formula, see the Syntax below
10
# data[column_sid], value of a column of current row
11
# data[row_sid__column_sid], value of column of a fixed row
12
# data[`${data['column__sid'].sid}`__column_sid]
13
# data[column1_sid__column2_sid], column1_sid, the ForeignKey column listed in rows;
14
# count[table_sid__column_sid], the count value
15
"format": {}, # (optional), the number in the wNumb format.
16
# Learn more at https://refreshless.com/wnumb/
17
"should_auto_update": false, # (optional), default to false.
18
# If true, the widget will perform live calculation
19
# If false, the user have to click reload to update the value
20
"should_auto_update_when_empty": true, # (optional), default to true.
21
# If true, the widget will perform live calculation when the data is empty
22
# If false, the results will not be calculated on default
23
}
Copied!

Syntax

data[Field 1] + data[Field 2] + data[Source column sid__Target solumn sid]
Wheres, Field is the SID of a column. For example:
  • data[8adg0a40x52520ejotyDI] + data[69be0a40x52508chmrwBG]
  • data[8adg0a40x52520ejotyDI].substring(1,2)
  • data[8adg0a40x52520ejotyDI].substring(1,3) == "ATCG" ? "Good" : "Bad"
  • data[8adg0a40x52520ejotyDI__69be0a40x52508chmrwBG].substring(1,2)

Operator

  • + Addition, a + b
  • - Subtraction,
  • * Multiplication
  • ** Exponentiation (ES2016)
  • / Division
  • % Modulus (Remainder)
  • sum - get sum value of array
  • mean - get mean value of array
  • sd - get standard deviation of array
  • se - get standard error of array
  • Priority calculate with () is supported, (100 + 50) * a;
  • If condition: true ? a : b, if the condition is true, then return a, else, return b
  • Substring: string.substring(start, end)
  • Case:
    • Upper: str.toUpperCase()
    • Lower: str.toLowerCase()
  • Date: new Date(dateString), learn more at here.
  • Math:
    • abs(x) Returns the absolute value of x
    • acos(x) Returns the arccosine of x, in radians
    • asin(x) Returns the arcsine of x, in radians
    • atan(x) Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians
    • atan2(y, x) Returns the arctangent of the quotient of its arguments
    • ceil(x) Returns the value of x rounded up to its nearest integer
    • cos(x) Returns the cosine of x (x is in radians)
    • exp(x) Returns the value of Ex
    • floor(x) Returns the value of x rounded down to its nearest integer
    • log(x) Returns the natural logarithm (base E) of x
    • max(x, y, z, ..., n) Returns the number with the highest value
    • min(x, y, z, ..., n) Returns the number with the lowest value
    • pow(x, y) Returns the value of x to the power of y
    • random() Returns a random number between 0 and 1
    • round(x) Returns the value of x rounded to its nearest integer
    • sin(x) Returns the sine of x (x is in radians)
    • sqrt(x) Returns the square root of x
    • tan(x) Returns the tangent of an angle

Numbering

Use this widget to generate your own ID with auto-increment. The Numbering can be generated automatically and can also be manually updated.
Click the reload button to update the ID
Configuration
1
{
2
"format": "YY-ID", # (required), the format of the id
3
# YYYY - 2020, 4 digits of year
4
# YY - 20, 2 digits of year
5
# MM - 07, 2 digits of month
6
# DD - 01, 2 digits of day
7
# ID, the serial id
8
# FOREIGNKEYCOLUMN - refer to the data from a foreignkey
9
"reset_month": 10, # (optional), the month to reset the id
10
"reset_day": 1, # (optional), the day to reset the id
11
"foreignkey": "xxx", # the foreignkey column to refer, required when FOREIGNKEYCOLUMN is used
12
"column": "xxx", # the column of foreignkey, required when FOREIGNKEYCOLUMN is used
13
"reset_column": "xxx", # (optional), the column to reset the ID
14
"digits": 4, # (optional), number of digits of ID to display
15
}
Copied!
The default value will be ignored for the ID widget.

RowCount

Use this widget to display the count of a Row. For example, the number of biospecimens generated from a host.
To make it work, provide the query string into column configuration.
Configuration
1
{
2
"query": "name__icontains=test&table__name_singular=experiment", # (requried)
3
# paste the query
4
# Some variables can be added to the link. The widget will replace it for you:
5
# {{ROW:SID}}, the sid of the current record.
6
"should_auto_update": false, # default to false.
7
# If true, the widget will perform live calculation
8
# If false, the user have to click reload to update the value
9
"format": {}, # the number in the wNumb format.
10
# Learn more at https://refreshless.com/wnumb/
11
}
Copied!

Consumption

Use this widget to display the remaining volume of a sample or reagent.
Configuration:
  • Column "Volume Value" with Number widget
  • Table "Consumption"
    • Column "Sample" or "Reagent" with ForeignKey widget
    • Column "Amount" with Number widget
1
{
2
"volume__sid": "RUX10a40x94dcTY49dins",
3
# required, the sid of the column "Volume Value"
4
"consumption_sample__sid": "KNQT0a40x94d5MRW27bgl",
5
# required, the sid of the column "Sample" or "Reagent" from the consumption table
6
"consumption_amount__sid": "MPSV0a40x94d7OTY49din",
7
# required, the sid of the column "Amount" from the consumption table
8
"threshold": 10,
9
# the color of the value will turn red if the remaining value lower than the threshold
10
"should_auto_update": true, # default to true.
11
# If true, the widget will perform live calculation
12
# If false, the user have to click reload to update the value
13
"format": {}, # the number in the wNumb format.
14
# Learn more at https://refreshless.com/wnumb/
15
}
Copied!
Default value:
1
{
2
"value": 10,
3
"is_low": false
4
}
Copied!
Last modified 2mo ago