From f899d983a5d39e2660a5eac8f1b09bd5ff7fd9b9 Mon Sep 17 00:00:00 2001 From: Amar Bolkan Date: Thu, 17 Nov 2022 16:20:26 +0100 Subject: [PATCH] Issue #151: Add required parameters and utility functions to calc score --- .../custom/CustomTeamScoreService.java | 15 +++-- .../custom/CustomTeamScoreServiceImpl.java | 57 +++++++++++++++---- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/iteratec/teamdojo/service/custom/CustomTeamScoreService.java b/src/main/java/com/iteratec/teamdojo/service/custom/CustomTeamScoreService.java index 7983e450..e85a0c59 100644 --- a/src/main/java/com/iteratec/teamdojo/service/custom/CustomTeamScoreService.java +++ b/src/main/java/com/iteratec/teamdojo/service/custom/CustomTeamScoreService.java @@ -4,10 +4,7 @@ */ package com.iteratec.teamdojo.service.custom; -import com.iteratec.teamdojo.service.dto.BadgeDTO; -import com.iteratec.teamdojo.service.dto.SkillDTO; -import com.iteratec.teamdojo.service.dto.TeamDTO; -import com.iteratec.teamdojo.service.dto.TeamSkillDTO; +import com.iteratec.teamdojo.service.dto.*; import com.iteratec.teamdojo.service.dto.custom.TeamScoreDTO; import java.util.List; import lombok.NonNull; @@ -33,5 +30,13 @@ public interface CustomTeamScoreService { * @param badges all available badges * @return never {@code null} */ - TeamScoreDTO calculateTeamScore(TeamDTO t, List teamSkills, List skills, List badges); + TeamScoreDTO calculateTeamScore( + TeamDTO t, + List teamSkills, + List skills, + List badges, + List badgeSkills, + List levels, + List levelSkills + ); } diff --git a/src/main/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImpl.java b/src/main/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImpl.java index 6a3089dc..2dfd8afe 100644 --- a/src/main/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImpl.java +++ b/src/main/java/com/iteratec/teamdojo/service/impl/custom/CustomTeamScoreServiceImpl.java @@ -5,13 +5,11 @@ package com.iteratec.teamdojo.service.impl.custom; import com.iteratec.teamdojo.service.custom.CustomTeamScoreService; -import com.iteratec.teamdojo.service.dto.BadgeDTO; -import com.iteratec.teamdojo.service.dto.SkillDTO; -import com.iteratec.teamdojo.service.dto.TeamDTO; -import com.iteratec.teamdojo.service.dto.TeamSkillDTO; +import com.iteratec.teamdojo.service.dto.*; import com.iteratec.teamdojo.service.dto.custom.TeamScoreDTO; import java.util.List; -import lombok.NonNull; +import java.util.Map; +import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -25,23 +23,60 @@ public TeamScoreDTO calculateTeamScore(TeamDTO t) { } @Override - public TeamScoreDTO calculateTeamScore(TeamDTO t, List teamSkills, List skills, List badges) { + public TeamScoreDTO calculateTeamScore( + TeamDTO t, + List teamSkills, + List skills, + List badges, + List badgeSkills, + List levels, + List levelSkills + ) { + final var groupedBadgeSkills = this.groupBadgeSkillsByBadgeId(badgeSkills); + final var groupedLevelskills = this.groupLevelSkillsByLevelId(levelSkills); + final var skillScore = this.calcSkillScore(t, teamSkills, skills); - final var levelBonus = this.calcLevelBonus(t, teamSkills, skills); - final var badgeBonus = this.calcBadgeBonus(t, teamSkills, skills, badges); + final var levelBonus = this.calcLevelBonus(t, teamSkills, skills, groupedLevelskills); + final var badgeBonus = this.calcBadgeBonus(t, teamSkills, skills, badges, groupedBadgeSkills); final var totalScore = skillScore + levelBonus + badgeBonus; return new TeamScoreDTO(t, totalScore); } private Long calcSkillScore(TeamDTO t, List teamSkills, List skills) { - return 0L; + var score = skills.stream().filter(skill -> this.isSkillCompleted(teamSkills, skill)).mapToLong(SkillDTO::getScore).sum(); + return score; } - private Long calcLevelBonus(TeamDTO t, List teamSkills, List skills) { + private Long calcLevelBonus( + TeamDTO t, + List teamSkills, + List skills, + Map> groupedLevelSkills + ) { + var score = t.getParticipations(); + return 0L; } - private Long calcBadgeBonus(TeamDTO t, List teamSkills, List skills, List badges) { + private Long calcBadgeBonus( + TeamDTO t, + List teamSkills, + List skills, + List badges, + Map> groupedBadgeSkills + ) { return 0L; } + + private boolean isSkillCompleted(List teamSkills, SkillDTO skill) { + return false; + } + + private Map> groupLevelSkillsByLevelId(List levelSkills) { + return levelSkills.stream().collect(Collectors.groupingBy(levelSkill -> levelSkill.getLevel().getId())); + } + + private Map> groupBadgeSkillsByBadgeId(List badgeSkills) { + return badgeSkills.stream().collect(Collectors.groupingBy(badgeSkill -> badgeSkill.getBadge().getId())); + } }