Nabrio Help
Nabrio Help

Getting Started

Nara Overview

Understanding Nara

Basic Course
Intermediate Course
Course Introduction · Designing Flows for Different Tasks
Operation
Moving Number Calculation
IO · Talking to the outside
Mini Project 1 · Danger Zone MonitoringMini Project 2 · Machine Status MonitoringMini Project 3 · Conveyor Parcel Processing

Using Nara

Components

Widgets

Miscellaneous

Nomenclature
Troubleshooting
Notice and DisclaimerEULA
CoursesIntermediate CourseProcess

Moving Number Calculation

Use the Moving Number Calculation Node to work out a figure from the last few numbers that arrived, such as a moving average, a maximum, or a minimum, with a workshop that feeds values from a Slider and watches the average follow.

Numbers that arrive in a stream, like a temperature reading or a conveyor speed, are never still. Decide on the raw values and the result flickers while nothing about the real thing has changed. The Moving Number Calculation Node exists for this: it holds on to the last few numbers and works them into a single figure for the next Node to use.

1. How it works in general

Suppose the Node is configured to use the three most recent numbers. Each new number is added to the calculation. After three values have been stored, adding another value removes the oldest one. The Node then recalculates the result using the latest three values.

feed 75          [75]              → 75
feed 85          [75, 85]          → 80
feed 90          [75, 85, 90]      → 83.33
feed 60      75 ⟵ [85, 90, 60]     → 78.33
feed 0       85 ⟵ [90, 60, 0]      → 50

The calculation is described as moving because the set of values changes whenever a new value arrives. The result reflects the most recent values rather than every value received since the Flow started.

What you get out of it is a steadier number: one reading that jumps out of line gets absorbed by its neighbours. It also follows the real value more slowly, because a new number can only pull the average so far until the older ones have dropped out.

2. How Moving Number Calculation works in NARA

This Node sits under Process in the Node panel. Where the Operation chapter was about Nodes that decide where a Flow goes, this one works on the numbers themselves. It takes one number in and sends one number out. The key thing is that one pass of the Flow through this Node is one new value fed in. The Flow must therefore run repeatedly to update the calculation, whether from a While Loop, a Time Interval Trigger, or a button press.

Moving Number Calculation settings

Configure the following five parameters:

ParameterWhat it means
Input TypeThe type of value coming in. Here it is Number
Input NumberThe value to include in the calculation. Select a Reference to the source Node's Output
Amount to CalculateThe number of recent values included in the calculation
Calculation TypeWhich calculation to run over the values held
Prefill With ValueWhether to prefill the stored values using the first input. Leave this disabled in this chapter

On the Output side there are two:

  • outValue number the result of the calculation, and what you'll use in almost every case
  • outArrayValues array the set of values used in that pass, there for cases where the answer can be more than one value, such as Mode

Calculation Type

The Calculation Type dropdown provides 14 options. They can be grouped by purpose as follows:

  • Representative values: Mean, Median, Mode, Geometric Mean, Harmonic Mean, and Root Mean Square
  • Limits and range: Minimum, Maximum, Range, and Mid-range (max - min)
  • Variation: Standard Deviation and Variance
  • Other calculations: Sum and Regression Coefficient

Use Mean to smooth a sequence of sensor readings, as demonstrated in this Workshop and Mini Project 2. If the readings may contain occasional outliers, Median can provide a more stable representative value because a single extreme value has less effect on the result. Use Standard Deviation when you need to measure how widely the readings vary rather than calculate a representative value.

Pay attention to the following output and input behavior:

  • Mode returns the most frequent value. More than one value may share the highest frequency, so the result is provided through outArrayValues as an Array rather than through outValue.
  • Geometric Mean and Harmonic Mean ignore negative input values. Do not use these calculations when negative readings must be included in the result.

3. Workshop · A moving average

Build a small Flow that lets someone pick a number on a slider on the Dashboard, press a Trigger button to feed that one value in, and get the average of the last three values back on screen.

Having a person press the button makes one thing obvious: one press is one new value. Move the slider around as much as you like and nothing happens until you press it.

The finished Flow looks like this:

The example Flow

As a diagram:

Dashboard Trigger Moving Number Calculationmean of the last 3 Cal Outputwrites the result into Dashboard Output Number Slider Dashboard Input Basic Display

