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); } } } }
@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); } } } }
@Test @Ignore public void testSelect() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, 15); Date begin = calendar.getTime(); System.out.println(begin); calendar.set(Calendar.DAY_OF_MONTH, 20); Date end = calendar.getTime(); System.out.println(end); List<com.dianping.cat.home.dal.abtest.AbtestReport> reports = m_abtestReportDao.findByRunIdDuration(152, null, end, AbtestReportEntity.READSET_FULL); System.out.println(reports.size()); }
private Date getLatestPeriod(Date now, int runId) { com.dianping.cat.home.dal.abtest.AbtestReport latestReport = null; Date period = null; try { latestReport = m_abtestReportDao.findLatestReportByRunId(runId, AbtestReportEntity.READSET_FULL); } catch (Exception e) { // ignore it } if (latestReport == null) { m_calendar.setTime(now); m_calendar.add(Calendar.DAY_OF_MONTH, -14); period = m_calendar.getTime(); } else { period = latestReport.getPeriod(); } return period; }