Package com.taobao.top.analysis.statistics.data.impl

Examples of com.taobao.top.analysis.statistics.data.impl.SimpleCalculator


          content.lastIndexOf(")"));
      entry.setGroupFunction(GroupFunctionFactory.getFunction(type));
      if (content.indexOf("entry(") >= 0){
        entry.setLazy(true);
      }
      entry.setCalculator(new SimpleCalculator(expression, aliasPool));
    }


    if (start.getAttributeByName(new QName("", "lazy")) != null) {
      entry.setLazy(Boolean.valueOf(start.getAttributeByName(
View Full Code Here


          .get(entryId);
      if (entry.isLazy())
      {
        if (result.get(entryId) == null)
          result.put(entryId, new HashMap<String, Object>());
        SimpleCalculator c = (SimpleCalculator)entry.getCalculator();
        if (c.getBindingStack() != null
            && c.getBindingStack().size() > 0) {
          List<Object> _bindingStack = c.getBindingStack();
          int size = _bindingStack.size();

          String leftEntryId = (String) _bindingStack.get(0);

          Map<String, Object> leftMap = result.get(leftEntryId);

          if (leftMap == null
              || (leftMap != null && leftMap.size() <= 0)) {
            continue;
          }
          Iterator<String> iter = leftMap.keySet().iterator();
          java.util.Map<String, Double> cacheMap = new java.util.HashMap<String, Double>();
          while (iter.hasNext()) {
            try {
              String nodekey = iter.next();
              Object nodevalue = result.get(leftEntryId).get(
                  nodekey);
              Object rightvalue = null;

              for (int i = 0; i < size - 1; i++) {
                String rightkey = (String) _bindingStack
                    .get(i + 1);

                if (rightkey.startsWith("sum:")) {
                  rightkey = rightkey.substring(rightkey
                      .indexOf("sum:") + "sum:".length());
                  double sumValue = 0;
                  if (cacheMap.get(rightkey) != null) {
                    sumValue = cacheMap.get(rightkey);

                  } else {
                    Iterator<Object> rValues = result
                        .get(rightkey).values()
                        .iterator();

                    while (rValues.hasNext()) {
                      Object rv = rValues.next();

                      if (rv != null) {
                        if (rv instanceof String)
                          sumValue += Double
                              .valueOf((String) rv);
                        else {
                          sumValue += (Double) rv;
                        }
                      }

                    }
                    cacheMap.put(rightkey, sumValue);
                  }

                  rightvalue = sumValue;

                } else {
                  // 简单实现只支持两位计算,同时是+或者-
                  if (rightkey
                      .indexOf(AnalysisConstants.OPERATE_PLUS_CHAR) > 0
                      || rightkey
                          .indexOf(AnalysisConstants.OPERATE_MINUS_CHAR) > 0) {

                    String l;
                    String r;

                    if (rightkey
                        .indexOf(AnalysisConstants.OPERATE_PLUS_CHAR) > 0) {
                      l = rightkey
                          .substring(
                              0,
                              rightkey.indexOf(AnalysisConstants.OPERATE_PLUS_CHAR))
                          .trim();

                      r = rightkey
                          .substring(
                              rightkey.indexOf(AnalysisConstants.OPERATE_PLUS_CHAR) + 1)
                          .trim();

                      if (result.get(l) == null
                          || result.get(r) == null
                          || (result.get(l) != null && result
                              .get(l)
                              .get(nodekey) == null)
                          || (result.get(r) != null && result
                              .get(r)
                              .get(nodekey) == null))
                        continue;

                      rightvalue = Double.valueOf(result
                          .get(l).get(nodekey)
                          .toString())
                          + Double.valueOf(result
                              .get(r)
                              .get(nodekey)
                              .toString());
                    } else {
                      l = rightkey
                          .substring(
                              0,
                              rightkey.indexOf(AnalysisConstants.OPERATE_MINUS_CHAR))
                          .trim();

                      r = rightkey
                          .substring(
                              rightkey.indexOf(AnalysisConstants.OPERATE_MINUS_CHAR) + 1)
                          .trim();

                      if (result.get(l) == null
                          || result.get(r) == null
                          || (result.get(l) != null && result
                              .get(l)
                              .get(nodekey) == null)
                          || (result.get(r) != null && result
                              .get(r)
                              .get(nodekey) == null))
                        continue;

                      rightvalue = Double.valueOf(result
                          .get(l).get(nodekey)
                          .toString())
                          - Double.valueOf(result
                              .get(r)
                              .get(nodekey)
                              .toString());
                    }

                                    }
                                    else {
                                        try {
                                            rightvalue = result.get(rightkey).get(nodekey);
                                        }
                                        catch (Throwable e) {
                                            if(!threshold.sholdBlock())
                                                logger.error("resultkey is null" + rightkey, e);
                                        }
                                    }
                }

                if (rightvalue != null) {
                  if (nodevalue != null) {
                    if (c.getOperatorStack().get(i) == AnalysisConstants.OPERATE_PLUS) {
                      if (nodevalue instanceof Double
                          || rightvalue instanceof Double)
                        nodevalue = Double
                            .valueOf(nodevalue
                                .toString())
                            + Double.valueOf(rightvalue
                                .toString());
                      else
                        nodevalue = (Long) nodevalue
                            + (Long) rightvalue;

                      continue;
                    }

                    if (c.getOperatorStack().get(i) == AnalysisConstants.OPERATE_MINUS) {
                      if (nodevalue instanceof Double
                          || rightvalue instanceof Double)
                        nodevalue = Double
                            .valueOf(nodevalue
                                .toString())
                            - Double.valueOf(rightvalue
                                .toString());
                      else
                        nodevalue = (Long) nodevalue
                            - (Long) rightvalue;

                      continue;
                    }

                    if (c.getOperatorStack().get(i) == AnalysisConstants.OPERATE_RIDE) {
                      if (nodevalue instanceof Double
                          || rightvalue instanceof Double)
                        nodevalue = Double
                            .valueOf(nodevalue
                                .toString())
                            * Double.valueOf(rightvalue
                                .toString());
                      else
                        nodevalue = (Long) nodevalue
                            * (Long) rightvalue;

                      continue;
                    }

                    if (c.getOperatorStack().get(i) == AnalysisConstants.OPERATE_DIVIDE) {
                      nodevalue = Double
                          .valueOf(nodevalue
                              .toString())
                          / Double.valueOf(rightvalue
                              .toString());
View Full Code Here

TOP

Related Classes of com.taobao.top.analysis.statistics.data.impl.SimpleCalculator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.