增加 平均值的批量处理方法

This commit is contained in:
2023-07-17 10:45:52 +08:00
parent 45a4bd0983
commit 2b36c07bc0
2 changed files with 31 additions and 11 deletions

View File

@@ -86,6 +86,7 @@ public interface InfluxDbSqlConstant {
String MAX = "MAX"; String MAX = "MAX";
String MIN = "MIN"; String MIN = "MIN";
String AVG = "MEAN"; String AVG = "MEAN";
String CP95 = "CP95";
String MEDIAN = "MEDIAN"; String MEDIAN = "MEDIAN";
String MODE = "MODE"; String MODE = "MODE";
String SPREAD = "SPREAD"; String SPREAD = "SPREAD";

View File

@@ -132,6 +132,7 @@ public class InfluxQueryWrapper {
} }
return this; return this;
} }
public <T, R> InfluxQueryWrapper select(String columnName, String resultColumnName) { public <T, R> InfluxQueryWrapper select(String columnName, String resultColumnName) {
StringBuilder selectFragment = new StringBuilder(); StringBuilder selectFragment = new StringBuilder();
@@ -172,7 +173,6 @@ public class InfluxQueryWrapper {
// } // }
/************常见的简单函数处理比如max/min/mean/percentile****************/ /************常见的简单函数处理比如max/min/mean/percentile****************/
/*** /***
@@ -267,7 +267,7 @@ public class InfluxQueryWrapper {
return this; return this;
} }
public <T, R> InfluxQueryWrapper mean(String columnName) { public InfluxQueryWrapper mean(String columnName) {
String selectFragment = InfluxDbSqlConstant.AVG + String selectFragment = InfluxDbSqlConstant.AVG +
InfluxDbSqlConstant.LBK + InfluxDbSqlConstant.LBK +
InfluxDbSqlConstant.DQM + InfluxDbSqlConstant.DQM +
@@ -281,6 +281,25 @@ public class InfluxQueryWrapper {
return this; return this;
} }
/***
* 批量获取指定字段平均值
* @author hongawen
* @param prefix 表字段名
* @param suffix 映射名称
* @return InfluxQueryWrapper
* 输出 mean(prefix+diffContent+suffix) as prefix+diffContent+suffix
*/
public InfluxQueryWrapper meanSamePrefixAndSuffix(String prefix, String suffix, List<Object> diffContent) {
if (CollectionUtil.isEmpty(diffContent)) {
throw new RuntimeException("查询数值集合为空,请校验!");
}
for (Object obj : diffContent) {
String fieldName = prefix + obj + suffix;
this.mean(fieldName);
}
return this;
}
/*** /***
* 统计中位数 * 统计中位数