Skip to content

Commit

Permalink
DEAR-132 add github username
Browse files Browse the repository at this point in the history
  • Loading branch information
smuefsmuef committed Aug 10, 2024
1 parent e43c359 commit a8f52e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
@Repository
public interface InsightsRepository extends JpaRepository<HappinessSurvey, Integer> {

// todo review & refactor queries

// team overall happiness - no daterange
@Query("SELECT CAST(submitted AS DATE) as day, AVG(score) as average " +
"FROM HappinessSurvey " +
Expand Down Expand Up @@ -188,5 +186,4 @@ List<Object[]> findTeamWorkKindCountPerDayWithDateRange(
nativeQuery = true)
List<Object[]> findTeamWorkKindCountPerDayNoDateRange(@Param("teamId") Integer teamId);


}
26 changes: 11 additions & 15 deletions src/main/java/ch/fhnw/deardevbackend/services/InsightsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class InsightsService {
private final WorkKindInsightMapper workKindInsightMapper;
private final SprintConfigRepository sprintConfigRepository;


public InsightsService(InsightsRepository insightsRepository,
HappinessSurveyRepository happinessSurveyRepository,
HappinessInsightMapper happinessInsightMapper,
Expand Down Expand Up @@ -66,7 +65,6 @@ public List<HappinessInsightDTO> getHappinessInsightsByTeam(@ValidateUserIdParam
userAverages = happinessSurveyRepository.findDailyAveragesByUserId(userId);
teamAverages = insightsRepository.findTeamDailyAverages(teamId);
} else {
// todo make sure the sprint belongs to the team
SprintConfig sprintConfig = sprintConfigRepository.findById(sprintId)
.orElseThrow(() -> new IllegalArgumentException("Invalid sprint ID: " + sprintId));

Expand All @@ -86,9 +84,9 @@ public List<HappinessInsightDTO> getHappinessInsightsByTeam(@ValidateUserIdParam
return userAverages.stream()
.map(userAvg -> {
String day = userAvg[0].toString();
int userAverage = ((Number) userAvg[1]).intValue(); // Convert user average to Integer
int teamAverage = teamAveragesMap.getOrDefault(day, 0.0).intValue(); // Convert team average to Integer
return happinessInsightMapper.toDTO(day, (double) userAverage, (double) teamAverage);
int userAverage = ((Number) userAvg[1]).intValue();
int teamAverage = teamAveragesMap.getOrDefault(day, 0.0).intValue();
return happinessInsightMapper.toDTO(day, userAverage, teamAverage);
})
.filter(Objects::nonNull)
.sorted(Comparator.comparing(h -> LocalDate.parse(h.getDay(), DateTimeFormatter.ISO_DATE)))
Expand Down Expand Up @@ -153,16 +151,14 @@ private List<WorkKindInsightDTO> mergeUserAndTeamWorkKindInsights(List<WorkKindI

for (WorkKindInsightDTO teamInsight : teamWorkKindInsights) {
if (teamInsight != null) {
merged.merge(teamInsight.getWorkKindId(), teamInsight, (userDto, teamDto) -> {
return new WorkKindInsightDTO(
userDto.getWorkKindId(),
userDto.getWorkKindName(),
userDto.getUserAverage() != null ? userDto.getUserAverage() : 0,
userDto.getUserCount() != null ? userDto.getUserCount() : 0,
teamDto.getTeamAverage() != null ? teamDto.getTeamAverage() : 0,
teamDto.getTeamCount() != null ? teamDto.getTeamCount() : 0
);
});
merged.merge(teamInsight.getWorkKindId(), teamInsight, (userDto, teamDto) -> new WorkKindInsightDTO(
userDto.getWorkKindId(),
userDto.getWorkKindName(),
userDto.getUserAverage() != null ? userDto.getUserAverage() : 0,
userDto.getUserCount() != null ? userDto.getUserCount() : 0,
teamDto.getTeamAverage() != null ? teamDto.getTeamAverage() : 0,
teamDto.getTeamCount() != null ? teamDto.getTeamCount() : 0
));
}
}

Expand Down

0 comments on commit a8f52e0

Please sign in to comment.