测试概览Tab页
This commit is contained in:
parent
c01018f5e8
commit
7345976adb
|
@ -10,6 +10,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -282,4 +284,69 @@ public class JtlResolver {
|
|||
return testOverview;
|
||||
}
|
||||
|
||||
|
||||
public static ChartsData getLoadChartData(String jtlString) {
|
||||
ChartsData data = new ChartsData();
|
||||
List<Metric> total = JtlResolver.resolver(jtlString);
|
||||
|
||||
////
|
||||
List<String> users = new ArrayList<>();
|
||||
List<String> hits = new ArrayList<>();
|
||||
List<String> erorrs = new ArrayList<>();
|
||||
List<String> timeList = new ArrayList<>();
|
||||
////
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
|
||||
total.sort(Comparator.comparing(metric -> Long.valueOf(metric.getTimestamp())));
|
||||
total.forEach(metric -> {
|
||||
metric.setTimestamp(stampToDate(metric.getTimestamp()));
|
||||
});
|
||||
|
||||
Map<String, List<Metric>> collect = total.stream().collect(Collectors.groupingBy(Metric::getTimestamp));
|
||||
List<Map.Entry<String, List<Metric>>> entries = new ArrayList<>(collect.entrySet());
|
||||
Collections.sort(entries, new Comparator<Map.Entry<String, List<Metric>>>() {
|
||||
@Override
|
||||
public int compare(Map.Entry<String, List<Metric>> t1, Map.Entry<String, List<Metric>> t2) {
|
||||
Date date1 = null,date2 = null;
|
||||
try {
|
||||
date1 = sdf.parse(t1.getKey());
|
||||
date2 = sdf.parse(t2.getKey());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return (int) (date1.getTime() - date2.getTime());
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
int failSize = 0;
|
||||
Map.Entry<String, List<Metric>> map = entries.get(i);
|
||||
List<Metric> metrics = map.getValue();
|
||||
for (int j = 0; j < metrics.size(); j++) {
|
||||
Metric metric = metrics.get(j);
|
||||
String success = metric.getSuccess();
|
||||
if (!"true".equals(success)){
|
||||
failSize++;
|
||||
}
|
||||
}
|
||||
timeList.add(map.getKey());
|
||||
hits.add(String.valueOf(metrics.size()));
|
||||
users.add(String.valueOf(metrics.size()));
|
||||
erorrs.add(String.valueOf(failSize));
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private static String stampToDate(String s){
|
||||
String res;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
long lt = Long.parseLong(s);
|
||||
Date date = new Date(lt);
|
||||
res = simpleDateFormat.format(date);
|
||||
return res;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package io.metersphere.report.base;
|
||||
|
||||
public class ChartsData {
|
||||
|
||||
private String xAxis;
|
||||
private String yAxis;
|
||||
private String yAxis1;
|
||||
private String serices;
|
||||
|
||||
public String getxAxis() {
|
||||
return xAxis;
|
||||
}
|
||||
|
||||
public void setxAxis(String xAxis) {
|
||||
this.xAxis = xAxis;
|
||||
}
|
||||
|
||||
public String getyAxis() {
|
||||
return yAxis;
|
||||
}
|
||||
|
||||
public void setyAxis(String yAxis) {
|
||||
this.yAxis = yAxis;
|
||||
}
|
||||
|
||||
public String getyAxis1() {
|
||||
return yAxis1;
|
||||
}
|
||||
|
||||
public void setyAxis1(String yAxis1) {
|
||||
this.yAxis1 = yAxis1;
|
||||
}
|
||||
|
||||
public String getSerices() {
|
||||
return serices;
|
||||
}
|
||||
|
||||
public void setSerices(String serices) {
|
||||
this.serices = serices;
|
||||
}
|
||||
}
|
|
@ -86,11 +86,16 @@
|
|||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: ['12:40', '12:50', '13:00', '13:10', '13:20', '13:30', '13:40']
|
||||
data: ["10:22:01", "10:22:02", "10:22:04", "10:22:06",
|
||||
"10:22:07", "10:22:08", "10:22:09", "10:22:10", "10:22:11", "10:22:12"]
|
||||
},
|
||||
yAxis: [{
|
||||
name: 'User',
|
||||
type: 'value',
|
||||
min: 0,
|
||||
max: 30,
|
||||
splitNumber: 5,
|
||||
interval: 30 / 5
|
||||
},
|
||||
{
|
||||
name: 'Hits/s',
|
||||
|
@ -101,20 +106,23 @@
|
|||
{
|
||||
name: 'Users',
|
||||
color: '#0CA74A',
|
||||
data: [20, 40, 40, 40, 40, 40, 40],
|
||||
data: [6,9,10,15,1,10,25,19,15,2],
|
||||
type: 'line',
|
||||
yAxisIndex: 0
|
||||
},
|
||||
{
|
||||
name: 'Hits/s',
|
||||
color: '#65A2FF',
|
||||
data: [15, 38, 35, 39, 36, 37, 5],
|
||||
data: [1,1,1,1,1,1,1,1,1,1],
|
||||
type: 'line',
|
||||
yAxisIndex: 1
|
||||
},
|
||||
{
|
||||
name: 'Error(s)',
|
||||
color: '#E6113C',
|
||||
data: [0, 0, 0, 0, 0, 0, 0],
|
||||
data: [0,0,0,0,1,1,2,0,5,2],
|
||||
type: 'line',
|
||||
yAxisIndex: 1
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -125,7 +133,8 @@
|
|||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: ['12:40', '12:50', '13:00', '13:10', '13:20', '13:30', '13:40']
|
||||
data: ["2020-03-25 10:22:01", "2020-03-25 10:22:02", "2020-03-25 10:22:04", "2020-03-25 10:22:06",
|
||||
"2020-03-25 10:22:07", "2020-03-25 10:22:08", "2020-03-25 10:22:09", "2020-03-25 10:22:10", "2020-03-25 10:22:11", "2020-03-25 10:22:12"]
|
||||
},
|
||||
yAxis: [{
|
||||
name: 'User',
|
||||
|
|
Loading…
Reference in New Issue