Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added progress bars for Match Merging and Token String Normalization. #1690

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading