提交 a268c898 编写于 作者: J jialinsun

app linechart 重构

上级 0946b4f0
......@@ -26,11 +26,11 @@ public class AppDataService {
@Inject
private AppConfigManager m_appConfigManager;
public static final String SUCCESS_RATIO = "成功率";
public static final String SUCCESS= "success";
public static final String REQUEST_COUNT = "请求数";
public static final String REQUEST = "request";
public static final String DELAY_AVG = "成功延时(ms)";
public static final String DELAY = "delay";
public void insert(AppDataCommand proto) throws DalException {
m_dao.insertData(proto);
......@@ -49,40 +49,40 @@ public class AppDataService {
List<AppDataCommand> datas;
try {
if (SUCCESS_RATIO.equals(type)) {
if (SUCCESS.equals(type)) {
datas = m_dao.findDataByMinuteCode(commandId, period, city, operator, network, appVersion, connnectType,
code, platform, AppDataCommandEntity.READSET_COUNT_DATA);
code, platform, AppDataCommandEntity.READSET_SUCCESS_DATA);
Pair<Integer, Map<Integer, List<AppDataCommand>>> dataPair = convert2AppDataCommandMap(datas);
return querySuccessRatio(dataPair);
} else {
return querySuccessRatio(commandId, dataPair);
} else if (REQUEST.equals(type)) {
datas = m_dao.findDataByMinute(commandId, period, city, operator, network, appVersion, connnectType, code,
platform, AppDataCommandEntity.READSET_COUNT_DATA);
Pair<Integer, Map<Integer, List<AppDataCommand>>> dataPair = convert2AppDataCommandMap(datas);
return queryRequestCount(dataPair);
} else if (DELAY.equals(type)) {
datas = m_dao.findDataByMinute(commandId, period, city, operator, network, appVersion, connnectType, code,
platform, AppDataCommandEntity.READSET_AVG_DATA);
if (REQUEST_COUNT.equals(type)) {
return queryRequestCount(dataPair);
} else if (DELAY_AVG.equals(type)) {
return queryDelayAvg(dataPair);
}
Pair<Integer, Map<Integer, List<AppDataCommand>>> dataPair = convert2AppDataCommandMap(datas);
return queryDelayAvg(dataPair);
}
} catch (Exception e) {
Cat.logError(e);
e.printStackTrace();
}
return null;
}
private Pair<Integer, Map<Integer, List<AppDataCommand>>> convert2AppDataCommandMap(List<AppDataCommand> fromDatas) {
Map<Integer, List<AppDataCommand>> dataMap = new LinkedHashMap<Integer, List<AppDataCommand>>();
int min = -1;
int max = -1;
for (AppDataCommand from : fromDatas) {
int minute = from.getMinuteOrder();
if (min < 0 || min > minute) {
min = minute;
}
if (max < 0 || max < minute) {
max = minute;
}
......@@ -95,11 +95,13 @@ public class AppDataService {
}
data.add(from);
}
int n = (max - min) / 5;
int n = max / 5;
return new Pair<Integer, Map<Integer, List<AppDataCommand>>>(n, dataMap);
}
public double[] querySuccessRatio(Pair<Integer, Map<Integer, List<AppDataCommand>>> dataPair) {
public double[] querySuccessRatio(int commandId, Pair<Integer, Map<Integer, List<AppDataCommand>>> dataPair) {
double[] value = new double[dataPair.getKey()];
Map<Integer, List<AppDataCommand>> dataMap = dataPair.getValue();
......@@ -112,12 +114,12 @@ public class AppDataService {
for (AppDataCommand data : entry.getValue()) {
long number = data.getAccessNumberSum();
if (isSuccessStatus(data)) {
if (isSuccessStatus(commandId, data.getCode())) {
success += number;
}
sum += number;
}
value[key / 5] = (double) success / sum;
value[key / 5 - 1] = (double) success / sum;
}
} catch (Exception e) {
Cat.logError(e);
......@@ -126,9 +128,8 @@ public class AppDataService {
return value;
}
private boolean isSuccessStatus(AppDataCommand data) {
int code = data.getCode();
Collection<Code> codes = m_appConfigManager.queryCodeByCommand(data.getCommandId());
private boolean isSuccessStatus(int commandId, int code) {
Collection<Code> codes = m_appConfigManager.queryCodeByCommand(commandId);
for (Code c : codes) {
if (c.getId() == code) {
......@@ -145,7 +146,7 @@ public class AppDataService {
for (AppDataCommand data : entry.getValue()) {
long count = data.getAccessNumberSum();
value[data.getMinuteOrder() / 5] = count;
value[data.getMinuteOrder() / 5 - 1] = count;
}
}
return value;
......@@ -160,7 +161,7 @@ public class AppDataService {
long sum = data.getResponseSumTimeSum();
double avg = sum / count;
value[data.getMinuteOrder() / 5] = avg;
value[data.getMinuteOrder() / 5 - 1] = avg;
}
}
return value;
......
......@@ -7,7 +7,7 @@
<member name="response-package" field="response_package" value-type="long" length="19" nullable="false" />
<member name="creation-date" field="creation_date" value-type="Date" nullable="false" />
<member name="access-number-sum" value-type="long" all="false" select-expr="sum(access_number)" length="19" nullable="false" />
<member name="response-sum-time-sum" value-type="long" all="false" select-expr="sum(response-sum-time)" length="19" nullable="false" />
<member name="response-sum-time-sum" value-type="long" all="false" select-expr="sum(response_sum_time)" length="19" nullable="false" />
<var name="key-id" value-type="int" key-member="id" />
<var name="command-id" value-type="int" />
<readsets>
......
......@@ -20,7 +20,7 @@ public class Payload extends AbstractReportPayload<Action> {
private String m_query2;
@FieldMeta("type")
private String m_type = "successRatio";
private String m_type = "request";
public Payload() {
super(ReportPage.APP);
......
......@@ -4,7 +4,6 @@ import java.util.Date;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Random;
import org.unidal.lookup.annotation.Inject;
......@@ -21,27 +20,43 @@ public class AppGraphCreator extends AbstractGraphCreator {
public LineChart buildLineChart(QueryEntity queryEntity1, QueryEntity queryEntity2, String type) {
LinkedList<double[]> dataList = new LinkedList<double[]>();
double[] data1 = prepareAllData(queryEntity1, type);
dataList.add(data1);
if (queryEntity1 != null) {
double[] data1 = prepareQueryData(queryEntity1, type);
dataList.add(data1);
}
if (queryEntity2 != null) {
double[] values2 = prepareAllData(queryEntity2, type);
double[] values2 = prepareQueryData(queryEntity2, type);
dataList.add(values2);
}
return buildChartData(dataList, type);
}
private double[] prepareAllData(QueryEntity queryEntity, String type) {
private double[] prepareQueryData(QueryEntity queryEntity, String type) {
double[] value = m_appDataService.queryValue(queryEntity, type);
return value;
}
private String queryType(String type) {
if (AppDataService.SUCCESS.equals(type)) {
return "成功率";
} else if (AppDataService.REQUEST.equals(type)) {
return "请求数";
} else if (AppDataService.DELAY.equals(type)) {
return "成功延时(ms)";
} else {
return "";
}
}
public LineChart buildChartData(final LinkedList<double[]> dataList, String type) {
LineChart lineChart = new LineChart();
lineChart.setId("app");
lineChart.setHtmlTitle(type);
lineChart.setHtmlTitle(queryType(type));
int i = 1;
for (double[] data : dataList) {
......@@ -64,46 +79,4 @@ public class AppGraphCreator extends AbstractGraphCreator {
return map;
}
public class AppDataServiceMock extends AppDataService {
public double[] queryValue(QueryEntity entity, String type) {
if (SUCCESS_RATIO.equals(type)) {
return querySuccessRatio(entity);
} else if (REQUEST_COUNT.equals(type)) {
return queryRequestCount(entity);
} else if (DELAY_AVG.equals(type)) {
return queryDelayAvg(entity);
} else {
return null;
}
}
private double[] makeMockValue(String type) {
long startTime = TimeUtil.getCurrentDay().getTime();
long current = System.currentTimeMillis();
long endTime = current - current % 300000;
int n = (int) (endTime - startTime) / 300000;
double[] value = new double[n];
for (int i = 0; i < n; i++) {
value[i] = (new Random().nextDouble() + 1) * 100;
}
return value;
}
private double[] querySuccessRatio(QueryEntity entity) {
return makeMockValue(SUCCESS_RATIO);
}
private double[] queryDelayAvg(QueryEntity entity) {
return makeMockValue(DELAY_AVG);
}
private double[] queryRequestCount(QueryEntity entity) {
return makeMockValue(REQUEST_COUNT);
}
}
}
......@@ -9,12 +9,9 @@
<a:body>
<res:useCss value="${res.css.local['select2.css']}" target="head-css" />
<res:useCss
value="${res.css.local['bootstrap-datetimepicker.min.css']}"
target="head-css" />
<res:useCss value="${res.css.local['bootstrap-datetimepicker.min.css']}" target="head-css" />
<res:useJs value="${res.js.local['select2.min.js']}" target="head-js" />
<res:useJs value="${res.js.local['bootstrap-datetimepicker.min.js']}"
target="head-js" />
<res:useJs value="${res.js.local['bootstrap-datetimepicker.min.js']}" target="head-js" />
<res:useJs value="${res.js.local['baseGraph.js']}" target="head-js" />
<script type="text/javascript">
var commandInfo = ${model.command};
......@@ -55,8 +52,10 @@
function getDate() {
var myDate = new Date();
var myMonth = new Number(myDate.getMonth());
var month = myMonth + 1;
return myDate.getFullYear() + "-" + myDate.getMonth() + "-"
return myDate.getFullYear() + "-" + month + "-"
+ myDate.getDate();
}
......@@ -72,8 +71,8 @@
var operator = $("#operator").val();
var split = ";";
var query1 = time + split + command + split + code + split
+ network + split + version + split + connectionType + split
+ palteform + split + city + split + operator;
+ network + split + version + split + connectionType
+ split + palteform + split + city + split + operator;
var query2 = "";
var value = document.getElementById("checkbox").checked;
......@@ -92,89 +91,93 @@
+ split + palteform2 + split + city2 + split
+ operator2;
}
var checkboxs = document.getElementsByName("typeCheckbox");
var type = "";
for(var i=0; i<checkboxs.length;i++){
if(checkboxs[i].checked){
for (var i = 0; i < checkboxs.length; i++) {
if (checkboxs[i].checked) {
type = checkboxs[i].value;
break;
}
}
var href = "?query1=" + query1 + "&query2=" + query2 + "&type=" + type;
var href = "?query1=" + query1 + "&query2=" + query2 + "&type="
+ type;
window.location.href = href;
}
$(document).ready(function() {
$('#datetimepicker1').datetimepicker();
$('#datetimepicker2').datetimepicker();
$(document).ready(
function() {
$('#datetimepicker1').datetimepicker();
$('#datetimepicker2').datetimepicker();
var query1 = '${payload.query1}';
var query2 = '${payload.query2}';
var command1 = $('#command');
var command2 = $('#command2');
var words = query1.split(";");
var query1 = '${payload.query1}';
var query2 = '${payload.query2}';
var command1 = $('#command');
var command2 = $('#command2');
var words = query1.split(";");
command1.on('change', command1Change);
command2.on('change', command2Change);
command1.on('change', command1Change);
command2.on('change', command2Change);
$("#command").val(words[1]);
$("#command").val(words[1]);
if (words[0] == null || words[0].length == 0) {
$("#time").val(getDate());
} else {
$("#time").val(words[0]);
}
if (words[0] == null || words.length == 1) {
console.log(words.length);
command1Change();
$("#code").val(words[2]);
$("#network").val(words[3]);
$("#version").val(words[4]);
$("#connectionType").val(words[5]);
$("#platform").val(words[6]);
$("#city").val(words[7]);
$("#operator").val(words[8]);
$("#time").val(getDate());
} else {
$("#time").val(words[0]);
}
if (query2 != null && query2 != '') {
$('#history').slideDown();
document.getElementById("checkbox").checked = true;
var words = query2.split(";");
command1Change();
$("#code").val(words[2]);
$("#network").val(words[3]);
$("#version").val(words[4]);
$("#connectionType").val(words[5]);
$("#platform").val(words[6]);
$("#city").val(words[7]);
$("#operator").val(words[8]);
if (words[0] == null || words[0].length == 0) {
$("#time2").val(getDate());
} else {
$("#time2").val(words[0]);
}
if (query2 != null && query2 != '') {
$('#history').slideDown();
document.getElementById("checkbox").checked = true;
var words = query2.split(";");
$("#command2").val(words[1]);
command2Change();
$("#code2").val(words[2]);
$("#network2").val(words[3]);
$("#version2").val(words[4]);
$("#connectionType2").val(words[5]);
$("#platform2").val(words[6]);
$("#city2").val(words[7]);
$("#operator2").val(words[8]);
} else {
$("#time2").val(getDate());
}
var checkboxs = document.getElementsByName("typeCheckbox");
for(var i=0; i<checkboxs.length;i++){
if(checkboxs[i].value == "${payload.type}"){
checkboxs[i].checked = true;
break;
}
}
var data = ${model.lineChart.jsonString};
graphMetricChartForApp(document.getElementById('${model.lineChart.id}'), data);
});
if (words[0] == null || words[0].length == 0) {
$("#time2").val(getDate());
} else {
$("#time2").val(words[0]);
}
$("#command2").val(words[1]);
command2Change();
$("#code2").val(words[2]);
$("#network2").val(words[3]);
$("#version2").val(words[4]);
$("#connectionType2").val(words[5]);
$("#platform2").val(words[6]);
$("#city2").val(words[7]);
$("#operator2").val(words[8]);
} else {
$("#time2").val(getDate());
}
var checkboxs = document.getElementsByName("typeCheckbox");
for (var i = 0; i < checkboxs.length; i++) {
if (checkboxs[i].value == "${payload.type}") {
checkboxs[i].checked = true;
break;
}
}
var data = ${model.lineChart.jsonString};
graphMetricChartForApp(document
.getElementById('${model.lineChart.id}'), data);
});
</script>
<div class="report">
<table>
......@@ -191,9 +194,10 @@
<c:forEach var="item" items="${model.commands}" varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 返回码 <select id="code" style="width: 120px;"><option value='0' >All</option>
</select> 返回码 <select id="code" style="width: 120px;"><option
value='0'>All</option>
</select> 网络类型 <select id="network" style="width: 80px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.networks}" varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
......@@ -202,28 +206,29 @@
</tr>
<tr>
<th align=left>版本 <select id="version" style="width: 100px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.versions}" varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 连接类型 <select id="connectionType" style="width: 100px;">
<option value='0' >All</option>
<c:forEach var="item" items="${model.connectionTypes}" varStatus="status">
<option value='0'>All</option>
<c:forEach var="item" items="${model.connectionTypes}"
varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 平台 <select id="platform" style="width: 100px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.platforms}"
varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 地区 <select id="city" style="width: 100px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.cities}" varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 运营商 <select id="operator" style="width: 100px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.operators}"
varStatus="status">
<option value='${item.id}'>${item.name}</option>
......@@ -251,9 +256,9 @@
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 返回码 <select id="code2" style="width: 120px;">
<option value='0' >All</option>
<option value='0'>All</option>
</select> 网络类型 <select id="network2" style="width: 80px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.networks}" varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
......@@ -262,28 +267,29 @@
</tr>
<tr>
<th align=left>版本 <select id="version2" style="width: 100px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.versions}" varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 连接类型 <select id="connectionType2" style="width: 100px;">
<option value='0' >All</option>
<c:forEach var="item" items="${model.connectionTypes}" varStatus="status">
<option value='0'>All</option>
<c:forEach var="item" items="${model.connectionTypes}"
varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 平台 <select id="platform2" style="width: 100px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.platforms}"
varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 地区 <select id="city2" style="width: 100px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.cities}" varStatus="status">
<option value='${item.id}'>${item.name}</option>
</c:forEach>
</select> 运营商 <select id="operator2" style="width: 100px;">
<option value='0' >All</option>
<option value='0'>All</option>
<c:forEach var="item" items="${model.operators}"
varStatus="status">
<option value='${item.id}'>${item.name}</option>
......@@ -294,16 +300,16 @@
</table>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-info"> <input type="radio"
name="typeCheckbox" value="成功率" >成功率
</label> <label class="btn btn-info"> <input type="radio"
name="typeCheckbox" value="请求数" >请求数
<label class="btn btn-info"><input type="radio"
name="typeCheckbox" value="request">请求数
</label> <label class="btn btn-info"> <input type="radio"
name="typeCheckbox" value="成功延时(ms)" >成功延时(ms)
name="typeCheckbox" value="success">成功率
</label> <label class="btn btn-info"> <input type="radio"
name="typeCheckbox" value="delay">成功延时(ms)
</label>
</div>
<div style="float:left;width:95%;">
<div style="float: left; width: 95%;">
<div id="${model.lineChart.id}"></div>
</div>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册