Esempio n. 1
0
  private void buildHourlyTaskInternal(Date period, Set<String> productLineSet) {
    MetricReportForABTestVisitor visitor = new MetricReportForABTestVisitor();

    for (String productLine : productLineSet) {
      MetricReport metricReport =
          m_reportService.queryMetricReport(
              productLine, period, new Date(period.getTime() + TimeUtil.ONE_HOUR));

      metricReport.accept(visitor);
    }

    Map<Integer, AbtestReport> result = visitor.getReportMap();

    for (AbtestReport report : result.values()) {
      if (report.getRunId() != -1) {
        com.dianping.cat.home.dal.abtest.AbtestReport _report =
            new com.dianping.cat.home.dal.abtest.AbtestReport();

        _report.setRunId(report.getRunId());
        _report.setPeriod(period);
        _report.setContent(report.toString());

        try {
          m_abtestReportDao.insert(_report);
        } catch (DalException e) {
          Cat.logError(e);
        }
      }
    }
  }
  private AbtestReport findOrCreateAbtestReport(int runId) {
    AbtestReport report = m_reportMap.get(runId);

    if (report == null) {
      report = new AbtestReport();

      report.setRunId(runId);
      report.setStartTime(m_startDate);
      report.setEndTime(m_endDate);
      m_reportMap.put(runId, report);
    }

    return report;
  }
  @Override
  public void visitPoint(Point point) {
    AbtestReport report = findOrCreateAbtestReport(m_runId);

    Variation variation = report.findOrCreateVariation(m_variation);

    Goal goal = variation.findOrCreateGoal(m_id);

    int count = goal.getCount() + point.getCount();
    double sum = goal.getSum() + point.getSum();

    goal.setType(m_type);
    goal.setCount(count);
    goal.setSum(sum);
    // avg?
  }
  public Map<Integer, AbtestReport> getReportMap() {
    for (AbtestReport report : m_reportMap.values()) {
      HashMap<String, String> map = m_metrics.get(report.getRunId());

      for (Entry<String, String> entry : map.entrySet()) {
        String metric = entry.getKey();
        String value = entry.getValue();

        for (Variation variation : report.getVariations().values()) {
          Goal goal = variation.findOrCreateGoal(metric);

          goal.setType(value);
        }

        Goal goal = new Goal();

        goal.setName(metric);
        report.getGoals().add(goal);
      }
    }

    return m_reportMap;
  }
Esempio n. 5
0
  @Test
  public void test() throws Exception {
    String xml =
        Files.forIO().readFrom(getClass().getResourceAsStream("metricReport.xml"), "utf-8");

    MetricReport metricReport = DefaultSaxParser.parse(xml);

    MetricReportForABTestVisitor visitor = new MetricReportForABTestVisitor();

    metricReport.accept(visitor);

    Map<Integer, AbtestReport> result = visitor.getReportMap();

    Calendar calendar = Calendar.getInstance();
    Date now = new Date();
    calendar.setTime(now);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.roll(Calendar.DAY_OF_MONTH, -14);

    for (AbtestReport ar : result.values()) {
      if (ar.getRunId() != -1) {
        System.out.println(ar.toString());
        for (int i = 0; i < 14; i++) {
          for (int j = 0; j < 24; j++) {
            Date begin = calendar.getTime();

            calendar.roll(Calendar.HOUR_OF_DAY, true);
            Date end = calendar.getTime();

            System.out.println("Import new report for " + begin);
            ar.setStartTime(begin);
            ar.setEndTime(end);

            com.dianping.cat.home.dal.abtest.AbtestReport report =
                new com.dianping.cat.home.dal.abtest.AbtestReport();
            report.setPeriod(begin);
            report.setRunId(ar.getRunId());
            report.setContent(ar.toString());

            m_abtestReportDao.insert(report);
          }
          calendar.roll(Calendar.DAY_OF_MONTH, true);
        }
      }
    }
  }