Time 如何在esper中记录事件的到达时间

Time 如何在esper中记录事件的到达时间,time,esper,Time,Esper,我想用esper记录一个数据处理时间,我选择了布林带作为例子。在布林格带中,有一个叫做移动平均线(MA)。从计算股票平均价格的结果中得出。在本例中,我设置win:length(20)。因此,MA可以从数据窗口视图中存在的20个事件的平均股价计算结果中获得。下面是我创建的代码 public class BollingerBand { static double startTime, finishTime; public static void main (String [] ar

我想用esper记录一个数据处理时间,我选择了布林带作为例子。在布林格带中,有一个叫做移动平均线(MA)。从计算股票平均价格的结果中得出。在本例中,我设置win:length(20)。因此,MA可以从数据窗口视图中存在的20个事件的平均股价计算结果中获得。下面是我创建的代码

public class BollingerBand {
    static double startTime, finishTime;

    public static void main (String [] args){
        Configuration configuration = new Configuration();
        configuration.addEventType("Stock", Stock.class);

        EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
        AdapterInputSource source = new AdapterInputSource("BollingerBand.csv");

        EPStatement statement = epService.getEPAdministrator().createEPL("insert into Aggregation " +
                "select prevcount(symbol), symbol, avg(price) as SimpleMovingAverage, stddev(price) as StandardDeviation, " +
                "last(price) as price, last(timestamp) as date from Stock.std:groupwin(symbol).win:length(20)" +
                " group by symbol having count(*) >=20");

        statement.addListener(new UpdateListener() {

            public void update(EventBean[] newEvents, EventBean[] oldEvents) {
                // TODO Auto-generated method stub
                //System.out.println("Event Receive : "+newEvents[0].getUnderlying());
                startTime = System.currentTimeMillis();
                System.out.println("\nStart time : " + startTime + " miliseconds\n");
            }
        });

        EPStatement statement2 = epService.getEPAdministrator().createEPL("select symbol, " +
                 "SimpleMovingAverage + 2*StandardDeviation as UpperBand," +
                 "SimpleMovingAverage as MiddleBand," +
                 "SimpleMovingAverage - 2*StandardDeviation as LowerBand," +
                 "price," +
                 "4*StandardDeviation/SimpleMovingAverage as Bandwidth," +
                 "(price - (SimpleMovingAverage - (2 * StandardDeviation))) / ((SimpleMovingAverage + " +
                 "(2 * StandardDeviation)) - (SimpleMovingAverage - (2 * StandardDeviation))) as PercentB," +
                 "date from Aggregation");

        statement2.addListener(new UpdateListener() {

            public void update(EventBean[] newEvents, EventBean[] oldEvents) {
                // TODO Auto-generated method stub
                //System.out.println("Event Receive : "+newEvents[0].getUnderlying());
                finishTime = System.currentTimeMillis();
                System.out.println("Start time : " + startTime + " miliseconds");
                System.out.println("Finish time : " + finishTime + " miliseconds");
                System.out.println("Processing time : " + (finishTime-startTime) + " miliseconds");
            }
        });

        (new CSVInputAdapter(epService, source, "Stock")).start();
    }

}

根据上述代码,如果已计算平均值,则将记录时间。但我需要的是,我想要记录第20个事件和下一个事件进入数据窗口视图时的时间。它是根据布林带计算结果得出的开始时间和结束时间。我的问题是如何记录第20个事件的时间,同时在下一个事件中输入窗口视图数据。请帮助

发送事件时,CSV适配器不提供回调。但是,您可以轻松地更改其代码。或者,您可以使用不同的CSV读取器,并通过运行时API发送事件。

可能有某种滴答计数器,其中有一个映射,其中包含一个键值对(项计数和时间戳)。您可以在第二个UpdateListener中更新此项,当然您可以始终查找键20的项

顺便说一句,我用了你的布林带计算,但用的是暴风雪和艾斯波特。在这里写博客:

你能给我详细解释一下吗?也许你可以举个例子来解释。