mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Rename all scripts to have ".zeek" file extension
This commit is contained in:
parent
537d9cab97
commit
18bd74454b
357 changed files with 169 additions and 169 deletions
39
scripts/base/frameworks/sumstats/plugins/average.zeek
Normal file
39
scripts/base/frameworks/sumstats/plugins/average.zeek
Normal file
|
@ -0,0 +1,39 @@
|
|||
##! Calculate the average.
|
||||
|
||||
@load ../main
|
||||
|
||||
module SumStats;
|
||||
|
||||
export {
|
||||
redef enum Calculation += {
|
||||
## Calculate the average of the values.
|
||||
AVERAGE
|
||||
};
|
||||
|
||||
redef record ResultVal += {
|
||||
## For numeric data, this is the average of all values.
|
||||
average: double &optional;
|
||||
};
|
||||
}
|
||||
|
||||
hook register_observe_plugins()
|
||||
{
|
||||
register_observe_plugin(AVERAGE, function(r: Reducer, val: double, obs: Observation, rv: ResultVal)
|
||||
{
|
||||
if ( ! rv?$average )
|
||||
rv$average = val;
|
||||
else
|
||||
rv$average += (val - rv$average) / rv$num;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
hook compose_resultvals_hook(result: ResultVal, rv1: ResultVal, rv2: ResultVal)
|
||||
{
|
||||
if ( rv1?$average && rv2?$average )
|
||||
result$average = ((rv1$average*rv1$num) + (rv2$average*rv2$num))/(rv1$num+rv2$num);
|
||||
else if ( rv1?$average )
|
||||
result$average = rv1$average;
|
||||
else if ( rv2?$average )
|
||||
result$average = rv2$average;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue