diff --git a/backend/src/main/java/io/metersphere/report/JtlResolver.java b/backend/src/main/java/io/metersphere/report/JtlResolver.java index d5e3a7a273..59a8b4784a 100644 --- a/backend/src/main/java/io/metersphere/report/JtlResolver.java +++ b/backend/src/main/java/io/metersphere/report/JtlResolver.java @@ -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 total = JtlResolver.resolver(jtlString); + + //// + List users = new ArrayList<>(); + List hits = new ArrayList<>(); + List erorrs = new ArrayList<>(); + List 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> collect = total.stream().collect(Collectors.groupingBy(Metric::getTimestamp)); + List>> entries = new ArrayList<>(collect.entrySet()); + Collections.sort(entries, new Comparator>>() { + @Override + public int compare(Map.Entry> t1, Map.Entry> 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> map = entries.get(i); + List 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; + } } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/report/base/ChartsData.java b/backend/src/main/java/io/metersphere/report/base/ChartsData.java new file mode 100644 index 0000000000..7254a1bc84 --- /dev/null +++ b/backend/src/main/java/io/metersphere/report/base/ChartsData.java @@ -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; + } +} diff --git a/frontend/src/business/components/performance/report/components/TestOverview.vue b/frontend/src/business/components/performance/report/components/TestOverview.vue index 54414663b8..312897926d 100644 --- a/frontend/src/business/components/performance/report/components/TestOverview.vue +++ b/frontend/src/business/components/performance/report/components/TestOverview.vue @@ -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',