Skip to content

Commit

Permalink
Issue #151: Add required parameters and utility functions to calc score
Browse files Browse the repository at this point in the history
  • Loading branch information
Amar-Bolkan committed Nov 17, 2022
1 parent 6cd6bfa commit f899d98
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,5 +30,13 @@ public interface CustomTeamScoreService {
* @param badges all available badges
* @return never {@code null}
*/
TeamScoreDTO calculateTeamScore(TeamDTO t, List<TeamSkillDTO> teamSkills, List<SkillDTO> skills, List<BadgeDTO> badges);
TeamScoreDTO calculateTeamScore(
TeamDTO t,
List<TeamSkillDTO> teamSkills,
List<SkillDTO> skills,
List<BadgeDTO> badges,
List<BadgeSkillDTO> badgeSkills,
List<LevelDTO> levels,
List<LevelSkillDTO> levelSkills
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,23 +23,60 @@ public TeamScoreDTO calculateTeamScore(TeamDTO t) {
}

@Override
public TeamScoreDTO calculateTeamScore(TeamDTO t, List<TeamSkillDTO> teamSkills, List<SkillDTO> skills, List<BadgeDTO> badges) {
public TeamScoreDTO calculateTeamScore(
TeamDTO t,
List<TeamSkillDTO> teamSkills,
List<SkillDTO> skills,
List<BadgeDTO> badges,
List<BadgeSkillDTO> badgeSkills,
List<LevelDTO> levels,
List<LevelSkillDTO> 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<TeamSkillDTO> teamSkills, List<SkillDTO> 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<TeamSkillDTO> teamSkills, List<SkillDTO> skills) {
private Long calcLevelBonus(
TeamDTO t,
List<TeamSkillDTO> teamSkills,
List<SkillDTO> skills,
Map<Long, List<LevelSkillDTO>> groupedLevelSkills
) {
var score = t.getParticipations();

return 0L;
}

private Long calcBadgeBonus(TeamDTO t, List<TeamSkillDTO> teamSkills, List<SkillDTO> skills, List<BadgeDTO> badges) {
private Long calcBadgeBonus(
TeamDTO t,
List<TeamSkillDTO> teamSkills,
List<SkillDTO> skills,
List<BadgeDTO> badges,
Map<Long, List<BadgeSkillDTO>> groupedBadgeSkills
) {
return 0L;
}

private boolean isSkillCompleted(List<TeamSkillDTO> teamSkills, SkillDTO skill) {
return false;
}

private Map<Long, List<LevelSkillDTO>> groupLevelSkillsByLevelId(List<LevelSkillDTO> levelSkills) {
return levelSkills.stream().collect(Collectors.groupingBy(levelSkill -> levelSkill.getLevel().getId()));
}

private Map<Long, List<BadgeSkillDTO>> groupBadgeSkillsByBadgeId(List<BadgeSkillDTO> badgeSkills) {
return badgeSkills.stream().collect(Collectors.groupingBy(badgeSkill -> badgeSkill.getBadge().getId()));
}
}

0 comments on commit f899d98

Please sign in to comment.