提交 a215653a 编写于 作者: Y yong.you

modify the cat metric graph builder

上级 092985fb
...@@ -43,7 +43,8 @@ public class DefaultBaselineService implements BaselineService { ...@@ -43,7 +43,8 @@ public class DefaultBaselineService implements BaselineService {
if (baseline == null) { if (baseline == null) {
try { try {
baseline = m_baselineDao.findByReportNameKeyTime(reportPeriod, reportName, key, BaselineEntity.READSET_FULL); baseline = m_baselineDao
.findByReportNameKeyTime(reportPeriod, reportName, key, BaselineEntity.READSET_FULL);
m_baselineMap.put(baselineKey, baseline); m_baselineMap.put(baselineKey, baseline);
} catch (DalNotFoundException e) { } catch (DalNotFoundException e) {
Cat.logEvent("BaselineNotFound", baselineKey); Cat.logEvent("BaselineNotFound", baselineKey);
...@@ -67,14 +68,13 @@ public class DefaultBaselineService implements BaselineService { ...@@ -67,14 +68,13 @@ public class DefaultBaselineService implements BaselineService {
double[] result = new double[60]; double[] result = new double[60];
Date today = TaskHelper.todayZero(reportPeriod); Date today = TaskHelper.todayZero(reportPeriod);
int hour = (int) ((reportPeriod.getTime() - today.getTime()) / TimeUtil.ONE_HOUR); int hour = (int) ((reportPeriod.getTime() - today.getTime()) / TimeUtil.ONE_HOUR);
double[] dayResult = queryDailyBaseline(reportName, key, today); double[] dayResult = queryDailyBaseline(reportName, key, today);
if (dayResult == null)
return null;
for (int i = 0; i < 60; i++) {
result[i] = dayResult[hour * 60 + i];
}
if (dayResult != null) {
for (int i = 0; i < 60; i++) {
result[i] = dayResult[hour * 60 + i];
}
}
return result; return result;
} }
......
...@@ -25,7 +25,7 @@ public class CachedMetricReportServiceImpl implements CachedMetricReportService ...@@ -25,7 +25,7 @@ public class CachedMetricReportServiceImpl implements CachedMetricReportService
@Inject @Inject
private ModelService<MetricReport> m_service; private ModelService<MetricReport> m_service;
private final Map<String, MetricReport> m_metricReportMap = new LinkedHashMap<String, MetricReport>() { private final Map<String, MetricReport> m_metricReports = new LinkedHashMap<String, MetricReport>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -37,13 +37,13 @@ public class CachedMetricReportServiceImpl implements CachedMetricReportService ...@@ -37,13 +37,13 @@ public class CachedMetricReportServiceImpl implements CachedMetricReportService
private MetricReport getReportFromDB(String product, long date) { private MetricReport getReportFromDB(String product, long date) {
String key = product + date; String key = product + date;
MetricReport result = m_metricReportMap.get(key); MetricReport result = m_metricReports.get(key);
if (result == null) { if (result == null) {
Date start = new Date(date); Date start = new Date(date);
Date end = new Date(date + TimeUtil.ONE_HOUR); Date end = new Date(date + TimeUtil.ONE_HOUR);
try { try {
result = m_reportService.queryMetricReport(product, start, end); result = m_reportService.queryMetricReport(product, start, end);
m_metricReportMap.put(key, result); m_metricReports.put(key, result);
} catch (Exception e) { } catch (Exception e) {
Cat.logError(e); Cat.logError(e);
} }
...@@ -61,6 +61,7 @@ public class CachedMetricReportServiceImpl implements CachedMetricReportService ...@@ -61,6 +61,7 @@ public class CachedMetricReportServiceImpl implements CachedMetricReportService
if (m_service.isEligable(request)) { if (m_service.isEligable(request)) {
ModelResponse<MetricReport> response = m_service.invoke(request); ModelResponse<MetricReport> response = m_service.invoke(request);
MetricReport report = response.getModel(); MetricReport report = response.getModel();
return report; return report;
} else { } else {
throw new RuntimeException("Internal error: no eligable metric service registered for " + request + "!"); throw new RuntimeException("Internal error: no eligable metric service registered for " + request + "!");
......
...@@ -51,12 +51,13 @@ public class MetricDataFetcherImpl implements MetricDataFetcher { ...@@ -51,12 +51,13 @@ public class MetricDataFetcherImpl implements MetricDataFetcher {
return values; return values;
} }
private void putKey(Map<String, double[]> datas, Map<String, double[]> values, String sumKey) { private void putKey(Map<String, double[]> datas, Map<String, double[]> values, String key) {
double[] value = datas.get(sumKey); double[] value = datas.get(key);
if(value ==null){ if(value ==null){
value = new double[60]; value = new double[60];
} }
values.put(sumKey, value); values.put(key, value);
} }
public class MetricDataBuilder extends BaseVisitor { public class MetricDataBuilder extends BaseVisitor {
......
...@@ -10,7 +10,6 @@ public class MetricReportMerger extends DefaultMerger { ...@@ -10,7 +10,6 @@ public class MetricReportMerger extends DefaultMerger {
public MetricReportMerger(MetricReport metricReport) { public MetricReportMerger(MetricReport metricReport) {
super(metricReport); super(metricReport);
} }
@Override @Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册