优化图形分析根据可选时间补0逻辑、优化流量图形单位可选功能。
This commit is contained in:
+37
-3
@@ -52,7 +52,7 @@ public class EchartsDataUtils {
|
||||
return Math.round(microseconds / 1_000_000.0 * 100.0) / 100.0;
|
||||
}
|
||||
/**
|
||||
* 构建ECharts图表数据(带时间补全和0值填充)
|
||||
* 构建ECharts图表数据(带时间补全和特殊值处理)
|
||||
* @param list 原始数据列表
|
||||
* @param timeExtractor 时间字段提取函数
|
||||
* @param dataExtractors 数据提取器Map
|
||||
@@ -112,6 +112,9 @@ public class EchartsDataUtils {
|
||||
dataExtractors.keySet().forEach(name ->
|
||||
yData.put(name, new ArrayList<Object>()));
|
||||
|
||||
// 特殊处理:查找percentile95的固定值
|
||||
Object fixedPercentile95Value = findFixedValueForPercentile95(sortedList, dataExtractors);
|
||||
|
||||
for (Date time : fullTimeSeries) {
|
||||
// X轴数据
|
||||
xAxisData.add(parseDateToStr(time));
|
||||
@@ -126,11 +129,13 @@ public class EchartsDataUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> seriesData = (List<Object>) yData.get(name);
|
||||
|
||||
if (item != null) {
|
||||
Object value = extractor.apply(item);
|
||||
seriesData.add(value != null ? value : 0);
|
||||
seriesData.add(value != null ? value : getDefaultValue(name, fixedPercentile95Value));
|
||||
} else {
|
||||
seriesData.add(0); // 补0
|
||||
// 数据补全
|
||||
seriesData.add(getDefaultValue(name, fixedPercentile95Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,6 +152,35 @@ public class EchartsDataUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找percentile95的固定值(第一个非零值)
|
||||
*/
|
||||
private static <T> Object findFixedValueForPercentile95(List<T> list, Map<String, Function<T, ?>> dataExtractors) {
|
||||
if (!dataExtractors.containsKey("percentile95")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Function<T, ?> extractor = dataExtractors.get("percentile95");
|
||||
for (T item : list) {
|
||||
Object value = extractor.apply(item);
|
||||
if (value != null && !value.equals(0)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指标名称获取默认值
|
||||
*/
|
||||
private static Object getDefaultValue(String metricName, Object fixedPercentile95Value) {
|
||||
if ("percentile95".equals(metricName) && !fixedPercentile95Value.equals(0)) {
|
||||
return fixedPercentile95Value; // percentile95使用固定值
|
||||
} else {
|
||||
return 0; // 其他指标补0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转日期
|
||||
*/
|
||||
|
||||
+5
-1
@@ -38,6 +38,10 @@ public class SpeedUtils {
|
||||
public BigDecimal getLastOutSpeedGb() { return lastOutSpeedGb; }
|
||||
public String getRecommendedUnit() { return recommendedUnit; }
|
||||
|
||||
public void setRecommendedUnit(String recommendedUnit) {
|
||||
this.recommendedUnit = recommendedUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
@@ -65,7 +69,7 @@ public class SpeedUtils {
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
"bit"
|
||||
"Kb"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user