-
Notifications
You must be signed in to change notification settings - Fork 334
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
Draft: Optimize report viewer dto size #507
Closed
nestabentum
wants to merge
6
commits into
jplag:master
from
nestabentum:optimize_reportViewer_dto_size_new
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1708cc6
Add Max Metric to Webreport
nestabentum efe795e
ReportViewer - Save File Lines as Indices to LookUpTable
nestabentum 726efb7
Serialize ReportObjects Immediately
nestabentum c023549
Save Submissions Unchanged and in their own folders
nestabentum 6084b8f
Use Original SubmissionFiles in Report DTOs
nestabentum e2ef33b
Improve Readability of JPlagResult#calculateDistributionFor
nestabentum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package de.jplag; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import de.jplag.clustering.ClusteringResult; | ||
import de.jplag.options.JPlagOptions; | ||
import de.jplag.options.SimilarityMetric; | ||
|
||
/** | ||
* Encapsulates the results of a comparison of a set of source code submissions. | ||
|
@@ -21,6 +23,7 @@ public class JPlagResult { | |
private final int[] similarityDistribution; // 10-element array representing the similarity distribution of the detected matches. | ||
|
||
private List<ClusteringResult<Submission>> clusteringResult; | ||
private final int SIMILARITY_DISTRIBUTION_SIZE = 10; | ||
|
||
public JPlagResult(List<JPlagComparison> comparisons, SubmissionSet submissions, long durationInMillis, JPlagOptions options) { | ||
this.comparisons = comparisons; | ||
|
@@ -47,7 +50,7 @@ public void setClusteringResult(List<ClusteringResult<Submission>> clustering) { | |
/** | ||
* @return a list of all comparisons sorted by percentage (descending) | ||
*/ | ||
public List<JPlagComparison> getComparisons() { | ||
public List<JPlagComparison> getAllComparisons() { | ||
return comparisons; | ||
} | ||
|
||
|
@@ -93,34 +96,49 @@ public JPlagOptions getOptions() { | |
} | ||
|
||
/** | ||
* Returns the similarity distribution of detected matches in a 10-element array. Each entry represents the absolute | ||
* frequency of matches whose similarity lies within the respective interval. Intervals: 0: [0% - 10%), 1: [10% - 20%), | ||
* 2: [20% - 30%), ..., 9: [90% - 100%] | ||
* For the {@link SimilarityMetric} JPlag was run with, this returns the similarity distribution of detected matches in | ||
* a 10-element array. Each entry represents the absolute frequency of matches whose similarity lies within the | ||
* respective interval. Intervals: 0: [0% - 10%), 1: [10% - 20%), 2: [20% - 30%), ..., 9: [90% - 100%] | ||
* @return the similarity distribution array. | ||
*/ | ||
public int[] getSimilarityDistribution() { | ||
return similarityDistribution; | ||
} | ||
|
||
/** | ||
* For the {@link SimilarityMetric#MAX} that is built in to every {@link JPlagComparison}, this returns the similarity | ||
* distribution of detected matches in a 10-element array. Each entry represents the absolute frequency of matches whose | ||
* similarity lies within the respective interval. Intervals: 0: [0% - 10%), 1: [10% - 20%), 2: [20% - 30%), ..., 9: | ||
* [90% - 100%] | ||
* @return the similarity distribution array. When JPlag was run with the {@link SimilarityMetric#MAX}, this will return | ||
* the same distribution as {@link JPlagResult#getSimilarityDistribution()} | ||
*/ | ||
public int[] getMaxSimilarityDistribution() { | ||
return calculateDistributionFor(comparisons, (JPlagComparison::maximalSimilarity)); | ||
} | ||
|
||
public List<ClusteringResult<Submission>> getClusteringResult() { | ||
return this.clusteringResult; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("JPlagResult { comparisons: %d, duration: %d ms, language: %s, submissions: %d }", getComparisons().size(), | ||
return String.format("JPlagResult { comparisons: %d, duration: %d ms, language: %s, submissions: %d }", getAllComparisons().size(), | ||
getDuration(), getOptions().getLanguageOption(), submissions.numberOfSubmissions()); | ||
} | ||
|
||
/** | ||
* Note: Before, comparisons with a similarity below the given threshold were also included in the similarity matrix. | ||
*/ | ||
private int[] calculateSimilarityDistribution(List<JPlagComparison> comparisons) { | ||
int[] similarityDistribution = new int[10]; | ||
|
||
comparisons.stream().map(JPlagComparison::similarity).map(percent -> percent / 10).map(Float::intValue).map(index -> index == 10 ? 9 : index) | ||
.forEach(index -> similarityDistribution[index]++); | ||
return calculateDistributionFor(comparisons, (JPlagComparison::similarity)); | ||
} | ||
|
||
private int[] calculateDistributionFor(List<JPlagComparison> comparisons, Function<JPlagComparison, Float> similarityExtractor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make this lambda to a 'normal' loop. From my point of view, it's not that easy to read |
||
int[] similarityDistribution = new int[SIMILARITY_DISTRIBUTION_SIZE]; | ||
comparisons.stream().map(similarityExtractor).map(percent -> percent / SIMILARITY_DISTRIBUTION_SIZE).map(Float::intValue) | ||
.map(index -> index == SIMILARITY_DISTRIBUTION_SIZE ? SIMILARITY_DISTRIBUTION_SIZE - 1 : index) | ||
.forEach(index -> similarityDistribution[SIMILARITY_DISTRIBUTION_SIZE - 1 - index]++); | ||
return similarityDistribution; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
package de.jplag.reporting; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import de.jplag.JPlagResult; | ||
import de.jplag.reporting.jsonfactory.JsonFactory; | ||
import de.jplag.reporting.reportobject.ReportObjectFactory; | ||
import de.jplag.reporting.reportobject.model.JPlagReport; | ||
|
||
// ReportImplementation -> JsonReport | ||
|
||
/** | ||
* A report generator which reports the JPlagResult in Json format. | ||
*/ | ||
public class JsonReport implements Report { | ||
|
||
@Override | ||
public List<String> getReportStrings(JPlagResult result) { | ||
JPlagReport report = ReportObjectFactory.getReportObject(result); | ||
return JsonFactory.getJsonStrings(report); | ||
} | ||
|
||
@Override | ||
public boolean saveReport(JPlagResult result, String path) { | ||
public void saveReport(JPlagResult result, String path) { | ||
JPlagReport report = ReportObjectFactory.getReportObject(result); | ||
File directory = new File(path); | ||
if (!directory.exists()) { | ||
if (!directory.mkdirs()) { | ||
logger.error("Failed to create dir."); | ||
} | ||
} | ||
return JsonFactory.saveJsonFiles(report, path); | ||
JsonFactory.saveJsonFiles(report, path); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,21 @@ | ||
package de.jplag.reporting; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import de.jplag.JPlagResult; | ||
|
||
// ReportStrategy -> Report | ||
|
||
/** | ||
* Strategy interface for reporting. A report generator should implement this interface. | ||
*/ | ||
public interface Report { | ||
|
||
Logger logger = LoggerFactory.getLogger(Report.class); | ||
|
||
/** | ||
* This function returns a list containing the report objects as simple strings. The first element is the string of the | ||
* overview object. Each following element is a string of a comparison report object. | ||
* @param result The result of a JPlag comparison | ||
* @return A list containing report objects to string. First element is Overview. Other elements are comparisons. | ||
*/ | ||
List<String> getReportStrings(JPlagResult result); | ||
|
||
/** | ||
* Creates and saves JPlag report files to the disk. | ||
* @param result The result of a JPlag comparison. | ||
* @param path Path to the directory where the report should be saved. | ||
* @return True if the process is successful, otherwise false. | ||
*/ | ||
boolean saveReport(JPlagResult result, String path); | ||
void saveReport(JPlagResult result, String path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.