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

[192-webreport] Added dialogs to display clusters and clusterdiagram, started vue doc

Evgeni 4 лет назад
Родитель
Сommit
b16ee1e8f0

+ 15 - 0
report-viewer/package-lock.json

@@ -11,6 +11,7 @@
         "chart.js": "^3.6.0",
         "chartjs-plugin-datalabels": "^2.0.0",
         "core-js": "^3.6.5",
+        "gitart-vue-dialog": "^1.2.3",
         "highlight.js": "^11.4.0",
         "jszip": "^3.7.1",
         "vue": "^3.0.0",
@@ -8453,6 +8454,14 @@
         "assert-plus": "^1.0.0"
       }
     },
+    "node_modules/gitart-vue-dialog": {
+      "version": "1.2.3",
+      "resolved": "https://registry.npmjs.org/gitart-vue-dialog/-/gitart-vue-dialog-1.2.3.tgz",
+      "integrity": "sha512-xwaELtjly7DxRuo+N1Jp/SdqhwHpC+7qKLTdvOHMeqh0EPx2y/oUowAELjtfRVMTsYgs/pvNLH84E2N3SCwIZA==",
+      "peerDependencies": {
+        "vue": "^3.2.6"
+      }
+    },
     "node_modules/glob": {
       "version": "7.2.0",
       "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
@@ -24265,6 +24274,12 @@
         "assert-plus": "^1.0.0"
       }
     },
