public void Execute(SCPTuple tuple)
        {
            var sensor = tuple.GetSensor();

            _ctx.Emit(Constants.DEFAULT_STREAM_ID, new List <object>()
            {
                sensor.Name, sensor.Value
            });

            _ctx.Ack(tuple);
        }
示例#2
0
        public void Execute(SCPTuple tuple)
        {
            if (tuple.IsTick())
            {
                Context.Logger.Warn("ON TICK, Ticks Number {0}", _aggregateValues.Keys.Count);

                foreach (var item in _aggregateValues.Keys)
                {
                    List <double> values;
                    if (_aggregateValues.TryGetValue(item, out values))
                    {
                        var average = values.Average();

                        var aggregate = new SensorAggregate()
                        {
                            Name    = item,
                            Average = average
                        };

                        Context.Logger.Info("Emiting aggreagate");

                        var serialized = JsonConvert.SerializeObject(aggregate);

                        ctx.Emit(Constants.DEFAULT_STREAM_ID, new List <object>()
                        {
                            serialized
                        });
                    }
                }
            }
            else
            {
                var sensor = tuple.GetSensor();

                if (sensor != null)
                {
                    _aggregateValues.AddOrUpdate(sensor.Name, new List <double>()
                    {
                        sensor.Value
                    }, (key, currentValues) =>
                    {
                        currentValues.Add(sensor.Value);

                        return(currentValues);
                    });
                }
            }
        }
示例#3
0
        public void Execute(SCPTuple tuple)
        {
            if (!tuple.IsTick())
            {
                var sensor = tuple.GetSensor();

                if (sensor != null)
                {
                    var serializedContent = JsonConvert.SerializeObject(sensor);

                    this.ctx.Emit(Constants.DEFAULT_STREAM_ID, new List <object>()
                    {
                        serializedContent
                    });
                }

                this.ctx.Ack(tuple);
            }
        }