MGB Framework

Honey | [Outdated] Examples

This pages shows various examples of Honey programs.

In theses example, the dataset is supposed to be loaded in the signal variables $X, $Y and $Z. The result of the operation is stored in the signal variable $OUT. The intermediate signal variables are $A, $B, $C, $D, etc.

Compute a tailing simple moving average of a signal with a window of 50 time units.

$OUT = sma $X 50

Compute a simple moving average of a signal with a time window of 5 hours (supposing that one time unit is a second).

$OUT = sma $X =3600,5,*

Compute a tailing simple moving average of a signal with a window of 50 time units. Update the value every 10 time unit.

$A = tick 10
$OUT = sma $X 50 trigger:$A

This is equivalent to

$A = tick 10
$B = sma $X 50
$OUT = sample $B trigger:$A

Compute a centered simple moving average of a signal with a window of 50 time units (Static mode only).

$A = echoPast $X 25
$OUT = sma $A 50

Compute the mean, median, minimum, maximum, range, range 90% and standard deviation of a signal over the last 10s.

$OUT = windowfeatures $X 10

Generate calendar events in the current time zone (days, week, months) while supposing that the time is the Unix time (number of seconds since the 1st jan 1970).

$OUT = calendar produce:hours,days,months

Downsample a signal to a maximum of one update every 10 seconds.

$OUT = skip $X 10

Add the value of two signals.

$OUT = eq $X "value,arg1,+" arg1:$Y

Let the signal $X passes only if the value of $Y is between 10 and $Z.

$OUT = passIf $X "10,arg1,>,arg2,arg1,<,*" arg1:$Y arg2:$Z

Remove all the values below 5.

# The two solutions are equivalent. The first solution is faster to compute.
$OUT = passIfFast $X minValue:5
$OUT = passIf $X "value,5,>"

Generate a signal if an event $X is followed by an event $Y, which is followed by an event $Z such that there is not more than 5 seconds between $X and $Y, and no more than 10 seconds between $Y and $Z.

$X_A = active $X 5
$A = passIf $Y "arg1" arg1:$X_A
$A_A = active $A 10
$OUT = passIf $Z "arg1" arg1:$A_A

Count the number of times the numerical derivative of $A, computed over the last 0.1 time units, was negative and had become positive (cross up 0) in the last 10 seconds.

# tma is a good stable smoothing function for derivation (better than sma).
$A = tma $X 0.1
$B = derivative $A
$C = layer $B min:0 max:0 step:1 exclude:state
$D = filter $C ".*crossup.*"
$OUT = count $D 10

# Note: Only one temporary signal variable can actually be used. The following example is equivalent. Note that it is generally a good idea to keep, save and visualise intermediate results for debug.
$A = tma $X 0.1
$A = derivative $A
$A = layer $A min:0 max:0 step:1 exclude:state
$A = filter $A ".*crossup.*"
$OUT = count $A 10

Compute the average value of $A by day i.e. Produce a value each day at midnight.

$A = sma $A =3600,24
$B = calendar produce:days
$C = filter $B event.day_is_.*
$OUT = sample $A trigger:$C

Compute a details report of the number of event $A according to the day of the week. Sort the results according of the day of the week.

$A = calendar produce:days
$B = filter $A state.day_is_.*
report_histIntersectEventState event:$A state:$B sortBy:name file:"hist_day_name.txt"

Compute a details report of the number of event $A according to the value of a scalar.

report_histIntersectEventState event:$A scalar:$B file:"report.txt"

Generate an event at every heart beat from an EKG signal.

# The input is $EKG, the output will be $BH
$R1 = range $EKG 0.02
$R2 = range $EKG 4
$D = div $R1 $R2
$D2 = sma $D 0.02
$L = layer $D2 min:0.3 max:0.3 step:1 exclude:state
$L2 = filter $L .+crossup.+
$BH = rename $L2 event.HeartBeat

Load a file from the script (and not from the command line argument).

# Load a.bin in memory, and define %output = "out.bin"
AUTODATASET input:"a.bin" output:"out.bin"

# Load a.bin and b.bin in memory, and define %output = "out.bin"
AUTODATASET input:"a.bin,b.bin" output:"out.bin"

# Load a.bin in memory, define %output = "out_a.bin" and apply the script. Next, load b.bin in memory, define %output = out_b.bin and execute the script with the new data.
AUTODATASET input:"a.bin" output:"out_a.bin"
AUTODATASET input:"a.bin" output:"out_b.bin"

Emit a beep every 200ms (Online mode only)

$A = tick 0.2
print $A every:true
beep $A pitch:750

Emit a beep when a keyboard key is pressed (Online mode only)

$A = keyboard
print $A every:true
beep $A pitch:750

Apply the titarl rules 1 2 and 3 from rules.xml, and output the rule id.

applyRules $INPUT_EVENT rulePath:"rules.xml" emitRuleId:true onlyIds:"1,2,3"