The dotted lines are reads and writes through variables, not wires between Nodes.

4. Workshop · The Dashboard side

The Dashboard uses four Widgets:

WidgetRoleVariable Source
Number SliderLets the user pick the number to feed inDashboard Input
Trigger ButtonSends the selected value into the FlowNot applicable
Basic DisplayShows the value just fed inDashboard Input
Basic DisplayShows the calculated resultDashboard Output

The Dashboard before anything runs

On the Flow side, create two Variable: Create Nodes to match:

VariableTypeWhat it holds
Dashboard Input numberTakes the value from the slider and hands it to the calculation
Dashboard Output numberHolds the result for the Widget to read

The Flow starts from a Dashboard Trigger bound to the Trigger button.

5. Workshop · Configuring the Node

Wire the Dashboard Trigger into Moving Number Calculation and set it up like this:

ParameterValueDescription
Input TypeNumberThe incoming value is a number
Input NumberoutValue from the Dashboard Input NodeWhatever the user just picked on the slider
Amount to Calculate3Keep the last three values
Calculation TypeMeanWork out the arithmetic average
Prefill With ValueOffBegin the calculation with the values received during each run

Try different Calculation Types

The example in section 2 uses Maximum, which returns the largest value among the recent values being calculated. This Workshop uses Mean to calculate the average of the three most recent values. After completing the Workshop, try other Calculation Types and compare how each option changes the result.

Then add a Variable: Modify at the end of the calculation, named Cal Output, to take the result and store it where the Widget is looking.

ParameterValueDescription
Variable SourceDashboard OutputThe variable the Widget reads from
Assign ModeOverwrite (=)Replace the previous result each pass
Variable ValueoutValue from Moving Number CalculationThe figure just calculated

Why the extra variable in between

Widgets on the Dashboard read from variables, not from a Node's Output directly. The Cal Output Node is the bridge: it takes the result from the calculation and writes it into a variable the Widget can see. It's the same pattern every workshop in this chapter uses.

6. Trying it out

Deploy, move the slider to 75, and press Trigger. Both readouts show 75 because only one value has been received, and the average of one value is that value.

After the first value, 75

Move to 85 and press Trigger again. The result reads 80, the average of 75 and 85.

After the second value, 85

Feed in 90 as the third value. The Node now has three values to calculate, and the result becomes 83.33333..., which is (75 + 85 + 90) ÷ 3.

After the third value, 90

Keep going and you'll see the older values start dropping out of the calculation:

PressValue fed inValues included in the calculationResult
1757575
28575, 8580
39075, 85, 9083.33
46085, 90, 6078.33
5090, 60, 050

On press 4, the original value of 75 is no longer included because Amount to Calculate is set to 3.

Try changing Amount to Calculate

Set Amount to Calculate to 5, then enter the same sequence again. The result will change more gradually because each calculation includes more recent values. A larger number can smooth noisy readings but may respond more slowly to a sudden change. A smaller number responds faster but provides less smoothing. Choose the value based on how much smoothing and response speed the task requires.

If the results aren't what you expect, work through these:

SymptomLikely cause
Pressing Trigger does nothingThe Dashboard Trigger isn't bound to the Trigger button
The result readout is always emptyThe Widget's Variable Source isn't Dashboard Output, or the Cal Output Node isn't wired in
The result always equals the value just fed inAmount to Calculate is set to 1, so each calculation includes only the latest value
The result is the largest value, not the averageCalculation Type is still Maximum rather than Mean
Nothing follows the sliderThe Number Slider and the Node's Input Number point at different variables
The result has a very long decimalNormal for a division that doesn't come out even. Round it at display time if you want it tidier

Next

That is the Process chapter done. Next comes keeping data around to look at later, at Database Table · Storing data in a table.

Switch Case · Creating multiple paths from one value

Use Switch Case to compare one value with up to four Cases, then build a Workshop that converts a machine mode number into a status message.

Database Table · Storing data in a table

Create a table with DB Table Initialize, define its Columns, and write rows with DB Table Row Insert or Modify, with a workshop that stores what the user enters on the Dashboard.

On this page

1. How it works in general2. How Moving Number Calculation works in NARACalculation Type3. Workshop · A moving average4. Workshop · The Dashboard side5. Workshop · Configuring the Node6. Trying it out