esper计算问题,有会的大神麻烦贴下代码,非常感谢

问题描述

esper计算问题,有会的大神麻烦贴下代码,非常感谢

1.字段是sbn,me,NodeB,cellID,都是int类型,time是long类型
2.100个计数器,分别是C1-C100,其中C1-C50是求sum,C51-C80是求avg,C81-C90是求max,C91-C100是求min
3.sendEvent(),发送事件1W条
4.汇总,time_batch(1 min)
5.updateListener 输出

实体类:
@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter @Setter
public class CounterInfo {
private int sbn;
private int me;
private int nodeB;
private int cellId;
private long time;
}

updateListener监听:
public void update(EventBean[] newEvents, EventBean[] oldEvents) {
//EsCounter esCounter = new EsCounter();
if(newEvents != null){
int sumC1 = (Integer) newEvents[0].get("C1");
Double avgC2 = (Double) newEvents[0].get("C2");
int maxC3 = (Integer) newEvents[0].get("C3");
int minC4 = (Integer) newEvents[0].get("C4");
System.out.println("C1 Sum is:"+sumC1);
System.out.println("C2 Avg is:"+avgC2);
System.out.println("C3 Max is:"+maxC3);
System.out.println("C4 Max is:"+minC4);
}

        main方法测试类:
        public static void main(String[] args) {

    EPServiceProvider provider = EPServiceProviderManager.getDefaultProvider();
    EPAdministrator administrator =provider.getEPAdministrator();
    EPRuntime runtime = provider.getEPRuntime();

    String esCounter = EsCounter.class.getName();
    String counterInfo = CounterInfo.class.getName();
    Map<String, Object> counterMap = null;

    String epl ="select sbn,me,nodeB,cellID,sum(C1) as C1,avg(C2) as C2,max(C3) as C3,min(C4) as C4 from "+ counterInfo +".win:time_batch(1 min) group by sbn,me,nodeB,cellID";
    /*String epl ="select sum(C1) as C1,avg(C2) as C2,max(C3) as C3,min(C4) as C4 "
            + "from "+counterInfo+".win:time_batch(1 min)";*/
    EPStatement statement = administrator.createEPL(epl);
    statement.addListener(new CounterListener());

    for (int i = 1; i < 10000; i++) {
        counterMap = new HashMap<String, Object>();
        counterMap.put("C" +  (new Random().nextInt(100)+1), new Random().nextInt(6)+1);
        System.out.println("send event"+i+":"+counterMap);
        runtime.sendEvent(counterMap);
    }

}

循环的1万条事件放入到100个计数器里面。

有会的大神帮忙回复下,非常感谢

解决方案

虽然没搞明白你要干嘛, 但是从模糊的描述中我大概差不多知道了你的意思...
贴下代码. 自己吧c1-c50补充完整就可以了. 下面的示例是 1sec 自己改1 min吧
直接可运行

 package test.esper_epl;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import com.espertech.esper.client.EPAdministrator;
import com.espertech.esper.client.EPRuntime;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.client.UpdateListener;

public class MapEpl {

    public static void main(String[] args) throws InterruptedException {

        EPServiceProvider provider = EPServiceProviderManager.getDefaultProvider();
        EPAdministrator administrator =provider.getEPAdministrator();
        EPRuntime runtime = provider.getEPRuntime();

        String counterInfo = CounterInfo.class.getName();

        String epl ="select sbn,me,nodeB,cellId, sum(cccc('C1')) as c1_sum, sum(cccc('C2')) as c2_sum, avg(cccc('C1')) as c1_avg, avg(cccc('C2')) as c2_avg  from "+ counterInfo +".win:time_batch(1 sec) group by sbn,me,nodeB,cellId";
        EPStatement statement = administrator.createEPL(epl);
        statement.addListener(new CounterListener());

        for (int j=0;j<10000;j++){
            CounterInfo counterinfo=new CounterInfo();

            counterinfo.setCellId(1);
            counterinfo.setMe(2);
            counterinfo.setNodeB(3);
            counterinfo.setSbn(4);
            counterinfo.setTime(5);

            //搞计数器??? 计数器是什么  ?
            Map<String, Integer> counterMap = new HashMap<String, Integer>();
            for (int i = 1; i < 10000; i++) {
                counterMap.put("C" +  (new Random().nextInt(100)+1), new Random().nextInt(6)+1);
            }
            counterinfo.setCccc(counterMap);
            runtime.sendEvent(counterinfo);
        }

        TimeUnit.SECONDS.sleep(6000);
    }
}

class CounterListener implements UpdateListener {

    @Override
    public void update(EventBean[] newEvents, EventBean[] oldEvents) {
        if (newEvents != null)
        {
            for (int i=0;i<newEvents.length;i++){
                Object event = newEvents[i].getUnderlying();
                System.out.println("输出............计数器什么的...");
                System.out.println(event);
            }
        }
    }

}

class CounterInfo {
    private int sbn;
    private int me;
    private int nodeB;
    private int cellId;
    private long time;
    Map<String, Integer> 计数器什么的esper里面没有啊;
    Map<String, Integer> cccc;  

    public int getSbn() {
        return sbn;
    }
    public void setSbn(int sbn) {
        this.sbn = sbn;
    }
    public int getMe() {
        return me;
    }
    public void setMe(int me) {
        this.me = me;
    }
    public int getNodeB() {
        return nodeB;
    }
    public void setNodeB(int nodeB) {
        this.nodeB = nodeB;
    }
    public int getCellId() {
        return cellId;
    }
    public void setCellId(int cellId) {
        this.cellId = cellId;
    }
    public long getTime() {
        return time;
    }
    public void setTime(long time) {
        this.time = time;
    }
    public Map<String, Integer> get计数器什么的esper里面没有啊() {
        return 计数器什么的esper里面没有啊;
    }
    public void set计数器什么的esper里面没有啊(Map<String, Integer> 计数器什么的esper里面没有啊) {
        this.计数器什么的esper里面没有啊 = 计数器什么的esper里面没有啊;
    }
    public Map<String, Integer> getCccc() {
        return cccc;
    }
    public void setCccc(Map<String, Integer> cccc) {
        this.cccc = cccc;
    }

    }

解决方案二:

http://blog.csdn.net/luonanqin/article/details/12224303

解决方案三:

你指的计数器是什么? 为什么不在一条epl中求出所有的计算, select sum(),avg(), max(),min() from event.win:time_batch(60 sec)?

解决方案四:

求大神们指教下啊:
1,字段该怎么使用,直接用于epl里面会报错,
2.创建一个map集合,把计数器当key,事件当做value,循环一万次,值该怎么添加到计数器里面
3.map集合循环中,新的key,value会把之前同样的覆盖掉吧
4.epl语句提交后,updatelistener该怎么去输出
5.epl语句中的sum(C1)到sum(50)该如何去简化

解决方案五:

epl ="select sbn,me,nodeB,cellID,sum(C1) as C1,avg(C2) as C2,max(C3) as C3,min(C4) as C4 from "+ counterInfo +".win:time_batch(1 min) group by sbn,me,nodeB,cellID";

解决方案六:

antibodies 2016.04.27 08:57
你指的计数器是什么? 为什么不在一条epl中求出所有的计算, select sum(),avg(), max(),min() from event.win:time_batch(60 sec)?

大神,该怎么写啊,求教。。

解决方案七:

什么场景? 需求是什么? 其实看完二楼提供的epl应该就可以搞定大多数情况了.

解决方案八:

没什么需求,就是要用一条epl语句,对计数器C1-C50这50个计数器分别求和,就是sum(C1),sum(C2)...sum(C50),还有C51到C80求平均数,avg(C51),avg(C52)..avg(C80),max(C81)..max(C90),min(C91)...min(C100).
做全部的计算,主要现在我不知道给的字段干嘛的,说是直接写到epl语句,但问题没值,运行就报错的,我想知道刚开始的类该怎么去写,然后1W条事件怎么分发到100个计数器里面去。
我是用的map方法

for (int i = 1; i < 10000; i++) {
counterMap = new HashMap();
//counterMap.put("C0" , 1);
counterMap.put("C" + (new Random().nextInt(100)+1), new Random().nextInt(6)+1);
System.out.println(counterMap);
runtime.sendEvent(counterMap);
}
这个出来新的map(key,value),会把上一个同样key的值覆盖掉的吧。

解决方案九:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter @Setter
public class CounterInfo {
private int sbn;
private int me;
private int nodeB;
private int cellId;
private long time;

}
String counterInfo = CounterInfo.class.getName();
String epl="select sbn,me,nodeB,cellID,sum(C1) as C1,avg(C2) as C2,max(C3) as C3,min(C4) as C4 from "+ esCounter +".win:time_batch(1 min) group by sbn,me,nodeB,cellID";
EPStatement statement = administrator.createEPL(epl);
statement.addListener(new CounterListener());

报错:log4j:WARN No appenders could be found for logger (com.espertech.esper.core.service.EPServiceProviderImpl).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" com.espertech.esper.client.EPStatementException: Error starting statement: Property named 'cellID' is not valid in any stream (did you mean 'cellId'?) [select sbn,me,nodeB,cellID,sum(C1) as C1,avg(C2) as C2,max(C3) as C3,min(C4) as C4 from com.zte.entity.CounterInfo.win:time_batch(1 min) group by sbn,me,nodeB,cellID]
at com.espertech.esper.core.service.StatementLifecycleSvcImpl.startInternal(StatementLifecycleSvcImpl.java:637)
at com.espertech.esper.core.service.StatementLifecycleSvcImpl.start(StatementLifecycleSvcImpl.java:595)
at com.espertech.esper.core.service.StatementLifecycleSvcImpl.createAndStart(StatementLifecycleSvcImpl.java:137)
at com.espertech.esper.core.service.EPAdministratorImpl.createEPLStmt(EPAdministratorImpl.java:117)
at com.espertech.esper.core.service.EPAdministratorImpl.createEPL(EPAdministratorImpl.java:66)
at com.zte.esper.CounterForTest.main(CounterForTest.java:39)
Caused by: com.espertech.esper.epl.expression.ExprValidationPropertyException: Property named 'cellID' is not valid in any stream (did you mean 'cellId'?)
at com.espertech.esper.epl.expression.ExprIdentNodeUtil.getSuggestionException(ExprIdentNodeUtil.java:183)
at com.espertech.esper.epl.expression.ExprIdentNodeUtil.getTypeFromStream(ExprIdentNodeUtil.java:59)
at com.espertech.esper.epl.expression.ExprIdentNodeImpl.validate(ExprIdentNodeImpl.java:150)
at com.espertech.esper.epl.expression.ExprNodeUtility.getValidatedSubtreeInternal(ExprNodeUtility.java:147)
at com.espertech.esper.epl.expression.ExprNodeUtility.getValidatedSubtree(ExprNodeUtility.java:122)
at com.espertech.esper.epl.core.ResultSetProcessorFactoryFactory.getProcessorPrototype(ResultSetProcessorFactoryFactory.java:114)
at com.espertech.esper.core.start.EPStatementStartMethodSelectUtil.prepare(EPStatementStartMethodSelectUtil.java:278)
at com.espertech.esper.core.start.EPStatementStartMethodSelect.startInternal(EPStatementStartMethodSelect.java:51)
at com.espertech.esper.core.start.EPStatementStartMethodBase.start(EPStatementStartMethodBase.java:53)
at com.espertech.esper.core.service.StatementLifecycleSvcImpl.startInternal(StatementLifecycleSvcImpl.java:625)
... 5 more

类的问题,该怎么去做的了

时间: 2024-10-02 02:50:26

esper计算问题,有会的大神麻烦贴下代码,非常感谢的相关文章

jsp-求教:哪位大神帮忙看下代码,本人小白,实在不知道哪里有问题!!

问题描述 求教:哪位大神帮忙看下代码,本人小白,实在不知道哪里有问题!! 代码如下,登陆页面,把java逻辑放到了后台页面上,运行的时候没有报错,但是不跳转.测试账号密码正确不跳转因为没写,但是测试账号密码错误的情况下也不跳转. <%@ page language=""java"" import=""java.util.*java.sql.*info.DataBase"" pageEncoding=""

c语言-C语言小白请大神帮忙改一下代码,谢谢。

问题描述 C语言小白请大神帮忙改一下代码,谢谢. #include #include #include #include #include void choose();//选择函数 void shu();//猜数字函数 void paihang();//排行榜 void repaihang(int n);//更新排行榜 void replace();//初始化排行榜(没有记录时的排行榜) typedef struct { char name[10]; int score; }re; int ma

编程-跪求大神帮忙看下代码,错了不晓得怎么改哦

问题描述 跪求大神帮忙看下代码,错了不晓得怎么改哦 switch (uMsg) { case WM_CHAR: char szChar[20]; sprintf(_T(szChar),_T( "char code is %d"), wParam); 错误 1 error C2065: "LszChar": 未声明的标识符 IntelliSense: "const wchar_t *" 类型的实参与 "const char *"

java-小白求助,求大神帮忙修改下代码

问题描述 小白求助,求大神帮忙修改下代码 我的条件是condition=1|2|3|4|5.... if (source.getProperty(""condition"" + NUM).equals(""1"")) { return p.panduan1(readrow source); } else if (source.getProperty(""condition"" + NUM

arraylist-求大神帮看下代码,怎么做才能接收自己输入的字符串进行判断呢?

问题描述 求大神帮看下代码,怎么做才能接收自己输入的字符串进行判断呢? public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("请输入你要查询出现单词或字母次数句子"); ArrayList<Object> arrayList = new ArrayList<Object>(); String f = s.nextLine()

java大神帮忙看下代码越界问题

问题描述 java大神帮忙看下代码越界问题 package com.net.ch02; public class Split { public void func(String str,String s){ String Str = s+str+s; String[]array = new String[100]; int[]ray = new int[100]; for(int i = 1 ; i<=Str.length();i++ ){array[i-1] = Str.substring(i

大神帮忙解释下代码,关于求一个数的绝对值的趣味解法

问题描述 packageNO4;publicclassTest24{staticintabsoluteValue(intnum){intmax=0;for(inti=0;true;i++){max=i>max?i:max;if(i==num){if(i>=max)returni;//elsereturn-i;}}}publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubSystem.out.println(absolut

php开发遇到错误 Creating default object from empty value 求大神帮忙解决下

问题描述 php开发遇到错误 Creating default object from empty value 求大神帮忙解决下 代码: 14 define('IN_ECS', true); 15 $smarty->left_delimiter = '<!--{'; 16 $smarty->right_delimiter = '}-->'; 17 require(dirname(__FILE__) . '/includes/init.php'); 18 if ((DEBUG_MOD

pascal 编程-pascal 问题 计算式子的值 求大神指点

问题描述 pascal 问题 计算式子的值 求大神指点 描述 Description 给定一个表达式串,计算其最后结果 输入格式 Input Format 一个表达式串(只包函+-*/()等运算符,且是整除;表达式长度小于255个字符) 输出格式 Output Format 最后结果(一个整数) 样例输入 1+2*3+(1+2) 样例输出 10 program p1654; var tot:ansistring; function f(st:ansistring):longint; var i,