261104_01_ENH: 기존 통계 결과를 유지하며 데이터 접근 및 문항·쿼터 설정 해석 분리
This commit is contained in:
@@ -22,12 +22,10 @@ import com.kri.kart.server.service.statistics.StatisticsDataService;
|
||||
import com.kri.kart.server.service.statistics.StatisticsDimension;
|
||||
import com.kri.kart.server.service.statistics.StatisticsDimensionService;
|
||||
import com.kri.kart.server.service.statistics.StatisticsFilterService;
|
||||
import com.kri.kart.server.service.statistics.StatisticsSourceService;
|
||||
import com.kri.kart.server.service.statistics.StatisticsTextService;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Predicate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -43,6 +41,7 @@ public class StatisticsService {
|
||||
private final QuestionRepository questionRepository;
|
||||
private final QuestionService questionService;
|
||||
private final StatisticsDataService statisticsDataService;
|
||||
private final StatisticsSourceService statisticsSourceService;
|
||||
private final StatisticsDimensionService statisticsDimensionService;
|
||||
private final StatisticsFilterService statisticsFilterService;
|
||||
private final StatisticsAggregationService statisticsAggregationService;
|
||||
@@ -188,7 +187,7 @@ public class StatisticsService {
|
||||
needsProfileResponses(project, requests, sharedRequest, questions);
|
||||
// Query the union of all storage roots once; calculate() narrows it again for each index.
|
||||
List<String> storageRoots =
|
||||
requests.stream().flatMap(request -> storageRoots(request).stream()).distinct().toList();
|
||||
requests.stream().flatMap(request -> statisticsSourceService.storageRoots(request).stream()).distinct().toList();
|
||||
List<StatisticsDataDto> data =
|
||||
statisticsRepository.data(project, sharedRequest, includeProfileResponses, storageRoots);
|
||||
return statisticsDataService.normalize(data).stream().filter(filter).toList();
|
||||
@@ -203,8 +202,8 @@ public class StatisticsService {
|
||||
if (project.projectType() != ProjectType.KIWI) {
|
||||
return false;
|
||||
}
|
||||
return requests.stream().anyMatch(request -> isProfileId(request.getIndex()))
|
||||
|| sharedRequest.getBanners().stream().flatMap(List::stream).anyMatch(this::isProfileId)
|
||||
return requests.stream().anyMatch(request -> statisticsSourceService.isProfileId(request.getIndex()))
|
||||
|| sharedRequest.getBanners().stream().flatMap(List::stream).anyMatch(statisticsSourceService::isProfileId)
|
||||
|| filterUsesProfile(sharedRequest.getFilter(), questions);
|
||||
}
|
||||
|
||||
@@ -213,25 +212,17 @@ public class StatisticsService {
|
||||
return false;
|
||||
}
|
||||
if (filter.getDimensionId() != null
|
||||
&& isProfileId(statisticsFilterService.resolveQid(filter, questions))) {
|
||||
&& statisticsSourceService.isProfileId(statisticsFilterService.resolveQid(filter, questions))) {
|
||||
return true;
|
||||
}
|
||||
return filter.getChildren().stream().anyMatch(child -> filterUsesProfile(child, questions));
|
||||
}
|
||||
|
||||
private boolean isProfileId(String id) {
|
||||
String normalized = StringUtil.normalizeBlank(id);
|
||||
if (normalized == null) {
|
||||
return false;
|
||||
}
|
||||
String upperCaseId = normalized.toUpperCase(Locale.ROOT);
|
||||
return KartConstant.PROFILE_ID_PREFIXES.stream().anyMatch(upperCaseId::startsWith);
|
||||
}
|
||||
|
||||
private StatisticsResponseDto calculate(
|
||||
StatisticsBatchDto statisticsBatch, StatisticsRequestDto request) {
|
||||
List<SurveyResponseDto> responses =
|
||||
withinStorageRoots(statisticsBatch.responses(), storageRoots(request));
|
||||
statisticsSourceService.withinStorageRoots(
|
||||
statisticsBatch.responses(), statisticsSourceService.storageRoots(request));
|
||||
StatisticsDimension index =
|
||||
statisticsDimensionService.resolve(
|
||||
request.getIndex(), statisticsBatch.questions(), responses);
|
||||
@@ -242,34 +233,8 @@ public class StatisticsService {
|
||||
request, statisticsBatch.questions(), responses);
|
||||
}
|
||||
|
||||
/** The shared union query must not add respondents that a single-index query would omit. */
|
||||
private List<SurveyResponseDto> withinStorageRoots(
|
||||
List<SurveyResponseDto> responses, List<String> storageRoots) {
|
||||
Predicate<String> storedUnderRoots =
|
||||
key -> storageRoots.contains(key) || storageRoots.contains(key.split("_")[0]);
|
||||
return responses.stream()
|
||||
.filter(response -> response.values().keySet().stream().anyMatch(storedUnderRoots))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/** Storage root keys selected by the original single-index query: index plus banners. */
|
||||
private List<String> storageRoots(StatisticsRequestDto request) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
ids.add(isStandard(request) ? request.getIndex() : KartConstant.TABULATION_STORAGE_ROOT);
|
||||
request.getBanners().forEach(ids::addAll);
|
||||
return ids.stream().map(this::toStorageRoot).distinct().toList();
|
||||
}
|
||||
|
||||
/** e.g. "q1_2#a" -> "Q1": upper-case, drop the attribute projection and keep the root. */
|
||||
private String toStorageRoot(String id) {
|
||||
return Objects.toString(StringUtil.normalizeBlank(id), "")
|
||||
.toUpperCase(Locale.ROOT)
|
||||
.replace(KartConstant.ATTRIBUTE_PROJECTION_SUFFIX, "")
|
||||
.split("_")[0];
|
||||
}
|
||||
|
||||
private boolean isOpenText(StatisticsDimension index) {
|
||||
return "text".equals(index.getQuestion().getQtype()) && !index.isAttributeProjection();
|
||||
return "text".equals(index.getQuestionType()) && !index.isAttributeProjection();
|
||||
}
|
||||
|
||||
private StatisticsResponseDto textAnalysis(
|
||||
@@ -280,7 +245,7 @@ public class StatisticsService {
|
||||
return StatisticsResponseDto.builder()
|
||||
.type("TEXT_ANALYSIS")
|
||||
.questionId(index.getDimensionId())
|
||||
.title(index.getQuestion().getTitle())
|
||||
.title(index.getTitle())
|
||||
.columns(List.of())
|
||||
.headerRows(List.of())
|
||||
.rows(List.of())
|
||||
|
||||
Reference in New Issue
Block a user