Skip to content

Commit

Permalink
Merge pull request #1690 from jplag/feature/additionalProgressBars
Browse files Browse the repository at this point in the history
Added progress bars for Match Merging and Token String Normalization.
  • Loading branch information
tsaglam authored Apr 16, 2024
2 parents 2f1d6a7 + 3e79571 commit d1ce85d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/de/jplag/SubmissionSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public List<Submission> getInvalidSubmissions() {
}

public void normalizeSubmissions() {
submissions.forEach(Submission::normalize);
ProgressBarLogger.iterate(ProgressBarType.TOKEN_STRING_NORMALIZATION, submissions, Submission::normalize);
}

private List<Submission> filterValidSubmissions() {
Expand Down
24 changes: 24 additions & 0 deletions core/src/main/java/de/jplag/logging/ProgressBarLogger.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package de.jplag.logging;

import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -32,6 +36,26 @@ public static void setProgressBarProvider(ProgressBarProvider progressBarProvide
ProgressBarLogger.progressBarProvider = progressBarProvider;
}

/**
* Iterates over the given collection while showing and updating a progress bar of the given type. The progress bar is
* updated, everytime the given action is done.
* @param type The type of progress bar
* @param data The data to iterate over
* @param action The action to call for each item
* @param <T> The type of data
*/
public static <T> void iterate(ProgressBarType type, Collection<T> data, Consumer<T> action) {
Iterator<T> iterator = data.iterator();
ProgressBar progressBar = ProgressBarLogger.createProgressBar(type, data.size());

while (iterator.hasNext()) {
action.accept(iterator.next());
progressBar.step();
}

progressBar.dispose();
}

private static class DummyProvider implements ProgressBarProvider {
@Override
public ProgressBar initProgressBar(ProgressBarType type, int totalSteps) {
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/de/jplag/logging/ProgressBarType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
public enum ProgressBarType {
LOADING("Loading Submissions "),
PARSING("Parsing Submissions "),
COMPARING("Comparing Submissions");
COMPARING("Comparing Submissions"),
MATCH_MERGING("Merging matched subsequences "),
TOKEN_STRING_NORMALIZATION("Normalizing Token Sequence");

private final String defaultText;

Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/de/jplag/merging/MatchMerging.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import de.jplag.SharedTokenType;
import de.jplag.Submission;
import de.jplag.Token;
import de.jplag.logging.ProgressBarLogger;
import de.jplag.logging.ProgressBarType;
import de.jplag.options.JPlagOptions;

/**
Expand Down Expand Up @@ -44,15 +46,15 @@ public JPlagResult mergeMatchesOf(JPlagResult result) {
List<JPlagComparison> comparisons = new ArrayList<>(result.getAllComparisons());
List<JPlagComparison> comparisonsMerged = new ArrayList<>();

for (JPlagComparison comparison : comparisons) {
ProgressBarLogger.iterate(ProgressBarType.MATCH_MERGING, comparisons, comparison -> {
Submission leftSubmission = comparison.firstSubmission().copy();
Submission rightSubmission = comparison.secondSubmission().copy();
List<Match> globalMatches = new ArrayList<>(comparison.matches());
globalMatches.addAll(comparison.ignoredMatches());
globalMatches = mergeNeighbors(globalMatches, leftSubmission, rightSubmission);
globalMatches = globalMatches.stream().filter(it -> it.length() >= options.minimumTokenMatch()).toList();
comparisonsMerged.add(new JPlagComparison(leftSubmission, rightSubmission, globalMatches, new ArrayList<>()));
}
});

long durationInMillis = System.currentTimeMillis() - timeBeforeStartInMillis;
return new JPlagResult(comparisonsMerged, result.getSubmissions(), result.getDuration() + durationInMillis, options);
Expand Down

0 comments on commit d1ce85d

Please sign in to comment.