Skip to content

Commit

Permalink
Merge pull request #132 from dnd-side-project/dev
Browse files Browse the repository at this point in the history
release v0.2.5
  • Loading branch information
eun-seong authored Mar 19, 2024
2 parents d353e58 + 24d5e76 commit 3b91a6c
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.dnd.namuiwiki.domain.dashboard.model.dto.RatioDto;
import com.dnd.namuiwiki.domain.dashboard.type.DashboardType;
import com.dnd.namuiwiki.domain.statistic.model.Legend;
import com.dnd.namuiwiki.domain.statistic.model.RatioStatistic;
import com.dnd.namuiwiki.domain.statistic.model.Statistics;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Getter
public class BestWorthDashboardComponent extends DashboardComponent {
Expand All @@ -25,15 +28,29 @@ public void calculate(Statistics statistics) {
RatioStatistic bestWorth = (RatioStatistic) statistics.getStatisticsByDashboardType(this.dashboardType).get(0);
Long totalCount = bestWorth.getTotalCount();

this.rank = bestWorth.getLegends().stream()
.map(legend -> {
if (totalCount == 0) {
return new RatioDto(legend.getText(), 0);
}
int percentage = (int) (legend.getCount() * 100 / totalCount);
return new RatioDto(legend.getText(), percentage);
})
.toList();
List<Legend> legends = bestWorth.getLegends();
int optionPercentage = 0;

this.rank = new ArrayList<>();

for (Legend legend : legends) {
if (totalCount == 0) {
rank.add(new RatioDto(legend.getText(), 0));
}
int percentage = (int) (legend.getCount() * 100 / totalCount);
optionPercentage += percentage;
rank.add(new RatioDto(legend.getText(), percentage));
}

// ์ง์ ‘์ž…๋ ฅ์ธ legend ์ธ๊ฑฐ ์ฐพ์•„์„œ ์ƒˆ๋กœ ์—…๋ฐ์ดํŠธ
updateManualLegendPercentage(optionPercentage);
}

private void updateManualLegendPercentage(int optionPercentage) {
Optional<RatioDto> manualLegend = this.rank.stream()
.filter(legend -> legend.getLegend().contains("์ง์ ‘ ์ž…๋ ฅ"))
.findFirst();
manualLegend.ifPresent(ratioDto -> ratioDto.setPercentage(100 - optionPercentage));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.dnd.namuiwiki.domain.dashboard.model.dto.RatioDto;
import com.dnd.namuiwiki.domain.dashboard.type.DashboardType;
import com.dnd.namuiwiki.domain.statistic.model.Legend;
import com.dnd.namuiwiki.domain.statistic.model.RatioStatistic;
import com.dnd.namuiwiki.domain.statistic.model.Statistics;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Getter
public class HappyDashboardComponent extends DashboardComponent {
Expand All @@ -24,15 +27,30 @@ public HappyDashboardComponent(Statistics statistics, String questionId) {
public void calculate(Statistics statistics) {
RatioStatistic happy = (RatioStatistic) statistics.getStatisticsByDashboardType(this.dashboardType).get(0);
Long totalCount = happy.getTotalCount();
this.rank = happy.getLegends().stream()
.map(legend -> {
if (totalCount == 0) {
return new RatioDto(legend.getText(), 0);
}
int percentage = (int) (legend.getCount() * 100 / totalCount);
return new RatioDto(legend.getText(), percentage);
})
.toList();

List<Legend> legends = happy.getLegends();
int optionPercentage = 0;

this.rank = new ArrayList<>();

for (Legend legend : legends) {
if (totalCount == 0) {
rank.add(new RatioDto(legend.getText(), 0));
}
int percentage = (int) (legend.getCount() * 100 / totalCount);
optionPercentage += percentage;
rank.add(new RatioDto(legend.getText(), percentage));
}

// ์ง์ ‘์ž…๋ ฅ์ธ legend ์ธ๊ฑฐ ์ฐพ์•„์„œ ์ƒˆ๋กœ ์—…๋ฐ์ดํŠธ
updateManualLegendPercentage(optionPercentage);
}

private void updateManualLegendPercentage(int optionPercentage) {
Optional<RatioDto> manualLegend = this.rank.stream()
.filter(legend -> legend.getLegend().contains("์ง์ ‘ ์ž…๋ ฅ"))
.findFirst();
manualLegend.ifPresent(ratioDto -> ratioDto.setPercentage(100 - optionPercentage));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.dnd.namuiwiki.domain.dashboard.model.dto.RatioDto;
import com.dnd.namuiwiki.domain.dashboard.type.DashboardType;
import com.dnd.namuiwiki.domain.statistic.model.Legend;
import com.dnd.namuiwiki.domain.statistic.model.RatioStatistic;
import com.dnd.namuiwiki.domain.statistic.model.Statistics;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Getter
public class SadDashboardComponent extends DashboardComponent {
Expand All @@ -24,15 +27,30 @@ public SadDashboardComponent(Statistics statistics, String questionId) {
public void calculate(Statistics statistics) {
RatioStatistic sad = (RatioStatistic) statistics.getStatisticsByDashboardType(this.dashboardType).get(0);
Long totalCount = sad.getTotalCount();
this.rank = sad.getLegends().stream()
.map(legend -> {
if (totalCount == 0) {
return new RatioDto(legend.getText(), 0);
}
int percentage = (int) (legend.getCount() * 100 / totalCount);
return new RatioDto(legend.getText(), percentage);
})
.toList();

List<Legend> legends = sad.getLegends();
int optionPercentage = 0;

this.rank = new ArrayList<>();

for (Legend legend : legends) {
if (totalCount == 0) {
rank.add(new RatioDto(legend.getText(), 0));
}
int percentage = (int) (legend.getCount() * 100 / totalCount);
optionPercentage += percentage;
rank.add(new RatioDto(legend.getText(), percentage));
}

// ์ง์ ‘์ž…๋ ฅ์ธ legend ์ธ๊ฑฐ ์ฐพ์•„์„œ ์ƒˆ๋กœ ์—…๋ฐ์ดํŠธ
updateManualLegendPercentage(optionPercentage);
}

private void updateManualLegendPercentage(int optionPercentage) {
Optional<RatioDto> manualLegend = this.rank.stream()
.filter(legend -> legend.getLegend().contains("์ง์ ‘ ์ž…๋ ฅ"))
.findFirst();
manualLegend.ifPresent(ratioDto -> ratioDto.setPercentage(100 - optionPercentage));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
@Getter
public class RatioDto {
private final String legend;
private final int percentage;
private int percentage;

public void setPercentage(int percentage) {
this.percentage = percentage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public GetAnswersByQuestionResponse getAnswersByQuestion(String wikiId, String q
.build();
});

return new GetAnswersByQuestionResponse(question.getTitle(), PageableDto.create(answers));
return new GetAnswersByQuestionResponse(question.getTitle(), question.getName(), PageableDto.create(answers));
}

private void validateFilter(Period period, Relation relation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.namuiwiki.domain.survey.model.dto;

import com.dnd.namuiwiki.common.dto.PageableDto;
import com.dnd.namuiwiki.domain.question.type.QuestionName;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -10,5 +11,6 @@
@Getter
public class GetAnswersByQuestionResponse {
private String questionTitle;
private QuestionName questionName;
private PageableDto<SingleAnswerWithSurveyDetailDto> answers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import com.dnd.namuiwiki.domain.survey.model.entity.Survey;
import com.dnd.namuiwiki.domain.survey.type.Period;
import com.dnd.namuiwiki.domain.survey.type.Relation;
import com.dnd.namuiwiki.domain.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

@Getter
@AllArgsConstructor
public class ReceivedSurveyDto {
Expand All @@ -14,13 +17,21 @@ public class ReceivedSurveyDto {
private Relation relation;
private Period period;
private String senderName;
private String senderWikiId;

public static ReceivedSurveyDto from(Survey survey) {
String senderWikiId = null;
User sender = survey.getSender();
if (sender != null) {
senderWikiId = sender.getWikiId();
}

return new ReceivedSurveyDto(
survey.getId(),
survey.getRelation(),
survey.getPeriod(),
survey.getSenderName()
survey.getSenderName(),
senderWikiId
);
}

Expand Down

0 comments on commit 3b91a6c

Please sign in to comment.