修改getAnalyze函数数据格式-配备前端四级分析页面的柱状图数据
This commit is contained in:
parent
f23a1dd5dd
commit
a5f4b5965f
|
@ -686,7 +686,15 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
|
|||
.eq(!major.isEmpty(), Cet_4::getMajorname, major)
|
||||
.eq(Cet_4::getBatch, batch);
|
||||
List<Cet_4> list = list(queryWrapper);
|
||||
JSONObject rateByLastBatch = getRateByLastBatch(list);
|
||||
//设置要查询的范围端
|
||||
List<int[]> ranges = Arrays.asList(
|
||||
new int[]{0, 400},
|
||||
new int[]{400, 425},
|
||||
new int[]{425, 450},
|
||||
new int[]{450, 475},
|
||||
new int[]{475, 750}
|
||||
);
|
||||
JSONObject rateByLastBatch = getRateByBatchRanges(list, ranges);
|
||||
JSONObject scoreRateByLastBatch = getScoreRateByLastBatch(list);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("rateByBatch", rateByLastBatch);
|
||||
|
@ -694,18 +702,32 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
|
|||
return Result.ok(result);
|
||||
}
|
||||
|
||||
//400-425占比
|
||||
public JSONObject getRateByLastBatch(List<Cet_4> list) {
|
||||
|
||||
public JSONObject getRateByBatchRanges(List<Cet_4> list, List<int[]> ranges) {
|
||||
int total = list.size();
|
||||
int count = (int) list.stream().filter(e -> e.getResult() >= 400 && e.getResult() < 425).count();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
double rate = count / (double) total;
|
||||
rate=rate*100;
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
jsonObject.put("rate", df.format(rate));
|
||||
|
||||
// 遍历每个区间
|
||||
for (int[] range : ranges) {
|
||||
int min = range[0];
|
||||
int max = range[1];
|
||||
|
||||
// 计算符合条件的个数
|
||||
int count = (int) list.stream().filter(e -> e.getResult() >= min && e.getResult() < max).count();
|
||||
|
||||
// 计算比率
|
||||
double rate = count / (double) total;
|
||||
rate = rate * 100;
|
||||
|
||||
// 格式化结果并添加到结果中
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
jsonObject.put(min + "-" + max, df.format(rate));
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
//听力阅读等各个模块占比
|
||||
public JSONObject getScoreRateByLastBatch(List<Cet_4> list) {
|
||||
int total = list.size();
|
||||
|
|
Loading…
Reference in New Issue