Example #1
0
        private void HandleInitialPriceEvent(object sender,
                                             UpdateEventArgs e)
        {
            var tick  = (StockTick)e.NewEvents[0].Get("tick");
            var limit = _limit;

            _initialPriceListener = null;

            var limitPct   = limit.LimitPct;
            var upperLimit = tick.Price * (1.0 + limitPct / 100.0);
            var lowerLimit = tick.Price * (1.0 - limitPct / 100.0);

            if (Log.IsDebugEnabled)
            {
                Log.Debug(
                    ".update Received initial tick, stock=" +
                    tick.StockSymbol +
                    "  Price=" +
                    tick.Price +
                    "  limit.LimitPct=" +
                    limitPct +
                    "  lowerLimit=" +
                    lowerLimit +
                    "  upperLimit=" +
                    upperLimit);
            }

            var listener =
                new StockTickerAlertListener(
                    _runtime,
                    limit,
                    tick,
                    _stockTickerResultListener);

            var expressionText = "every tick=StockTick" +
                                 "(StockSymbol='" +
                                 limit.StockSymbol +
                                 "', Price < " +
                                 lowerLimit +
                                 ")";

            _lowPriceListener         = _runtime.DeployStatement(expressionText);
            _lowPriceListener.Events += listener.Update;

            expressionText = "every tick=StockTick" +
                             "(StockSymbol='" +
                             limit.StockSymbol +
                             "', Price > " +
                             upperLimit +
                             ")";
            _highPriceListener         = _runtime.DeployStatement(expressionText);
            _highPriceListener.Events += listener.Update;
        }
Example #2
0
        public static EPStatement Create(EPRuntime runtime)
        {
            var stmt = "insert into TicksPerSecond " +
                       "select Feed as feed, count(*) as cnt from MarketDataEvent.win:time_batch(1 sec) group by Feed";

            return(runtime.DeployStatement(stmt));
        }
Example #3
0
        public static EPStatement Create(EPRuntime runtime)
        {
            var stmt = "select feed, avg(cnt) as avgCnt, cnt as feedCnt from TicksPerSecond.win:time(10 sec) " +
                       "group by feed, cnt " +
                       "having cnt < avg(cnt) * 0.75 ";

            return(runtime.DeployStatement(stmt));
        }
Example #4
0
        public static EPStatement Create(EPRuntime runtime)
        {
            var stmt = "select ID as sensorId, coalesce(sum(countTags), 0) as numTagsPerSensor " +
                       "from AutoIdRFIDExample.win:time(60 sec) " +
                       "where Observation[0].Command = 'READ_PALLET_TAGS_ONLY' " +
                       "group by ID";

            return(runtime.DeployStatement(stmt));
        }
        public static void Start()
        {
            _runtime = EPRuntimeProvider.GetDefaultRuntime();

            var eventName    = typeof(LatencyLimit).FullName;
            var latencyAlert = _runtime.DeployStatement("every newlimit=" + eventName);

            latencyAlert.Events +=
                (sender, e) => { new DynaLatencySpikeMonitor((LatencyLimit)e.NewEvents[0]["newlimit"]); };
        }
Example #6
0
        public FraudMonitor(EPRuntime runtime, EventHandler <UpdateEventArgs> eventHandler)
        {
            string joinStatement = "select fraud.accountNumber as accountNumber, fraud.warning as warning, withdraw.amount as amount, " +
                                   "max(fraud.timestamp, withdraw.timestamp) as timestamp, 'withdrawlFraudWarn' as descr from " +
                                   "FraudWarning.win:time(30 min) as fraud," +
                                   "Withdrawal.win:time(30 sec) as withdraw" +
                                   " where fraud.accountNumber = withdraw.accountNumber";

            joinView         = runtime.DeployStatement(joinStatement);
            joinView.Events += eventHandler;
        }
Example #7
0
        public StockTickerMonitor(
            EPRuntime runtime,
            StockTickerResultListener stockTickerResultListener)
        {
            _runtime = runtime;
            _stockTickerResultListener = stockTickerResultListener;

            // Listen to all limits to be set
            var         expressionText = "every Pricelimit=PriceLimit()";
            EPStatement factory        = runtime.DeployStatement(expressionText);

            factory.Events += HandleEvents;
        }
Example #8
0
        public StockTickerMonitor(
            EPRuntime runtime,
            PriceLimit limit,
            StockTickerResultListener stockTickerResultListener)
        {
            _runtime = runtime;
            _limit   = limit;
            _stockTickerResultListener = stockTickerResultListener;

            var expressionText = "every Pricelimit=PriceLimit" +
                                 "(UserId='" +
                                 limit.UserId +
                                 "'," +
                                 "StockSymbol='" +
                                 limit.StockSymbol +
                                 "')";

            _newLimitListener         = runtime.DeployStatement(expressionText);
            _newLimitListener.Events += HandleNewLimitEvent;

            expressionText                = "tick=StockTick(StockSymbol='" + limit.StockSymbol + "')";
            _initialPriceListener         = runtime.DeployStatement(expressionText);
            _initialPriceListener.Events += HandleInitialPriceEvent;
        }
        public DynaLatencySpikeMonitor(LatencyLimit limit)
        {
            Log.Debug("New limit, for operation '" + limit.OperationName +
                      "' and customer '" + limit.CustomerId + "'" +
                      " setting threshold " + limit.LatencyThreshold);

            var filter = "operationName='" + limit.OperationName +
                         "',customerId='" + limit.CustomerId + "'";

            // Alert specific to operation and customer
            _spikeLatencyDeployment = _runtime.CompileDeploy(
                "every alert=" + typeof(OperationMeasurement).FullName +
                "(" + filter + ", latency>" + limit.LatencyThreshold + ")");
            _spikeLatencyAlert         = _spikeLatencyDeployment.Statements[0];
            _spikeLatencyAlert.Events += LogLatencyEvent;

            // Stop pattern when the threshold changes
            var eventName   = typeof(LatencyLimit).FullName;
            var stopPattern = _runtime.DeployStatement(eventName + "(" + filter + ")");

            stopPattern.Events += ((newEvents, oldEvents) => _runtime
                                   .DeploymentService.Undeploy(_spikeLatencyAlert.DeploymentId));
        }