fix(性能测试): 修复BigDecimal float value 产生的精度问题

This commit is contained in:
CaptainB 2023-07-18 10:39:39 +08:00
parent b4bf0c6e63
commit 3023a31d3a
2 changed files with 4 additions and 17 deletions

View File

@ -7,6 +7,7 @@ import io.metersphere.commons.constants.FileType;
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.constants.ResourceStatusEnum;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.DateUtils;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.i18n.Translator;
@ -150,19 +151,11 @@ public class EngineFactory {
if (resourceIndex + 1 == tgRatios.size()) {
double beforeLast = 0; // 前几个线程数
for (int k = 0; k < tgRatios.size() - 1; k++) {
if (tgRatios.get(k) instanceof BigDecimal) {
beforeLast += Math.round(threadNum2 * ((BigDecimal) tgRatios.get(k)).floatValue());
} else {
beforeLast += Math.round(threadNum2 * (double) tgRatios.get(k));
}
beforeLast += Math.round(threadNum2 * Double.parseDouble(tgRatios.get(k).toString()));
}
value = Math.round(threadNum2 - beforeLast);
} else {
if (tgRatios.get(resourceIndex) instanceof BigDecimal) {
value = Math.round(threadNum2 * ((BigDecimal) tgRatios.get(resourceIndex)).floatValue());
} else {
value = Math.round(threadNum2 * (double) tgRatios.get(resourceIndex));
}
value = Math.round(threadNum2 * Double.parseDouble(tgRatios.get(resourceIndex).toString()));
}
}
break;

View File

@ -127,13 +127,7 @@ public class MetricQueryService {
List jsonArray = (List) resultObject.get("values");
jsonArray.forEach(value -> {
List ja = JSON.parseArray(value.toString());
double timestamp;
if (ja.get(0) instanceof BigDecimal) {
timestamp = ((BigDecimal) ja.get(0)).floatValue();
} else {
timestamp = (double) ja.get(0);
}
timestamps.add(DateUtils.getTimeString((long) (timestamp * 1000)));
timestamps.add(DateUtils.getTimeString((long) (Double.parseDouble(ja.get(0).toString()) * 1000)));
values.add(Double.valueOf(ja.get(1).toString()));
});