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;
  }
Exemplo n.º 2
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);
        }
      }
    }
  }