@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); } } } }
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); } } } }