Просмотр исходного кода

adapt report viewer to normalized similarity value
adapt documentation and JSON field name

Jan Wittler 4 лет назад
Родитель
Сommit
f4a1792c09

+ 5 - 5
core/src/main/java/de/jplag/JPlagResult.java

@@ -26,7 +26,7 @@ public class JPlagResult {
     private final int SIMILARITY_DISTRIBUTION_SIZE = 10;
 
     public JPlagResult(List<JPlagComparison> comparisons, SubmissionSet submissions, long durationInMillis, JPlagOptions options) {
-        // sort comparisons by percentage (descending)
+        // sort by similarity (descending)
         this.comparisons = comparisons.stream().sorted((first, second) -> Double.compare(second.similarity(), first.similarity())).toList();
         this.submissions = submissions;
         this.durationInMillis = durationInMillis;
@@ -36,7 +36,7 @@ public class JPlagResult {
 
     /**
      * Drops elements from the comparison list to free memory. Note, that this affects the similarity distribution and is
-     * only meant to be used if you don't need the information about comparisons with lower match percentage anymore.
+     * only meant to be used if you don't need the information about comparisons with lower match similarity anymore.
      * @param limit the number of comparisons to keep in the list
      */
     public void dropComparisons(int limit) {
@@ -48,17 +48,17 @@ public class JPlagResult {
     }
 
     /**
-     * @return a list of all comparisons sorted by percentage (descending)
+     * @return a list of all comparisons sorted by similarity (descending)
      */
     public List<JPlagComparison> getAllComparisons() {
         return comparisons;
     }
 
     /**
-     * Returns the first n comparisons (sorted by percentage, descending), limited by the specified parameter.
+     * Returns the first n comparisons (sorted by similarity, descending), limited by the specified parameter.
      * @param numberOfComparisons specifies the number of requested comparisons. If set to -1, all comparisons will be
      * returned.
-     * @return a list of comparisons sorted descending by percentage.
+     * @return a list of comparisons sorted descending by similarity.
      */
     public List<JPlagComparison> getComparisons(int numberOfComparisons) {
         if (numberOfComparisons == JPlagOptions.SHOW_ALL_COMPARISONS) {

+ 1 - 1
core/src/main/java/de/jplag/options/JPlagOptions.java

@@ -36,7 +36,7 @@ import de.jplag.clustering.ClusteringOptions;
  * @param similarityMetric The similarity metric determines how the minimum similarity threshold required for a
  * comparison (of two submissions) is calculated. This affects which comparisons are stored and thus make it into the
  * result object.
- * @param similarityThreshold Percentage value (must be between 0 and 100). Comparisons (of submissions pairs) with a
+ * @param similarityThreshold Similarity value (must be between 0 and 1). Comparisons (of submissions pairs) with a
  * similarity below this threshold will be ignored. The default value of 0 allows all matches to be stored. This affects
  * which comparisons are stored and thus make it into the result object. See also {@link #similarityMetric()}.
  * @param maximumNumberOfComparisons The maximum number of comparisons that will be shown in the generated report. If

+ 2 - 2
core/src/main/java/de/jplag/options/SimilarityMetric.java

@@ -12,8 +12,8 @@ public enum SimilarityMetric implements ToDoubleFunction<JPlagComparison> {
 
     private final ToDoubleFunction<JPlagComparison> similarityFunction;
 
-    SimilarityMetric(ToDoubleFunction<JPlagComparison> determinePercentage) {
-        this.similarityFunction = determinePercentage;
+    SimilarityMetric(ToDoubleFunction<JPlagComparison> similarityFunction) {
+        this.similarityFunction = similarityFunction;
     }
 
     public boolean isAboveThreshold(JPlagComparison comparison, double similarityThreshold) {

+ 1 - 1
core/src/main/java/de/jplag/reporting/reportobject/model/TopComparison.java

@@ -3,5 +3,5 @@ package de.jplag.reporting.reportobject.model;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 public record TopComparison(@JsonProperty("first_submission") String firstSubmission, @JsonProperty("second_submission") String secondSubmission,
-        @JsonProperty("match_percentage") double matchPercentage) {
+        @JsonProperty("similarity") double similarity) {
 }

+ 1 - 1
core/src/test/java/de/jplag/special/VolumeTest.java

@@ -36,7 +36,7 @@ public class VolumeTest extends TestBase {
 
     /**
      * This test requires a folder "data" with submissions and a file named "matches_avg.csv" inside the volume folder.
-     * Accepts a derivation of 0.1% in the matching percentage
+     * Accepts a derivation of {@link #DELTA} in the matching similarity
      */
     @Test
     @Disabled

+ 6 - 6
report-viewer/src/components/ComparisonsTable.vue

@@ -15,7 +15,7 @@
       :key="
         comparison.firstSubmissionId +
         comparison.secondSubmissionId +
-        comparison.matchPercentage
+        comparison.similarity
       "
       class="selectable"
     >
@@ -81,7 +81,7 @@
           )
         "
       >
-        {{ formattedMatchPercentage(comparison.matchPercentage) }}
+        {{ formattedMatchPercentage(comparison.similarity) }}
       </td>
       <td>
         <img
@@ -144,7 +144,7 @@ export default defineComponent({
   },
   setup(props) {
     const store = useStore();
-    let formattedMatchPercentage = (num: number) => num.toFixed(2);
+    let formattedMatchPercentage = (num: number) => (num * 100).toFixed(2);
     const dialog: Ref<Array<boolean>> = ref([]);
     props.topComparisons.forEach(() => dialog.value.push(false));
     const displayName = (submissionId: string) =>
@@ -154,7 +154,7 @@ export default defineComponent({
       dialog.value[index] = true;
     };
 
-    const navigateToComparisonView = (firstId: string, secondId: string) => {
+    const navigateToComparisonView = (firstId : string, secondId: string) => {
       if (!store.state.single) {
         router.push({
           name: "ComparisonView",
@@ -185,7 +185,7 @@ export default defineComponent({
         ) {
           matches.push({
             matchedWith: comparison.secondSubmissionId,
-            percentage: comparison.matchPercentage,
+            percentage: comparison.similarity,
           });
         } else if (
           comparison.secondSubmissionId.includes(id) &&
@@ -193,7 +193,7 @@ export default defineComponent({
         ) {
           matches.push({
             matchedWith: comparison.firstSubmissionId,
-            percentage: comparison.matchPercentage,
+            percentage: comparison.similarity,
           });
         }
       });

+ 5 - 5
report-viewer/src/model/Comparison.ts

@@ -8,16 +8,16 @@ import { MatchInSingleFile } from "./MatchInSingleFile";
 export class Comparison {
   private readonly _firstSubmissionId: string;
   private readonly _secondSubmissionId: string;
-  private readonly _match_percentage: number;
+  private readonly _similarity: number;
 
   constructor(
     firstSubmissionId: string,
     secondSubmissionId: string,
-    match_percentage: number
+    similarity: number
   ) {
     this._firstSubmissionId = firstSubmissionId;
     this._secondSubmissionId = secondSubmissionId;
-    this._match_percentage = match_percentage;
+    this._similarity = similarity;
     this._filesOfFirstSubmission = new Map();
     this._filesOfSecondSubmission = new Map();
     this._colors = [];
@@ -94,7 +94,7 @@ export class Comparison {
     return this._secondSubmissionId;
   }
 
-  get match_percentage(): number {
-    return this._match_percentage;
+  get similarity(): number {
+    return this._similarity;
   }
 }

+ 1 - 1
report-viewer/src/model/ComparisonListElement.ts

@@ -5,5 +5,5 @@
 export type ComparisonListElement = {
     firstSubmissionId: string,
     secondSubmissionId: string,
-    matchPercentage: number
+    similarity: number
 }

+ 1 - 1
report-viewer/src/model/factories/OverviewFactory.ts

@@ -27,7 +27,7 @@ export class OverviewFactory {
           const comparison: ComparisonListElement = {
             firstSubmissionId: jsonComparison.first_submission as string,
             secondSubmissionId: jsonComparison.second_submission as string,
-            matchPercentage: jsonComparison.match_percentage as number,
+            similarity: jsonComparison.similarity as number,
           };
           comparisons.push(comparison);
         }

+ 1 - 1
report-viewer/src/views/ComparisonView.vue

@@ -31,7 +31,7 @@
         :value="store.getters.submissionDisplayName(secondId)"
         label="Submission 2"
       />
-      <TextInformation :value="comparison.match_percentage" label="Match %" />
+      <TextInformation :value="(comparison.similarity * 100).toFixed(2)" label="Match %" />
       <MatchTable
         :id1="firstId"
         :id2="secondId"