예제 #1
0
  public void testCorrel() {
    // further math tests can be found in the view unit test
    EPAdministrator admin = epService.getEPAdministrator();
    admin.getConfiguration().addEventType("Market", SupportMarketDataBean.class);
    EPStatement statement =
        admin.createEPL(
            "select * from Market.std:groupwin(symbol).win:length(1000000).stat:correl(price, volume, feed)");
    SupportUpdateListener listener = new SupportUpdateListener();
    statement.addListener(listener);

    assertEquals(Double.class, statement.getEventType().getPropertyType("correlation"));

    String[] fields = new String[] {"symbol", "correlation", "feed"};

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 10.0, 1000L, "f1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", Double.NaN, "f1"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 1.0, 2L, "f2"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", Double.NaN, "f2"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 2.0, 4L, "f3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", 1.0, "f3"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 20.0, 2000L, "f4"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", 1.0, "f4"});
  }
예제 #2
0
  public static void main(String[] args) {
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
    EPAdministrator admin = epService.getEPAdministrator();

    // Apple定义
    Map<String, Object> apple = new HashMap<String, Object>();
    apple.put("id", int.class);
    apple.put("price", int.class);

    // 注册Apple到Esper
    admin.getConfiguration().addEventType("Apple", apple);

    String epl = "select avg(price) from Apple.win:length_batch(3)";

    EPStatement state = admin.createEPL(epl);
    state.addListener(new AppleListener());

    EPRuntime runtime = epService.getEPRuntime();

    Map<String, Object> apple1 = new HashMap<String, Object>();
    apple1.put("id", 1);
    apple1.put("price", 5);
    runtime.sendEvent(apple1, "Apple");

    Map<String, Object> apple2 = new HashMap<String, Object>();
    apple2.put("id", 2);
    apple2.put("price", 2);
    runtime.sendEvent(apple2, "Apple");

    Map<String, Object> apple3 = new HashMap<String, Object>();
    apple3.put("id", 3);
    apple3.put("price", 5);
    runtime.sendEvent(apple3, "Apple");
  }
예제 #3
0
  private void registerEventStream(EventDefinition def) {
    log.info("registering event type stream %s", def.getEventType());
    for (String ns : namespaces) {
      EPAdministrator admin = EsperProvider.getProvider(ns).getEPAdministrator();

      HashMap<String, Object> m = new HashMap<String, Object>();
      for (Map.Entry<String, Class> entry : def.getProperties().entrySet()) {
        m.put(entry.getKey(), entry.getValue());
      }

      admin.getConfiguration().addEventType(def.getEventType(), m);
      inputEventRegistrationsValid.add(def.getEventType());
    }
    notifyEventRegistered(def);
  }