+    "gitart-vue-dialog": {
+      "version": "1.2.3",
+      "resolved": "https://registry.npmjs.org/gitart-vue-dialog/-/gitart-vue-dialog-1.2.3.tgz",
+      "integrity": "sha512-xwaELtjly7DxRuo+N1Jp/SdqhwHpC+7qKLTdvOHMeqh0EPx2y/oUowAELjtfRVMTsYgs/pvNLH84E2N3SCwIZA==",
+      "requires": {}
+    },
     "glob": {
       "version": "7.2.0",
       "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",

+ 1 - 0
report-viewer/package.json

@@ -12,6 +12,7 @@
     "chart.js": "^3.6.0",
     "chartjs-plugin-datalabels": "^2.0.0",
     "core-js": "^3.6.5",
+    "gitart-vue-dialog": "^1.2.3",
     "highlight.js": "^11.4.0",
     "jszip": "^3.7.1",
     "vue": "^3.0.0",

+ 101 - 0
report-viewer/src/components/ClusterRadarChart.vue

@@ -0,0 +1,101 @@
+<template>
+<div class="wrapper">
+  <select v-model="selectedMember">
+    <option v-for="(member, index) in Object.keys(cluster.members)" :key="index">{{ member }}</option>
+  </select>
+  <RadarChart class="chart" :chartData="chartData" :options="options"></RadarChart>
+</div>
+</template>
+
+<script>
+import { defineComponent, ref, watch } from "vue";
+import { RadarChart } from "vue-chart-3"
+import { Chart, registerables } from 'chart.js';
+import ChartDataLabels from 'chartjs-plugin-datalabels';
+Chart.register(...registerables);
+Chart.register(ChartDataLabels);
+
+export default defineComponent({
+  name: "ClusterRadarChart",
+  components: { RadarChart },
+  props: {
+    cluster: {}
+  },
+  setup(props) {
+    const selectedMember = ref("")
+    const labels = ref([])
+
+    const createLabelsFor = (member) => {
+      let matchedWith = []
+      props.cluster.members[member].forEach( m => matchedWith.push(m.matchedWith))
+      return matchedWith
+    }
+    const createDataSetFor = (member) => {
+      let data = []
+      props.cluster.members[member].forEach( m => data.push(m.percentage))
+      return data
+    }
+
+    const chartData = ref({
+      labels: createLabelsFor(Object.keys(props.cluster.members)[0]),
+      datasets: [{
+        label: Object.keys(props.cluster.members)[0],
+        data: createDataSetFor(Object.keys(props.cluster.members)[0]),
+        fill: true,
+        backgroundColor: 'rgba(149, 168, 241, 0.5)',
+        borderColor: 'rgba(149, 168, 241, 1)',
+        pointBackgroundColor: 'rgba(149, 168, 241, 1)',
+        pointBorderColor: '#fff',
+        pointHoverBackgroundColor: '#fff',
+        pointHoverBorderColor: 'rgb(255, 99, 132)'
+      }]
+    })
+
+    const options = ref({
+      scales: { r: {
+          suggestedMin: 50,
+          suggestedMax: 100
+        }
+      }
+    })
+
+    watch( () => selectedMember.value, (val) => {
+      console.log("Selected member is " + val)
+      console.log(JSON.stringify(createLabelsFor(val)))
+      chartData.value = {
+        labels: createLabelsFor(val),
+        datasets: [{
+          label: val,
+          data: createDataSetFor(val),
+          fill: true,
+          backgroundColor: 'rgba(149, 168, 241, 0.5)',
+          borderColor: 'rgba(149, 168, 241, 1)',
+          pointBackgroundColor: 'rgba(149, 168, 241, 1)',
+          pointBorderColor: '#fff',
+          pointHoverBackgroundColor: '#fff',
+          pointHoverBorderColor: 'rgb(255, 99, 132)'
+        }]
+      }
+    })
+
+    return {
+      selectedMember,
+      chartData,
+      options
+    }
+  }
+})
+</script>
+
+<style scoped>
+.wrapper {
+  display: flex;
+  flex-direction: column;
+  flex-wrap: nowrap;
+
+}
+
+.chart {
+  height: 50vw;
+}
+</style>

+ 61 - 0
report-viewer/src/components/ClustersList.vue

@@ -0,0 +1,61 @@
+<template>
+  <div class="wrapper">
+  <h1>Clusters for comparison {{ comparison.firstSubmissionId }} > {{ comparison.secondSubmissionId}}</h1>
+  <p v-for="( cluster, index ) in clusters" :key="index" @click="toggleDialog">
+    {{index}} - {{cluster.avgSim}}
+    <GDialog v-model="dialog" fullscreen>
+      <button @click="toggleDialog">Close</button>
+      <ClusterRadarChart :cluster="cluster"></ClusterRadarChart>
+    </GDialog>
+  </p>
+  </div>
+</template>
+
+<script>
+import  { defineComponent, ref } from "vue";
+import { GDialog } from "gitart-vue-dialog";
+import ClusterRadarChart from "@/components/ClusterRadarChart";
+
+export default defineComponent({
+  name: "ClustersList",
+  components: {ClusterRadarChart, GDialog },
+  props: {
+    comparison: {},
+    clusters: Array
+  },
+  setup() {
+    const dialog = ref(false)
+    const toggleDialog = () => dialog.value = !dialog.value
+    return {
+      dialog,
+      toggleDialog
+    }
+  }
+})
+</script>
+
+<style scoped>
+.wrapper {
+  display: flex;
+  flex-direction: column;
+  padding: 1%;
+  background: var(--background-color);
+  font-family: Avenir, Helvetica, Arial, sans-serif;
+  color: var(--on-primary-color);
+}
+
+p {
+  font-family: inherit;
+  font-weight: bold;
+  border-radius: 10px;
+  background: var(--primary-color-light);
+  box-shadow: var(--shadow-color) 3px 3px 2px;
+  padding: 1%;
+}
+
+p:hover {
+  background: var(--primary-color-dark);
+  cursor: pointer;
+}
+
+</style>

+ 63 - 1
report-viewer/src/components/CodePanel.vue

@@ -25,48 +25,110 @@
 <script>
 import {ref, defineComponent} from "vue";
 import LineOfCode from "./LineOfCode";
-
 export default defineComponent({
   name: "CodePanel",
   components: {LineOfCode},
   props: {
+    /**
+     * Title of the displayed file.
+     */
     title: {
       type: String,
     },
+    /**
+     * Index of file amongst other files in submission.
+     */
     fileIndex: {
       type: Number
     },
+    /**
+     * Code lines of the file.
+     * type: Array<string>
+     */
     lines: {
       type: Array,
       required: true
     },
+    /**
+     * Matches in the file
+     * type: Array<MatchInSingleFile>
+     */
     matches: {
       type: Array
     },
+    /**
+     * Id of the FilesContainer. Needed for lines link generation.
+     */
     panelId: {
       type: Number
     },
+    /**
+     * Indicates whether files is collapsed or not.
+     */
     collapse: {
       type: Boolean
     }
   },
   setup(props) {
+    /**
+     * An object containing the color of each line in code. Keys are line numbers, values are their color.
+     * Example: {
+     *   ...
+     *   100 : "#3333"
+     *   101 : "#3333"
+     *   102 : "#3333"
+     *   103 : "#FFFF"
+     *   ...
+     * }
+     * @type {Ref<UnwrapRef<{}>>}
+     */
     const coloringArray = ref({})
+    /**
+     * An object containing an object from which an id is to of the line to which this is linked is constructed.
+     * Id object contains panel, file name, first line number of linked matched.
+     * Example: {
+     *   panel: 1,
+     *   file: "Example.java",
+     *   line: 121
+     * }
+     * Constructed ID (generateLineCodeLink from Utils.ts): 1Example.java121
+     * When a line is clicked it uses this link id
+     * to scroll into vie the linked line in the linked file of the other submission.
+     * Key is line number, value is id of linked line.
+     * @type {Ref<UnwrapRef<{}>>}
+     */
     const linksArray = ref({})
+    /**
+     * Indicates whether the line is last line of match. Key is line number, value is true or false.
+     * @type {Ref<UnwrapRef<{}>>}
+     */
     const isLast = ref({})
+    /**
+     * Indicates whether the line is the first line of a match. Key is line number, value is true or false.
+     * @type {Ref<UnwrapRef<{}>>}
+     */
     const isFirst = ref({})
+
+    /**
+     * Initializing the the upper arrays.
+     */
     props.matches.forEach(m => {
       for (let i = m.start; i <= m.end; i++) {
+        //assign match color to line
         coloringArray.value[i] = m.color
+        //assign link object to line.
         linksArray.value[i] = { panel : m.linked_panel, file : m.linked_file, line : m.linked_line }
+        //check whether line is start of match and assign true if yes
         if(i === m.start) {
           isFirst.value[i] = true
         }
+        //check whether line is end of match and assign true if yes
         if(i === m.end) {
           isLast.value[i] = true
         }
       }
     })
+    //assign default values for all line which are not contained in matches
     for(let i = 0; i < props.lines.length; i++) {
       if(!coloringArray.value[i]) {
         coloringArray.value[i] = "#FFFFFF"

+ 83 - 11
report-viewer/src/components/ComparisonsTable.vue

@@ -13,39 +13,62 @@
             + comparison.matchPercentage"
       :class="{ 'even-row' : index % 2 === 0, 'odd-row' : index % 2 !== 0 }"
       class="selectable"
-      @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)"
       >
-    <td>{{ index + 1 }}.</td>
-    <td :class="{ 'anonymous-style' : anonymous.has(comparison.firstSubmissionId)}">
-      {{ anonymous.has(comparison.firstSubmissionId) ? "Hidden" : comparison.firstSubmissionId  }}
+
+    <td  @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)">{{ index + 1 }}.</td>
+    <td :class="{ 'anonymous-style' : isAnonymous(comparison.firstSubmissionId)}"
+        @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)">
+      {{ isAnonymous(comparison.firstSubmissionId) ? "Hidden" : comparison.firstSubmissionId  }}
+    </td>
+    <td
+        @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)">
+      <img src="@/assets/double_arrow_black_18dp.svg" alt=">>"/>
     </td>
-    <td><img src="@/assets/double_arrow_black_18dp.svg" alt=">>"/></td>
-    <td :class="{ 'anonymous-style' : anonymous.has(comparison.secondSubmissionId)}">
-      {{ anonymous.has(comparison.secondSubmissionId) ? "Hidden" : comparison.secondSubmissionId }}
+    <td :class="{ 'anonymous-style' : isAnonymous(comparison.secondSubmissionId)}"
+        @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)">
+      {{ isAnonymous(comparison.secondSubmissionId) ? "Hidden" : comparison.secondSubmissionId }}
     </td>
     <td>{{ formattedMatchPercentage(comparison.matchPercentage) }}</td>
+    <td>
+      <img v-if="isInCluster(comparison.firstSubmissionId, comparison.secondSubmissionId)"
+           src="@/assets/keyboard_double_arrow_down_black_18dp.svg"
+           alt=">>"
+           @click="toggleDialog"
+      />
+    </td>
+    <GDialog v-model="dialog">
+      <ClustersList :clusters="getClustersFor(comparison.firstSubmissionId, comparison.secondSubmissionId)" :comparison="comparison"/>
+    </GDialog>
   </tr>
 </table>
 </template>
 
 <script>
-import { defineComponent } from "vue";
+import {defineComponent, ref} from "vue";
 import router from "@/router";
 import store from "@/store/store";
+import { GDialog } from "gitart-vue-dialog";
+import ClustersList from "@/components/ClustersList";
 
 export default defineComponent({
   name: "ComparisonsTable",
+  components: {ClustersList, GDialog },
   props: {
    topComparisons : {
      type: Array,
      required: true
    },
-    anonymous : {
-     type: Set
+    clusters : {
+     type: Array
     }
   },
-  setup() {
+  setup(props) {
     let formattedMatchPercentage = ( number ) => number.toFixed(2)
+    const dialog = ref(false)
+
+    const toggleDialog = () => {
+      dialog.value = true
+    }
 
     const navigateToComparisonView = (id1, id2) => {
       if(!store.state.single) {
@@ -55,9 +78,58 @@ export default defineComponent({
         })
       }
     }
+
+    const isInCluster = (id1, id2) => {
+      return props.clusters.some( c => c.members.includes(id1) && c.members.includes(id2))
+    }
+
+    const isAnonymous = (id) => {
+      return store.state.anonymous.has(id)
+    }
+
+
+    const getParticipatingMatchesForId = (id, others) => {
+      let matches = []
+      props.topComparisons.forEach( comparison => {
+        if(comparison.firstSubmissionId.includes(id)  && others.includes(comparison.secondSubmissionId)) {
+          console.log("Pushing")
+          matches.push({ matchedWith: comparison.secondSubmissionId, percentage: comparison.matchPercentage})
+        } else if ( comparison.secondSubmissionId.includes(id) && others.includes(comparison.firstSubmissionId)) {
+          console.log("Pushing")
+          matches.push({ matchedWith: comparison.firstSubmissionId, percentage: comparison.matchPercentage})
+        }
+      })
+      return matches;
+    }
+
+    const clustersWithParticipatingMatches = props.clusters.map( cluster => {
+      let membersArray = {}
+      cluster.members.forEach( member => {
+        let others = cluster.members.filter(m => !m.includes(member))
+        membersArray[member] = getParticipatingMatchesForId(member, others)
+      })
+
+      return {
+        avgSim: cluster.avgSim,
+        members: membersArray
+      }
+    })
+
+    const getClustersFor = (id1, id2) => {
+      return clustersWithParticipatingMatches.filter( c => Object.keys(c.members).includes(id1) &&
+                                                                Object.keys(c.members).includes(id2))
+    }
+
     return {
+      clustersWithParticipatingMatches,
+      dialog,
+
+      isAnonymous,
+      getClustersFor,
+      toggleDialog,
       formattedMatchPercentage,
       navigateToComparisonView,
+      isInCluster
     }
   }
 })

+ 8 - 3
report-viewer/src/components/DistributionDiagram.vue

@@ -22,7 +22,10 @@ export default defineComponent({
     }
   },
   setup(props) {
+    //Highest count of submissions in a percentage range. We set the diagrams maximum shown value to maxVal + 5,
+    //otherwise maximum is set to the highest count of submissions and is one bar always reaches the end.
     let maxVal = ref(Math.max(...props.distribution));
+
     let chartData = ref( {
         labels: ['0-10%', '11-20%', '21-30%', '31-40%', '41-50%', '51-60%', '61-70%', '71-80%', '81-90%', '91-100%'],
         datasets: [{
@@ -68,6 +71,8 @@ export default defineComponent({
       }
     })
 
+    //We watch the given distributions parameter. When the distribution of another metric is passed, the diagram is
+    //updated with the new data.
     watch( () => props.distribution, (val) => {
       chartData.value = {
         labels: ['0-10%', '11-20%', '21-30%', '31-40%', '41-50%', '51-60%', '61-70%', '71-80%', '81-90%', '91-100%'],
@@ -89,18 +94,18 @@ export default defineComponent({
           x: {
             suggestedMax: maxVal.value + 5,
             ticks: {
-              color: '#860000',
+              color: '#000000',
             }
           },
           y: {
             ticks: {
-              color: '#860000',
+              color: '#000000',
             }
           }
         },
         plugins: {
           datalabels: {
-            color: '#be1523',
+            color: '#000000',
             font: {
               weight: 'bold'
             },

+ 4 - 3
report-viewer/src/components/LineOfCode.vue

@@ -11,6 +11,9 @@ import hljs from 'highlight.js';
 export default defineComponent({
   name: "LineOfCode",
   props: {
+    /**
+     * Indicates whether the line is shown on screen. Used for highlighting on demand.
+     */
     visible: {
       type: Boolean,
       required: true
@@ -26,9 +29,6 @@ export default defineComponent({
     color: {
       required:true
     },
-    startOfMatch: {
-      type: Number
-    },
     fileIndex: {
       type: Number,
     },
@@ -43,6 +43,7 @@ export default defineComponent({
   setup(props) {
     let highlighted = false
     let lineRef = ref(null)
+    //Trigger highlighting when code panel is collapsed.
     onUpdated( () => {
       if ( props.visible && !highlighted ) {
           hljs.highlightElement(lineRef.value)

+ 1 - 1
report-viewer/src/components/TextInformation.vue

@@ -2,7 +2,7 @@
   <div class="wrapper">
       <div class="text-container">
       <p class="label-text">{{ label }}</p>
-      <p :class="{ anonymous : anonymous }" class="value-text" :title="anonymous ? '' : value">{{ anonymous ? "Hidden" : value }}</p>
+      <p :class="{ 'anonymous' : anonymous }" class="value-text" :title="anonymous ? '' : value">{{ anonymous ? "Hidden" : value }}</p>
       </div>
       <button class="collapse-button" :class="{ hidden : !hasAdditionalInfo }" @click="toggleIsCollapsed">
         <img v-if="isCollapsed" src="../assets/keyboard_double_arrow_up_black_18dp.svg" alt="hide info">

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

@@ -99,5 +99,15 @@
         }
       ]
     }
+  ],
+  "clusters": [
+    {
+      "avgSim": 30,
+      "members": ["A", "B", "C"]
+    },
+    {
+      "avgSim": 80,
+      "members": ["A", "B", "D", "E"]
+    }
   ]
 }

+ 1 - 0
report-viewer/src/main.ts

@@ -3,6 +3,7 @@ import App from "./App.vue";
 import router from "./router";
 import store from "./store/store"
 import './libs/highlightjs/styles/edited/vs.min.css'
+import 'gitart-vue-dialog/dist/style.css'
 import 'highlight.js/lib/common';
 
 

+ 4 - 0
report-viewer/src/model/Cluster.ts

@@ -0,0 +1,4 @@
+export type Cluster = {
+    avgSim: number,
+    members: Array<string>
+}

+ 8 - 1
report-viewer/src/model/Overview.ts

@@ -1,4 +1,5 @@
 import {Metric} from "./Metric";
+import {Cluster} from "@/model/Cluster";
 
 export class Overview {
     private readonly _submissionFolderPath: string
@@ -10,9 +11,10 @@ export class Overview {
     private readonly _dateOfExecution: string
     private readonly _durationOfExecution: number
     private readonly _metrics: Array<Metric>
+    private readonly _clusters: Array<Cluster>
 
 
-    constructor(submissionFolderPath: string, baseCodeFolderPath: string, language: string, fileExtensions: Array<string>,matchSensitivity: number, submissionIds: Array<string>, dateOfExecution: string, durationOfExecution: number, metrics: Array<Metric>) {
+    constructor(submissionFolderPath: string, baseCodeFolderPath: string, language: string, fileExtensions: Array<string>,matchSensitivity: number, submissionIds: Array<string>, dateOfExecution: string, durationOfExecution: number, metrics: Array<Metric>, clusters: Array<Cluster>) {
         this._submissionFolderPath = submissionFolderPath;
         this._baseCodeFolderPath = baseCodeFolderPath;
         this._language = language;
@@ -22,6 +24,7 @@ export class Overview {
         this._dateOfExecution = dateOfExecution;
         this._durationOfExecution = durationOfExecution;
         this._metrics = metrics;
+        this._clusters = clusters
     }
 
 
@@ -60,4 +63,8 @@ export class Overview {
     get metrics(): Array<Metric> {
         return this._metrics;
     }
+
+    get clusters(): Array<Cluster> {
+        return this._clusters
+    }
 }

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

@@ -1,6 +1,7 @@
 import {Overview} from "../Overview";
 import {Metric} from "../Metric";
 import {ComparisonListElement} from "../ComparisonListElement";
+import {Cluster} from "@/model/Cluster";
 
 export class OverviewFactory {
 
@@ -14,6 +15,7 @@ export class OverviewFactory {
         const dateOfExecution = json.date_of_execution as string
         const duration = json.execution_time as number as number
         const metrics = [] as Array<Metric>
+        const clusters = [] as Array<Cluster>
         (json.metrics as Array<unknown>).forEach( (m) => {
             const metric = m as Record<string, unknown>
             const comparisons = [] as Array<ComparisonListElement>
@@ -34,8 +36,18 @@ export class OverviewFactory {
                 comparisons : comparisons
             }
             metrics.push(newMetric)
+        });
+
+        (json.clusters as Array<unknown>).forEach( c => {
+            const cluster = c as Record<string, unknown>
+            const newCluster : Cluster = {
+                avgSim: cluster.avgSim as number,
+                members: cluster.members as Array<string>
+            }
+            clusters.push(newCluster)
         })
 
+
         return new Overview(
             submissionFolder,
             baseCodeFolder,
@@ -45,7 +57,8 @@ export class OverviewFactory {
             submissions,
             dateOfExecution,
             duration,
-            metrics
+            metrics,
+            clusters
         )
     }
 }

+ 1 - 4
report-viewer/src/views/Overview.vue

@@ -38,7 +38,7 @@
     <div class="column-container" style="width: 35%">
         <p class="section-title">Top Comparisons:</p>
         <div id="comparisonsList">
-          <ComparisonsTable :top-comparisons="topComps[selectedMetricIndex]" :anonymous="store.state.anonymous"/>
+          <ComparisonsTable :top-comparisons="topComps[selectedMetricIndex]" :clusters="overview.clusters"/>
         </div>
     </div>
   </div>
@@ -65,17 +65,14 @@ export default defineComponent({
         // 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) {