Skip to content

Commit

Permalink
simon feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
az108 committed Dec 2, 2024
1 parent d363283 commit b157de6
Showing 1 changed file with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -645,7 +645,7 @@ public FeedbackAnalysisResponseDTO getFeedbackDetailsOnPage(long exerciseId, Fee
List<FeedbackDetailDTO> allFeedbackDetails = feedbackDetailPage.getContent();

// Apply Levenshtein-based grouping and aggregation with a similarity threshold of 90%
List<FeedbackDetailDTO> aggregatedFeedbackDetails = aggregateUsingLevenshtein(allFeedbackDetails, 0.5);
List<FeedbackDetailDTO> aggregatedFeedbackDetails = aggregateUsingLevenshtein(allFeedbackDetails, 0.9);

levenshteinMaxCount = aggregatedFeedbackDetails.stream().mapToLong(FeedbackDetailDTO::count).max().orElse(0);
// Apply manual pagination
Expand Down Expand Up @@ -682,36 +682,40 @@ private Comparator<FeedbackDetailDTO> getComparatorForFeedbackDetails(FeedbackPa
}

private List<FeedbackDetailDTO> aggregateUsingLevenshtein(List<FeedbackDetailDTO> feedbackDetails, double similarityThreshold) {
// Group by testCaseName and taskName using nested maps
Map<String, Map<String, List<FeedbackDetailDTO>>> groupedByKeys = feedbackDetails.stream()
.collect(Collectors.groupingBy(FeedbackDetailDTO::testCaseName, Collectors.groupingBy(FeedbackDetailDTO::taskName)));

List<FeedbackDetailDTO> aggregatedList = new ArrayList<>();
Set<FeedbackDetailDTO> processedDetails = new HashSet<>();

// Iterate through the grouped data
groupedByKeys.forEach((testCaseName, taskMap) -> {
taskMap.forEach((taskName, feedbackGroup) -> {
List<FeedbackDetailDTO> unprocessed = new ArrayList<>(feedbackGroup);
while (!unprocessed.isEmpty()) {
FeedbackDetailDTO base = unprocessed.removeFirst();
List<String> aggregatedTexts = new ArrayList<>(base.detailText());
long totalCount = base.count();

Iterator<FeedbackDetailDTO> iterator = unprocessed.iterator();
while (iterator.hasNext()) {
FeedbackDetailDTO compare = iterator.next();
double similarity = NameSimilarity.levenshteinSimilarity(base.detailText().get(0), compare.detailText().get(0));
if (similarity > similarityThreshold) {
aggregatedTexts.add(compare.detailText().get(0));
totalCount += compare.count();
iterator.remove(); // Remove processed entry
}
}
for (FeedbackDetailDTO base : feedbackDetails) {
if (processedDetails.contains(base)) {
continue; // Skip already aggregated feedback
}

aggregatedList.add(new FeedbackDetailDTO(totalCount, 0, aggregatedTexts, testCaseName, taskName, base.errorCategory()));
List<String> aggregatedTexts = new ArrayList<>();
aggregatedTexts.add(base.detailText().getFirst());
long totalCount = base.count();

for (FeedbackDetailDTO compare : feedbackDetails) {
if (processedDetails.contains(compare) || base.equals(compare)) {
continue; // Skip already processed or the same feedback
}
});
});

// Ensure feedbacks have the same testCaseName and taskName
if (base.testCaseName().equals(compare.testCaseName()) && base.taskName().equals(compare.taskName())) {
double similarity = NameSimilarity.levenshteinSimilarity(base.detailText().getFirst(), compare.detailText().getFirst());

if (similarity > similarityThreshold) {
// Merge the feedbacks
aggregatedTexts.add(compare.detailText().getFirst());
totalCount += compare.count();
processedDetails.add(compare);
}
}
}

// Add aggregated feedback entry
aggregatedList.add(new FeedbackDetailDTO(totalCount, 0, aggregatedTexts, base.testCaseName(), base.taskName(), base.errorCategory()));
processedDetails.add(base);
}

return aggregatedList;
}
Expand Down

0 comments on commit b157de6

Please sign in to comment.