提交 5b4b46b2 编写于 作者: Y youyong205

modify the baseline creator

上级 33098d38
......@@ -13,10 +13,10 @@ public class MapUtils {
Map<K, V> result = new LinkedHashMap<K, V>();
List<Entry<K, V>> entries = new ArrayList<Entry<K, V>>(map.entrySet());
Collections.sort(entries, compator);
for (Entry<K, V> entry : entries) {
result.put(entry.getKey(), entry.getValue());
}
return result;
}
}
......@@ -41,10 +41,10 @@ public enum ReportPage implements Page {
STATISTICS("statistics", "statistics", "Statistics", "Statistics", true),
MONITOR("monitor", "monitor", "Monitor", "Monitor", true),
ALTERATION("alteration", "alteration", "Change", "Alteration", true),
MONITOR("monitor", "monitor", "Monitor", "Monitor", true);
ALTERATION("alteration", "alteration", "Alteration", "Alteration", true);
private String m_name;
private String m_path;
......
package com.dianping.cat.report.baseline.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.dianping.cat.report.baseline.BaselineCreator;
......@@ -17,7 +19,7 @@ public class DefaultBaselineCreator implements BaselineCreator {
for (int j = 0; j < weights.size(); j++) {
double[] values = valueList.get(j);
double weight = weights.get(j);
if (values[i] > 0) {
totalValue += values[i] * weight;
totalWeight += weight;
......@@ -33,7 +35,7 @@ public class DefaultBaselineCreator implements BaselineCreator {
result[i] = totalValue / totalWeight;
}
}
return denoise(result, 6);
return denoise(result, 10);
}
public double[] denoise(double[] data, int mixNumber) {
......@@ -50,22 +52,13 @@ public class DefaultBaselineCreator implements BaselineCreator {
last = true;
}
double min = Double.MAX_VALUE;
double max = 0;
double sum = 0;
List<Double> mixNumbers = new ArrayList<Double>();
for (int j = 0; j < mixNumber; j++) {
int position = i + j;
if (data[position] > max) {
max = data[position];
}
if (data[position] < min) {
min = data[position];
}
sum = sum + data[position];
mixNumbers.add(data[position]);
}
double avg = (sum - max - min) / (mixNumber - 2);
double avg = computeAvg(mixNumbers);
result[i + mixNumber / 2] = avg;
if (first) {
......@@ -81,7 +74,33 @@ public class DefaultBaselineCreator implements BaselineCreator {
}
}
}
return result;
}
public double computeAvg(List<Double> data) {
Collections.sort(data);
int length = data.size();
double value = 0;
int middle = length / 2;
if (length % 2 == 0) {
value = (data.get(middle - 1) + data.get(middle)) / 2;
} else {
value = data.get(middle);
}
int size = 0;
double sum = 0;
for (double d : data) {
if (d > value * 3 || d < value / 3) {
continue;
} else {
size++;
sum = sum + d;
}
}
return sum / size;
}
}
......@@ -55,8 +55,8 @@
</page>
<page name="statistics" title="Statistics" path="statistics" view="/jsp/report/bug/bug.jsp" template="default">
<description>Statistics</description>
</page>
<page name="alteration" title="Alteration" path="alteration" template="default">
</page>
<page name="alteration" title="Change" path="alteration" template="default">
<description>Alteration</description>
</page>
<page name="monitor" title="Monitor" path="monitor" template="default">
......
<%@ page contentType="text/html; charset=utf-8" %>
<jsp:useBean id="ctx" type="com.dianping.cat.report.page.alteration.Context" scope="request"/>
<jsp:useBean id="payload" type="com.dianping.cat.report.page.alteration.Payload" scope="request"/>
<jsp:useBean id="model" type="com.dianping.cat.report.page.alteration.Model" scope="request"/>
View of alteration page under report
\ No newline at end of file
package com.dianping.cat.report.task.metric;
import java.text.DecimalFormat;
import java.util.Date;
import junit.framework.Assert;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
......@@ -26,20 +27,29 @@ public class BaselineCreatorTest extends ComponentTestCase {
@Test
public void test() {
DefaultBaselineCreator creator = new DefaultBaselineCreator();
double[] data = new double[24 * 60];
double[] data = new double[60];
for (int i = 0; i < data.length; i++) {
data[i] = i;
if (i == 20 || i == 30 || i == 40) {
data[i] = 100;
}
if (i == 21 || i == 31 || i == 41) {
data[i] = 200;
}
if (i == 25 || i == 35 || i == 45) {
data[i] = 300;
}
if (i == 26 || i == 36 || i == 46) {
data[i] = 300;
}
}
double[] result = creator.denoise(data, 5);
DecimalFormat df = new DecimalFormat("#.#");
double[] result = creator.denoise(data, 10);
for (int i = 0; i < result.length; i++) {
System.out.print(df.format(result[i]) + " ");
if (i % 60 == 59) {
System.out.println();
}
Assert.assertEquals(result[i] < 60, true);
}
}
}
......@@ -393,12 +393,12 @@ CREATE TABLE `alteration` (
`hostname` varchar(128) NOT NULL COMMENT '变更机器名',
`ip` varchar(128) DEFAULT NULL COMMENT '变更机器IP',
`date` datetime NOT NULL COMMENT '变更时间',
`user` varchar(45) NOT NULL COMMENT '变更用户,
`alt_group` varchar(45) DEFAULT NULL COMMENT '变更组别,
`user` varchar(45) NOT NULL COMMENT '变更用户',
`alt_group` varchar(45) DEFAULT NULL COMMENT '变更组别',
`content` text NOT NULL COMMENT '变更内容',
`url` varchar(200) DEFAULT NULL COMMENT '变更链接',
`creation_date` datetime NOT NULL COMMENT '数据库创建时间',
PRIMARY KEY (`id`),
KEY `ind_date_domain_host` (`date`,`domain`,`hostname`)
) ENGINE=InnoDB AUTO_INCREMENT=1241 DEFAULT CHARSET=utf8 COMMENT='变更表;
) ENGINE=InnoDB AUTO_INCREMENT=1241 DEFAULT CHARSET=utf8 COMMENT='变更表';
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册