@Entity @Data @AllArgsConstructor @NoArgsConstructor @Table(name = "scorerule") public…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
@Entity @Data @AllArgsConstructor @NoArgsConstructor @Table(name = "score_rule") public class ScoreRule { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private long id; @Column private long bid;//大作业id @Column private int scoreType;//评分类型 @Column private int rule;//策略选择1为权重策略,0为平均策略 @Column private int weight; @Column private boolean selectAppraise;//选择评价方式(分值评价true,星级评价false) } @Entity @Data @AllArgsConstructor @NoArgsConstructor @Table(name = "score_person") public class ScorePerson { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private long id; @Column private long sid;//被评id @Column private long uid;//评人id @Column private double score; @Column private int type; } @Entity @Data @AllArgsConstructor @NoArgsConstructor @Table(name = "score_group") public class ScoreGroup { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private long id; @Column private long gid;//被评id @Column private long uid;//评组id @Column private double score; @Column private int type; }
@Component public class ScoreManager { @Autowired ScorePersonRepository scorePersonRepository; @Autowired ScoreGroupRepository scoreGroupRepository;
code//处理个人成绩和小组成绩的层次结构 ScoreComponentU s = new ScoreComponentU(); //创建不同类型的成绩对象(教师分数、小组分数、组内成员分数) public Score createScoreByFactory(Object scoreData) { ScoreFactory factory = ScoreFactoryProvider.getFactory(scoreData); return factory.createScore(); } //动态添加额外的成绩计算功能,如加权、归一化等。 public Score createScoreByDecorator(Object scoreData) { ScoreFactory factory = ScoreFactoryProvider.getFactory(scoreData); Score baseScore = factory.createScore(); Score weightedScore = new WeightedScoreDecorator(baseScore, 0.5); Score normalizedScore = new NormalizedScoreDecorator(weightedScore, 0, 100); CompositeScoreDecorator compositeScore = new CompositeScoreDecorator(baseScore); compositeScore.addDecorator(new WeightedScoreDecorator(baseScore, 0.5)); compositeScore.addDecorator(new NormalizedScoreDecorator(baseScore, 0, 100)); return compositeScore; } public double compositePerson(List<ScorePerson> scorePersonList){ //List<ScorePerson> scorePersonList1; // 根据scoreType组合它们,得出综合得分,相同type的为一组 int type; double score = 0; Map<Integer, Double> typeScoreMap = new HashMap<>(); for (ScorePerson scores : scorePersonList) { int types = scores.getType(); double currentScore = scores.getScore(); typeScoreMap.put(types, typeScoreMap.getOrDefault(types, 0.0) + currentScore); score+=(currentScore); } return score; } - Assistant
要将单例模式应用到您的代码中,我们可以对
ScoreManager类进行修改,确保它只有一个实例被创建。这通常在多线程环境中很有用,以确保状态的一致性。下面是如何实现 作为单例的示例:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.