Skip to content

Commit

Permalink
Merge pull request #131 from dnd-side-project/feat/#128
Browse files Browse the repository at this point in the history
feat: λŒ€μ‹œλ³΄λ“œ 쑰회 μ‹œ μ§μ ‘μž…λ ₯ μ˜΅μ…˜ νΌμ„ΌνŠΈ 응닡에 포함(#128)
  • Loading branch information
eun-seong authored Mar 19, 2024
2 parents 794ea4b + 5d57ab0 commit 24d5e76
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 28 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;
}
}

0 comments on commit 24d5e76

Please sign in to comment.