예제 #4
0
  public void testLinest() {
    // further math tests can be found in the view unit test
    EPAdministrator admin = epService.getEPAdministrator();
    admin.getConfiguration().addEventType("Market", SupportMarketDataBean.class);
    EPStatement statement =
        admin.createEPL(
            "select * from Market.std:groupwin(symbol).win:length(1000000).stat:linest(price, volume, feed)");
    SupportUpdateListener listener = new SupportUpdateListener();
    statement.addListener(listener);

    assertEquals(Double.class, statement.getEventType().getPropertyType("slope"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YIntercept"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("XAverage"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("XStandardDeviationPop"));
    assertEquals(
        Double.class, statement.getEventType().getPropertyType("XStandardDeviationSample"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("XSum"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("XVariance"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YAverage"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YStandardDeviationPop"));
    assertEquals(
        Double.class, statement.getEventType().getPropertyType("YStandardDeviationSample"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YSum"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("YVariance"));
    assertEquals(Long.class, statement.getEventType().getPropertyType("dataPoints"));
    assertEquals(Long.class, statement.getEventType().getPropertyType("n"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumX"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumXSq"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumXY"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumY"));
    assertEquals(Double.class, statement.getEventType().getPropertyType("sumYSq"));

    String[] fields = new String[] {"symbol", "slope", "YIntercept", "feed"};

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 10.0, 50000L, "f1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        fields,
        new Object[] {"ABC", Double.NaN, Double.NaN, "f1"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 1.0, 1L, "f2"));
    EventBean theEvent = listener.assertOneGetNewAndReset();
    EPAssertionUtil.assertProps(
        theEvent, fields, new Object[] {"DEF", Double.NaN, Double.NaN, "f2"});
    assertEquals(1d, theEvent.get("XAverage"));
    assertEquals(0d, theEvent.get("XStandardDeviationPop"));
    assertEquals(Double.NaN, theEvent.get("XStandardDeviationSample"));
    assertEquals(1d, theEvent.get("XSum"));
    assertEquals(Double.NaN, theEvent.get("XVariance"));
    assertEquals(1d, theEvent.get("YAverage"));
    assertEquals(0d, theEvent.get("YStandardDeviationPop"));
    assertEquals(Double.NaN, theEvent.get("YStandardDeviationSample"));
    assertEquals(1d, theEvent.get("YSum"));
    assertEquals(Double.NaN, theEvent.get("YVariance"));
    assertEquals(1L, theEvent.get("dataPoints"));
    assertEquals(1L, theEvent.get("n"));
    assertEquals(1d, theEvent.get("sumX"));
    assertEquals(1d, theEvent.get("sumXSq"));
    assertEquals(1d, theEvent.get("sumXY"));
    assertEquals(1d, theEvent.get("sumY"));
    assertEquals(1d, theEvent.get("sumYSq"));
    // above computed values tested in more detail in RegressionBean test

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 2.0, 2L, "f3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", 1.0, 0.0, "f3"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 11.0, 50100L, "f4"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", 100.0, 49000.0, "f4"});
  }
예제 #5
0
  /** @param args */
  public static void main(String[] args) {
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();

    EPAdministrator admin = epService.getEPAdministrator();

    Map<String, Object> mapDef = new HashMap<String, Object>();
    mapDef.put("p", Product.class);

    Map<String, Object> mapDef1 = new HashMap<String, Object>();
    mapDef1.put("count", int.class);

    admin.getConfiguration().addEventType("S", mapDef);
    admin.getConfiguration().addEventType("Scount", mapDef1);
    admin.getConfiguration().addEventType("Acount", mapDef1);

    EPRuntime runtime = epService.getEPRuntime();

    String product = Product.class.getName();
    String close = User.class.getName();

    String input = "select irstream *, prevwindow(i) from " + product + ".win:time(5 sec) as i";
    String window = "create window ABC.win:keepall() as select * from S";
    String output =
        "insert into ABC select * from pattern[every a=S -[1]> b=S(b.p.price>=(a.p.price*1.05))]";
    String acount = "on " + close + " select and delete count(*) from ABC";
    String result = "every b=Acount -> every a=Scount(b.count+1=a.count)";

    EPStatement state1 = admin.createEPL(input);
    state1.addListener(new InputListener(runtime));
    admin.createEPL(window);
    admin.createEPL(output);
    EPStatement state2 = admin.createEPL(acount);
    state2.addListener(new AcountListener(runtime));
    EPStatement state3 = admin.createPattern(result);
    state3.addListener(new Result3Listener());

    Product esb = new Product();
    esb.setPrice(1);
    esb.setType("esb");
    runtime.sendEvent(esb);

    Product eos = new Product();
    eos.setPrice(2);
    eos.setType("eos");
    runtime.sendEvent(eos);

    Product esb1 = new Product();
    esb1.setPrice(3);
    esb1.setType("esb");
    runtime.sendEvent(esb1);

    Product eos1 = new Product();
    eos1.setPrice(5);
    eos1.setType("eos");
    runtime.sendEvent(eos1);

    Product esb2 = new Product();
    esb2.setPrice(6);
    esb2.setType("esb");
    runtime.sendEvent(esb2);

    Product eos3 = new Product();
    eos3.setPrice(7);
    eos3.setType("eos");
    runtime.sendEvent(eos3);

    System.out.println();
  }