Procházet zdrojové kódy

[192-webreport] Reintroduced file upload window, accepting zip, single json upload or local files

Evgeni před 4 roky
rodič
revize
083a6ae4b9

+ 8 - 5
report-viewer/src/components/ComparisonsTable.vue

@@ -31,6 +31,7 @@
 <script>
 import { defineComponent } from "vue";
 import router from "@/router";
+import store from "@/store/store";
 
 export default defineComponent({
   name: "ComparisonsTable",
@@ -43,14 +44,16 @@ export default defineComponent({
      type: Set
     }
   },
-  setup(props) {
+  setup() {
     let formattedMatchPercentage = ( number ) => number.toFixed(2)
 
     const navigateToComparisonView = (id1, id2) => {
-      router.push({
-        name: "ComparisonView",
-        query: {id1: id1, id2: id2},
-      })
+      if(!store.state.single) {
+        router.push({
+          name: "ComparisonView",
+          query: {id1: id1, id2: id2},
+        })
+      }
     }
     return {
       formattedMatchPercentage,

+ 10 - 2
report-viewer/src/components/IDsList.vue

@@ -32,9 +32,8 @@ export default defineComponent({
 
 <style scoped>
 button {
-  height: 25%;
   background: inherit;
-  font-family: "JetBrains Mono", serif;
+  font-weight: bold;
   border: none;
   border-radius: 10px;
 }
@@ -47,12 +46,21 @@ button:hover {
 .container {
   display: flex;
   justify-content: space-between;
+  background: inherit !important;
 }
 
 .column-list {
   display: flex;
   flex-direction: column;
   flex-wrap: nowrap;
+  width: 100%;
+  overflow-x: auto;
+}
+
+.column-list > p {
+  width: 100%;
+  font-weight: bold;
+  margin: 0;
 }
 
 .column-list > p:hover {

+ 103 - 0
report-viewer/src/files/overview.json

@@ -0,0 +1,103 @@
+{
+  "submission_folder_path": "C:\\Uni\\PISE\\JPlag\\jplag\\src\\test\\resources\\de\\jplag\\samples\\PartialPlagiarism",
+  "base_code_folder_path": "",
+  "language": "Javac 1.9+ based AST plugin",
+  "file_extensions": [
+    ".java",
+    ".JAVA"
+  ],
+  "submission_ids": [
+    "A",
+    "B",
+    "C",
+    "D",
+    "E"
+  ],
+  "failed_submission_names": [],
+  "excluded_files": [],
+  "match_sensitivity": 9,
+  "date_of_execution": "27/12/21",
+  "execution_time": 94,
+  "comparison_names": [
+    "C-A",
+    "D-A",
+    "D-C",
+    "B-D",
+    "B-A",
+    "B-C",
+    "E-A",
+    "E-B",
+    "E-C",
+    "E-D"
+  ],
+  "metrics": [
+    {
+      "name": "AVG",
+      "threshold": 0.0,
+      "distribution": [
+        4,
+        0,
+        3,
+        0,
+        0,
+        0,
+        0,
+        2,
+        0,
+        1
+      ],
+      "topComparisons": [
+        {
+          "first_submission": "C",
+          "second_submission": "A",
+          "match_percentage": 99.6633
+        },
+        {
+          "first_submission": "D",
+          "second_submission": "A",
+          "match_percentage": 77.87255
+        },
+        {
+          "first_submission": "D",
+          "second_submission": "C",
+          "match_percentage": 77.87255
+        },
+        {
+          "first_submission": "B",
+          "second_submission": "D",
+          "match_percentage": 28.278688
+        },
+        {
+          "first_submission": "B",
+          "second_submission": "A",
+          "match_percentage": 24.576895
+        },
+        {
+          "first_submission": "B",
+          "second_submission": "C",
+          "match_percentage": 24.576895
+        },
+        {
+          "first_submission": "E",
+          "second_submission": "A",
+          "match_percentage": 0.0
+        },
+        {
+          "first_submission": "E",
+          "second_submission": "B",
+          "match_percentage": 0.0
+        },
+        {
+          "first_submission": "E",
+          "second_submission": "C",
+          "match_percentage": 0.0
+        },
+        {
+          "first_submission": "E",
+          "second_submission": "D",
+          "match_percentage": 0.0
+        }
+      ]
+    }
+  ]
+}

+ 4 - 2
report-viewer/src/router/index.ts

@@ -13,13 +13,15 @@ const routes: Array<RouteRecordRaw> = [
     path: "/overview",
     name: "Overview",
     component: Overview,
-    props:true
   },
   {
     path: "/comparison",
     name: "ComparisonView",
     component: ComparisonView,
-    props: route => ({ notAnonymized : route.params.notAnonymized, id1: route.query.id1, id2: route.query.id2})
+    props: route => ({
+      id1: route.query.id1,
+      id2: route.query.id2
+    })
   },
 ];
 

+ 13 - 3
report-viewer/src/store/store.ts

@@ -4,7 +4,11 @@ const store = createStore({
     state () {
         return {
             anonymous : new Set(),
-            files: Array
+            files : Object,
+            local: Boolean,
+            zip: Boolean,
+            single: Boolean,
+            fileString: String
         }
     },
     getters: {
@@ -26,8 +30,14 @@ const store = createStore({
         resetAnonymous (state) {
             state.anonymous = new Set()
         },
-        saveFiles (state, files) {
-            state.files = files
+        saveFile (state, file: Record<string, any>) {
+            state.files[file.fileName] = file.data
+        },
+        setLoadingType (state, payload: Record<string, any>) {
+            state.local = payload.local
+            state.zip = payload.zip
+            state.single = payload.single
+            state.fileString = payload.fileString
         }
 
     }

+ 11 - 0
report-viewer/src/utils/Utils.ts

@@ -16,4 +16,15 @@ export function generateColoringArray(array: Array<Record<string, unknown>>, fil
         default:
             return []
     }
+}
+
+export function isTrue(str: string): boolean {
+    return str === "true";
+}
+
+export function getFileExtension(file: File): string {
+    if(file.name.includes(".")) {
+        return file.name.split(".")[1]
+    }
+    return "";
 }

+ 9 - 3
report-viewer/src/views/ComparisonView.vue

@@ -47,9 +47,15 @@ export default defineComponent({
   },
   setup(props) {
     const fileName = props.id1.concat("-").concat(props.id2)
-    // eslint-disable-next-line @typescript-eslint/no-var-requires
-    const json = require(`../files/${fileName}.json`)
-    const comparison = ComparisonFactory.getComparison(json)
+    let comparison;
+    if(store.state.local) {
+      // eslint-disable-next-line @typescript-eslint/no-var-requires
+      comparison = ComparisonFactory.getComparison(require(`../files/${fileName}.json`))
+    } else if(store.state.zip) {
+      comparison = ComparisonFactory.getComparison(JSON.parse(store.state.files[fileName.concat(".json")]))
+    } else if(store.state.single) {
+      comparison = ComparisonFactory.getComparison(JSON.parse(store.state.fileString))
+    }
 
     const filesOfFirst = ref(comparison.filesOfFirstSubmission)
     const filesOfSecond = ref(comparison.filesOfSecondSubmission)

+ 90 - 23
report-viewer/src/views/FileUpload.vue

@@ -2,41 +2,77 @@
   <div class="container" @dragover.prevent @drop.prevent>
     <img src="@/assets/logo-nobg.png" alt="JPlag"/>
     <h1>JPlag Report Viewer</h1>
-    <h2>Select an overview or comparison file to display.</h2>
+    <h2>Select an overview or comparison file or a zip to display.</h2>
     <div class="drop-container" @drop="uploadFile">
-      <p> Drop a .json file here</p>
+      <p> Drop a .json or .zip file here</p>
+    </div>
+    <div v-if="hasLocalFile" class="local-files-container">
+      <p class="local-files-text">Detected local files!</p>
+      <button class="local-files-button" @click="continueWithLocal">Continue with local files</button>
     </div>
-    <label for="browse">Or browse for a .json file</label>
-    <input type="file" id="browse" name="browse">
   </div>
 </template>
 
 <script>
 import { defineComponent } from "vue";
-import { fs } from "fs";
-import { jszip } from "jszip"
+import jszip from "jszip"
 import router from "@/router";
 import store from "@/store/store";
+import { getFileExtension } from "@/utils/Utils";
 
 export default defineComponent({
   name: "FileUpload",
   setup() {
-
-    const navigateToOverview = (file) => {
+    let hasLocalFile;
+    try {
+      require("../files/overview.json")
+      hasLocalFile = true
+    } catch(e) {
+      console.log(e)
+      hasLocalFile = false
+    }
+    const navigateToOverview = () => {
       router.push({
-            name: "OverviewV2",
-            params: {str: file},
+            name: "Overview",
           }
       )
     }
 
-    const navigateToComparisonView = (file) => {
+    const navigateToComparisonView = (id1, id2) => {
       router.push({
         name: "ComparisonView",
-        params: {str: file}
+        query: {
+          id1: id1,
+          id2: id2
+        }
       })
     }
 
+    const handleZipFile = (file) => {
+      jszip.loadAsync(file).then( async (zip) => {
+        for (const fileName of Object.keys(zip.files)) {
+          console.log(fileName)
+          await zip.files[fileName].async("string").then(data => {
+                store.commit("saveFile", {fileName: fileName, data: data})
+              }
+          )
+        }
+        store.commit("setLoadingType", {local: false, zip: true, single: false, fileString: ""})
+        navigateToOverview()
+      })
+    }
+
+    const handleJsonFile = (str) => {
+      let json = JSON.parse(str)
+      if(json["submission_folder_path"]) {
+        store.commit("setLoadingType", {local: false, zip: false, single: true, fileString: str})
+        navigateToOverview()
+      } else if(json["first_submission_id"] && json["second_submission_id"]) {
+        store.commit("setLoadingType", {local: false, zip: false, single: true, fileString: str})
+        navigateToComparisonView(json["first_submission_id"], json["second_submission_id"] )
+      }
+    }
+
     const uploadFile = (e) => {
       let dropped = e.dataTransfer.files
       if (!dropped) return
@@ -44,20 +80,24 @@ export default defineComponent({
       if (files.length > 1 || files.length === 0) return
       let read = new FileReader()
       read.onload = (e) => {
-        store.commit("saveFiles", files)
-        fs.readFile(files[0], (err, data) => {
-          console.log(data.name)
-        })
-        /*if(files[0].name.includes("comparison")) {
-          navigateToComparisonView(e.target.result)
-        } else {
-          navigateToOverview(e.target.result)
-        }*/
+        let extension = getFileExtension(files[0])
+        if(extension === "zip") {
+          handleZipFile(files[0])
+        } else if (extension === "json") {
+          handleJsonFile(e.target.result)
+        }
       }
       read.readAsText(files[0])
     }
+
+    const continueWithLocal = () => {
+      store.commit("setLoadingType", {local: true, zip: false, single: false, fileString: ""})
+      navigateToOverview()
+    }
     return {
-      uploadFile
+      continueWithLocal,
+      uploadFile,
+      hasLocalFile
     }
   }
 })
@@ -71,7 +111,7 @@ export default defineComponent({
   justify-content: center;
   width: 100%;
   height: 100%;
-  background: linear-gradient(to right, #FF5353,#ECECEC, #ECECEC);
+  background: var(--primary-color-light);
 }
 
 .drop-container {
@@ -88,6 +128,33 @@ export default defineComponent({
   text-align: center;
 }
 
+.local-files-container {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+
+.local-files-text {
+  font-weight: bold;
+  color: var(--on-background-color);
+}
+
+.local-files-button {
+  font-size: large;
+  background: var(--primary-color);
+  color: var(--on-primary-color);
+  font-weight: bold;
+  padding: 5%;
+  border: none;
+  border-radius: 10px;
+  box-shadow: var(--shadow-color) 2px 3px 3px;
+}
+
+.local-files-button:hover {
+  cursor: pointer;
+  background: var(--primary-color-dark);
+}
+
 input {
   display: none;
 }

+ 33 - 26
report-viewer/src/views/Overview.vue

@@ -37,7 +37,6 @@
       </div>
     <div class="column-container" style="width: 35%">
         <p class="section-title">Top Comparisons:</p>
-        <p class="section-subtitle">(Top n comparisons)</p>
         <div id="comparisonsList">
           <ComparisonsTable :top-comparisons="topComps[selectedMetricIndex]" :anonymous="store.state.anonymous"/>
         </div>
@@ -48,10 +47,10 @@
 <script>
 import {defineComponent, ref} from "vue";
 import store from "@/store/store";
+import router from "@/router";
 import TextInformation from "../components/TextInformation";
 import DistributionDiagram from "@/components/DistributionDiagram";
 import MetricButton from "@/components/MetricButton";
-import Overview from "../files/overview.json"
 import ComparisonsTable from "@/components/ComparisonsTable";
 import {OverviewFactory} from "@/model/factories/OverviewFactory";
 import IDsList from "@/components/IDsList";
@@ -59,48 +58,63 @@ import IDsList from "@/components/IDsList";
 export default defineComponent({
   name: "Overview",
   components: {IDsList, ComparisonsTable, DistributionDiagram, MetricButton, TextInformation },
-  props: {
-  },
   setup() {
-    const overview = OverviewFactory.getOverview(Overview)
+    let overview;
+    if (store.state.local) {
+      try {
+        // eslint-disable-next-line @typescript-eslint/no-var-requires
+        overview = OverviewFactory.getOverview(require("../files/overview.json"))
+      } catch (e) {
+        console.log(e)
+        router.back()
+      }
+    } else if (store.state.zip) {
+      console.log(store.state.files["overview.json"])
+      overview = OverviewFactory.getOverview(JSON.parse(store.state.files["overview.json"]))
+    } else if (store.state.single) {
+      overview = OverviewFactory.getOverview(JSON.parse(store.state.fileString))
+    }
+
 
     const handleId = (id) => {
-      if( id.length === overview.submissionIds.length) {
-        if(store.state.anonymous.size > 0) {
+      if (id.length === overview.submissionIds.length) {
+        if (store.state.anonymous.size > 0) {
           store.commit("resetAnonymous")
         } else {
           store.commit("addAnonymous", id)
         }
       } else {
-          if (store.state.anonymous.has(id[0])) {
-            store.commit("removeAnonymous", id)
+        if (store.state.anonymous.has(id[0])) {
+          store.commit("removeAnonymous", id)
+        } else {
+          if (store.state.anonymous.size === 0) {
+            store.commit("addAnonymous", overview.submissionIds.filter(s => s !== id[0]))
           } else {
-            if(store.state.anonymous.size === 0) {
-              store.commit("addAnonymous", overview.submissionIds.filter(s => s !== id[0]))
-            } else  {
-              store.commit("addAnonymous", id)
-            }
+            store.commit("addAnonymous", id)
           }
+        }
       }
     }
 
 
     //Metrics
-    let selectedMetric = ref(overview.metrics.map( () => false ))
+    let selectedMetric = ref(overview.metrics.map(() => false))
     let selectedMetricIndex = ref(0)
     selectedMetric.value[0] = true;
-    
+
     const selectMetric = (metric) => {
-      selectedMetric.value = selectedMetric.value.map( () => { return false })
+      selectedMetric.value = selectedMetric.value.map(() => {
+        return false
+      })
       selectedMetric.value[metric] = true
       selectedMetricIndex.value = metric
     }
 
     //Distribution
-    let distributions = ref(overview.metrics.map( (m) =>  m.distribution ))
+    let distributions = ref(overview.metrics.map((m) => m.distribution))
 
     //Top Comparisons
-    let topComps = ref(overview.metrics.map((m) => m.comparisons ))
+    let topComps = ref(overview.metrics.map((m) => m.comparisons))
 
 
     return {
@@ -161,13 +175,6 @@ hr {
   color: var(--on-background-color);
 }
 
-.section-subtitle {
-  font-size: small;
-  text-align: start;
-  margin-top: 0;
-}
-
-
 #basicInfo {
   display: flex;
   flex-direction: column;