/// <summary>
        /// The Execute() function will be called, when a new tuple is available.
        /// </summary>
        /// <param name="tuple"></param>
        public void Execute(SCPTuple tuple)
        {
            if (tuple.GetSourceStreamId().Equals(Constants.SYSTEM_TICK_STREAM_ID))
            {
                Context.Logger.Info("Aggregates tuple values..");

                foreach (var key in _data.Keys)
                {
                    var avg = _data[key].Average();

                    this.ctx.Emit(Constants.DEFAULT_STREAM_ID, tuplesToAck, new Values(key, avg));
                }

                Context.Logger.Info("acking the batch: " + tuplesToAck.Count);

                foreach (var t in tuplesToAck)
                {
                    this.ctx.Ack(t);
                }

                _data.Clear();
                tuplesToAck.Clear();
            }
            else
            {
                var sensorName = tuple.GetString(0);
                var value      = tuple.GetDouble(1);

                if (!_data.ContainsKey(tuple.GetString(0)))
                {
                    _data.Add(sensorName, new List <double>()
                    {
                        value
                    });
                }
                else
                {
                    _data[sensorName].Add(value);
                }

                tuplesToAck.Enqueue(tuple);
            }
        }
        /// <summary>
        /// The Execute() function will be called, when a new tuple is available.
        /// </summary>
        /// <param name="tuple"></param>
        public void Execute(SCPTuple tuple)
        {
            var sensor = tuple.GetString(0);
            var value  = tuple.GetDouble(1);

            //really add logic here!!
            if (sensor.Equals("Sensor-A", StringComparison.InvariantCultureIgnoreCase)
                &&
                value > 10)
            {
                Context.Logger.Warn("The sensor {0} throw alarms by {1} value", sensor, value);

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

            this.ctx.Ack(tuple);
        }
示例#3
0
        public void Execute(SCPTuple tuple)
        {
            try
            {
                double tempReading = tuple.GetDouble(0);
                String createDate  = tuple.GetString(1);
                String deviceId    = tuple.GetString(2);

                if (tempReading > _maxAlertTemp)
                {
                    _context.Emit(new Values(
                                      "reading above bounds",
                                      tempReading,
                                      createDate,
                                      deviceId
                                      ));
                    Context.Logger.Info("Emitting above bounds: " + tempReading);
                }
                else if (tempReading < _minAlertTemp)
                {
                    _context.Emit(new Values(
                                      "reading below bounds",
                                      tempReading,
                                      createDate,
                                      deviceId
                                      ));
                    Context.Logger.Info("Emitting below bounds: " + tempReading);
                }

                _context.Ack(tuple);
            }
            catch (Exception ex)
            {
                Context.Logger.Error(ex.ToString());
            }
        }