Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AverageEvaluator.cs
5
7{
12 {
13 private IElement sum = null;
14 private double doubleSum = 0;
15 private bool isDouble = true;
16 private long count = 0;
17
23 : base(Node.Argument)
24 {
25 }
26
30 public override void RestartEvaluator()
31 {
32 this.sum = null;
33 this.count = 0;
34 this.doubleSum = 0;
35 this.isDouble = true;
36 }
37
42 public override void AggregateElement(IElement Element)
43 {
44 if (this.isDouble && Element is DoubleNumber D)
45 this.doubleSum += D.Value;
46 else if (this.sum is null)
47 {
48 this.isDouble = false;
49
50 if (this.count == 0)
51 this.sum = Element;
52 else
53 this.sum = Add.EvaluateAddition(new DoubleNumber(this.doubleSum), Element, this.Node);
54 }
55 else
56 this.sum = Add.EvaluateAddition(this.sum, Element, this.Node);
57
58 this.count++;
59 }
60
64 public override IElement GetAggregatedResult()
65 {
66 if (this.count == 0)
67 return ObjectValue.Null;
68 else if (this.isDouble)
69 return new DoubleNumber(this.doubleSum / this.count);
70 else if (this.count == 1)
71 return this.sum;
72 else
73 return Divide.EvaluateDivision(this.sum, new DoubleNumber(this.count), this.Node);
74 }
75 }
76}
Base class for all types of elements.
Definition: Element.cs:14
Average(v), Avg(v) iterative evaluator
override IElement GetAggregatedResult()
Gets the aggregated result.
override void AggregateElement(IElement Element)
Aggregates one new element.
override void RestartEvaluator()
Restarts the evaluator.
AverageEvaluator(Average Node)
Average(v), Avg(v) iterative evaluator
An interative evaluator of a function or operation defined by a single ScriptNode.
ScriptNode Node
Node being iteratively evaluated.
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:88
static IElement EvaluateAddition(IElement Left, IElement Right, ScriptNode Node)
Adds two operands.
Definition: Add.cs:65
static IElement EvaluateDivision(IElement Left, IElement Right, ScriptNode Node)
Divides the right operand from the left one.
Definition: Divide.cs:65
Basic interface for all types of elements.
Definition: IElement.cs:21