feat: 新增学生报告的指标

11111
winter 1 year ago
parent cec0a7e58d
commit ef1979cbd7

@ -111,6 +111,11 @@ public interface AppraiseRecordRepository extends CosmosRepository<AppraiseRecor
"group by c.targetId, n.appraiseNode.isPraise")
List<RankPo> studentRank(String code, String academicYearId, Long startTime, Long endTime);
@Query("select c.targetId, c.praiseCount from Student as c where c.code = @code and c.academicYearId = @academicYearId and c.targetType = 'student' and c.classId = @classId")
List<AppraiseRecord> findClassRecord(String code, String academicYearId, String classId);
// test script
@Query("select * from Student as c where c.code = @code")
List<AppraiseRecord> findByCode(String code);

@ -20,4 +20,6 @@ public interface StudentRepository extends CosmosRepository<Student, String> {
@Query("select c.id, c.name, c.classId from Student as c where c.code = @code and c.id in (@ids)")
List<Student> findAllByCodeAndIdIn(String code, Set<String> ids);
int countByClassIdAndCode(String classId, String code);
}

@ -2,10 +2,14 @@ package cn.teammodel.model.vo.appraise;
import cn.teammodel.common.FiveEducations;
import cn.teammodel.model.entity.appraise.AchievementRule;
import cn.teammodel.model.entity.appraise.AppraiseRecordItem;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -14,18 +18,41 @@ import java.util.Map;
* @create 2023-12-04 15:26
*/
@Data
@Builder
public class StudentReportVo {
@ApiModelProperty("学生表扬总数")
private Integer praiseCount;
@ApiModelProperty("学生总分")
private Integer score;
@ApiModelProperty("表扬数据超越了全班多少人")
private Float beyondPercent;
@ApiModelProperty("表扬最多的老师")
private Teacher topPraiseTeacher;
@ApiModelProperty("批评最多的老师")
private Teacher topCriticalTeacher;
@ApiModelProperty("最多的表扬指标")
private String topPraiseNode;
@ApiModelProperty("最多的批评指标")
private String topCriticalNode;
@ApiModelProperty("五育表扬分布图")
private Map<String, Integer> praiseDistribution;
@ApiModelProperty("五育待改进分布图")
private Map<String, Integer> criticalDistribution;
@ApiModelProperty("学生当前成就")
private AchievementRule curAchievement;
@ApiModelProperty("学生本学期的所有评价数据")
private List<AppraiseRecordItem> records;
public static Map<String, Integer> ofFiveEducation() {
Map<String, Integer> initialMap = new HashMap<>();
FiveEducations.codes().forEach(item -> {
@ -34,4 +61,12 @@ public class StudentReportVo {
return initialMap;
}
@Data
@AllArgsConstructor
public static class Teacher {
String id;
String name;
}
}

@ -426,20 +426,34 @@ public class EvaluationServiceImpl implements EvaluationService {
academicYearId,
String.format(PK.PK_APPRAISE_RECORD, schoolId)
);
int stuInClassCount = studentRepository.countByClassIdAndCode(classId, String.format(PK.STUDENT, schoolId));
List<AppraiseRecord> classRecord = appraiseRecordRepository.findClassRecord(String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, classId);
if (appraiseRecord == null || appraiseRecord.getNodes() == null) {
return null;
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "当前学生暂未产生评价数据,无法生成报告");
}
Integer praiseCount = appraiseRecord.getPraiseCount();
List<AppraiseRecordItem> records = appraiseRecord.getNodes();
records = records.stream().sorted(Comparator.comparing(AppraiseRecordItem::getCreateTime).reversed()).collect(Collectors.toList());
// 查询成就规则
Appraise appraise = RepositoryUtil.findOne(appraiseRepository.findRulesById(schoolId, periodId), "当前成就规则还未创建");
List<AchievementRule> rules = appraise.getAchievementRules();
if (CollectionUtil.isEmpty(rules)) {
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "当前成就规则为空");
}
StudentReportVo reportVo = new StudentReportVo();
// 计算雷达图
Map<String, Integer> praiseDistribution = StudentReportVo.ofFiveEducation();
Map<String, Integer> criticalDistribution = StudentReportVo.ofFiveEducation();
// 计算数据
Map<String, Integer> praiseTeacherMap = new HashMap<>();
Map<String, Integer> criticalTeacherMap = new HashMap<>();
Map<String, Integer> praiseNodeMap = new HashMap<>();
Map<String, Integer> criticalNodeMap = new HashMap<>();
// 计算当前学生排名在全班次位
float beyondPercent = 0;
long currentRank = classRecord.stream().filter(item -> item.getPraiseCount() < praiseCount).count();
beyondPercent = (float) currentRank / stuInClassCount;
// 根据全部数据计算结果
for (AppraiseRecordItem record : records) {
AppraiseTreeNode appraiseNode = record.getAppraiseNode();
String[] path = appraiseNode.getPath();
@ -450,19 +464,28 @@ public class EvaluationServiceImpl implements EvaluationService {
String root = path[0];
// 一级评价项不在预期中
String key = FiveEducations.getCodeByName(root);
if (key == null) {
// todo: 这里的数据异常情况是否需要上报一下
continue;
// 计算雷达图
if (key != null) {
if (appraiseNode.isPraise()) {
praiseDistribution.put(key, praiseDistribution.getOrDefault(key, 0) + 1);
} else {
criticalDistribution.put(key, criticalDistribution.getOrDefault(key, 0) + 1);
}
}
String teacherId = record.getCreatorId();
String nodeName = appraiseNode.getName();
// 根据评价是否为表扬计算数据
if (appraiseNode.isPraise()) {
praiseDistribution.put(key, praiseDistribution.getOrDefault(key, 0) + 1);
praiseTeacherMap.put(teacherId, praiseTeacherMap.getOrDefault(teacherId, 0) + 1);
praiseNodeMap.put(nodeName, praiseNodeMap.getOrDefault(nodeName, 0) + 1);
} else {
criticalDistribution.put(key, criticalDistribution.getOrDefault(key, 0) + 1);
criticalTeacherMap.put(teacherId, criticalTeacherMap.getOrDefault(teacherId, 0) + 1);
criticalNodeMap.put(nodeName, criticalNodeMap.getOrDefault(nodeName, 0) + 1);
}
}
// 计算成就项 (排序
rules = rules.stream().sorted(Comparator.comparing(AchievementRule::getLevel).reversed()).collect(Collectors.toList());
Integer praiseCount = appraiseRecord.getPraiseCount();
AchievementRule curAchievement = rules.get(rules.size() - 1);
for (AchievementRule rule : rules) {
Integer promotionCount = rule.getPromotionCount();
@ -473,12 +496,31 @@ public class EvaluationServiceImpl implements EvaluationService {
break;
}
}
reportVo.setPraiseCount(appraiseRecord.getPraiseCount());
reportVo.setScore(appraiseRecord.getScore());
reportVo.setPraiseDistribution(praiseDistribution);
reportVo.setCriticalDistribution(criticalDistribution);
reportVo.setCurAchievement(curAchievement);
return reportVo;
// 汇总数据
String topPraiseTeacherId = praiseTeacherMap.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null);
AppraiseRecordItem tmp1 = records.stream().filter(item -> item.getCreatorId().equals(topPraiseTeacherId)).findFirst().orElse(null);
String topPraiseTeacherName = tmp1 == null ? null : tmp1.getCreator();
String topCriticalTeacherId = criticalTeacherMap.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null);
AppraiseRecordItem tmp2 = records.stream().filter(item -> item.getCreatorId().equals(topCriticalTeacherId)).findFirst().orElse(null);
String topCriticalTeacherName = tmp2 == null ? null : tmp2.getCreator();
String topPraiseNode = praiseNodeMap.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null);
String topCriticalNode = criticalNodeMap.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null);
return StudentReportVo.builder()
.praiseCount(praiseCount)
.score(appraiseRecord.getScore())
.beyondPercent(beyondPercent)
.topPraiseTeacher(new StudentReportVo.Teacher(topPraiseTeacherId, topPraiseTeacherName))
.topCriticalTeacher(new StudentReportVo.Teacher(topCriticalTeacherId, topCriticalTeacherName))
.topPraiseNode(topPraiseNode)
.topCriticalNode(topCriticalNode)
.praiseDistribution(praiseDistribution)
.criticalDistribution(criticalDistribution)
.curAchievement(curAchievement)
.records(records)
.build();
}
/**

@ -230,7 +230,8 @@ class TeamModelExtensionApplicationTests {
// CosmosPatchOperations options = CosmosPatchOperations.create().add("/history/-", message);
// System.out.println(chatSessionRepository.save("111e90e5-6afd-413b-ae0f-646d957aedf8", PK.of(PK.CHAT_SESSION), ChatSession.class, options));
System.out.println(chatSessionRepository.findLatestMessage("111e90e5-6afd-413b-ae0f-646d957aedf8"));
// System.out.println(chatSessionRepository.findLatestMessage("111e90e5-6afd-413b-ae0f-646d957aedf8"));
System.out.println(appraiseRecordRepository.findClassRecord("AppraiseRecord-hbcn", "2023-08b81e76-e7d2-4001-8b4c-e7c789ef4bs1", "ae01dc81-1422-4643-bf13-0b38c6d15b1b"));
}

Loading…
Cancel
Save