Skip to content

Commit

Permalink
Merge pull request #535 from nestabentum/optimize_reportViewer_dto_si…
Browse files Browse the repository at this point in the history
…ze_new_ready

Optimize report viewer dto size new
  • Loading branch information
tsaglam authored Aug 3, 2022
2 parents 0c569ae + 7315125 commit 8d28e95
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 408 deletions.
8 changes: 3 additions & 5 deletions jplag.cli/src/main/java/de/jplag/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import de.jplag.options.LanguageOption;
import de.jplag.options.SimilarityMetric;
import de.jplag.options.Verbosity;
import de.jplag.reporting.JsonReport;
import de.jplag.reporting.Report;
import de.jplag.reporting.reportobject.ReportObjectFactory;
import de.jplag.strategy.ComparisonMode;

/**
Expand Down Expand Up @@ -65,9 +64,8 @@ public static void main(String[] args) {
JPlag program = new JPlag(options);
logger.info("JPlag initialized");
JPlagResult result = program.run();
Report report = new JsonReport();
report.saveReport(result, arguments.getString(RESULT_FOLDER.flagWithoutDash()));
finalizeLogger();
ReportObjectFactory.createAndSaveReport(result, arguments.getString(RESULT_FOLDER.flagWithoutDash()));

} catch (ExitException exception) {
logger.error(exception.getMessage(), exception);
finalizeLogger();
Expand Down
12 changes: 9 additions & 3 deletions jplag/src/main/java/de/jplag/JPlagResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,15 @@ private int[] calculateSimilarityDistribution(List<JPlagComparison> comparisons)

private int[] calculateDistributionFor(List<JPlagComparison> comparisons, Function<JPlagComparison, Float> similarityExtractor) {
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]++);
int similarityDistributionBucketSize = 100 / SIMILARITY_DISTRIBUTION_SIZE;
for (JPlagComparison comparison : comparisons) {
float similarity = similarityExtractor.apply(comparison); // extract similarity in percent: 0f <= similarity <= 100f
int index = (int) (similarity / similarityDistributionBucketSize); // divide similarity by bucket size to find index of correct bucket.
index = Math.min(index, SIMILARITY_DISTRIBUTION_SIZE - 1);// index is out of bounds when similarity is 100%. decrease by one to count
// towards the highest value bucket
similarityDistribution[SIMILARITY_DISTRIBUTION_SIZE - 1 - index]++; // count comparison towards its determined bucket. bucket order is
// reversed, so that the highest value bucket has the lowest index
}
return similarityDistribution;
}
}
36 changes: 0 additions & 36 deletions jplag/src/main/java/de/jplag/reporting/JsonReport.java

This file was deleted.

34 changes: 0 additions & 34 deletions jplag/src/main/java/de/jplag/reporting/Report.java

This file was deleted.

29 changes: 29 additions & 0 deletions jplag/src/main/java/de/jplag/reporting/jsonfactory/FileWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.jplag.reporting.jsonfactory;

import java.io.IOException;
import java.nio.file.Path;

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

import com.fasterxml.jackson.databind.ObjectMapper;

public class FileWriter {
private static final Logger logger = LoggerFactory.getLogger(FileWriter.class);

private static final ObjectMapper objectMapper = new ObjectMapper();

/**
* Saves the provided object to the provided path under the provided name
* @param fileToSave The object to save
* @param folderPath The path to save the object to
* @param fileName The name to save the object under
*/
public void saveAsJSON(Object fileToSave, String folderPath, String fileName) {
try {
objectMapper.writeValue(Path.of(folderPath, fileName).toFile(), fileToSave);
} catch (IOException e) {
logger.error("Failed to save json file " + fileName + ": " + e.getMessage(), e);
}
}
}

This file was deleted.

Loading

0 comments on commit 8d28e95

Please sign in to comment.