ComparisonsTable.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <!--
  2. Table which display all of the comparisons with their participating ids and similarity percentage for the selected metric.
  3. -->
  4. <template>
  5. <table>
  6. <tr class="head-row">
  7. <th>No.</th>
  8. <th>Submission 1</th>
  9. <th></th>
  10. <th>Submission 2</th>
  11. <th>Match %</th>
  12. </tr>
  13. <tr v-for="(comparison, index) in topComparisons"
  14. :key="comparison.firstSubmissionId
  15. + comparison.secondSubmissionId
  16. + comparison.matchPercentage"
  17. class="selectable"
  18. >
  19. <td @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)">{{
  20. index + 1
  21. }}.
  22. </td>
  23. <td :class="{ 'anonymous-style' : isAnonymous(comparison.firstSubmissionId)}"
  24. @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)">
  25. {{ isAnonymous(comparison.firstSubmissionId) ? "Hidden" : comparison.firstSubmissionId }}
  26. </td>
  27. <td
  28. @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)">
  29. <img alt=">>" src="@/assets/double_arrow_black_18dp.svg"/>
  30. </td>
  31. <td :class="{ 'anonymous-style' : isAnonymous(comparison.secondSubmissionId)}"
  32. @click="navigateToComparisonView(comparison.firstSubmissionId, comparison.secondSubmissionId)">
  33. {{ isAnonymous(comparison.secondSubmissionId) ? "Hidden" : comparison.secondSubmissionId }}
  34. </td>
  35. <td>{{ formattedMatchPercentage(comparison.matchPercentage) }}</td>
  36. <td>
  37. <img v-if="isInCluster(comparison.firstSubmissionId, comparison.secondSubmissionId)"
  38. alt=">>"
  39. src="@/assets/keyboard_double_arrow_down_black_18dp.svg"
  40. @click="toggleDialog(index)"
  41. />
  42. </td>
  43. <GDialog v-model="dialog[index]">
  44. <ClustersList :clusters="getClustersFor(comparison.firstSubmissionId, comparison.secondSubmissionId)"
  45. :comparison="comparison"/>
  46. </GDialog>
  47. </tr>
  48. </table>
  49. </template>
  50. <script>
  51. import {defineComponent, ref} from "vue";
  52. import router from "@/router";
  53. import store from "@/store/store";
  54. import {GDialog} from "gitart-vue-dialog";
  55. import ClustersList from "@/components/ClustersList";
  56. export default defineComponent({
  57. name: "ComparisonsTable",
  58. components: {ClustersList, GDialog},
  59. props: {
  60. topComparisons: {
  61. type: Array,
  62. required: true
  63. },
  64. clusters: {
  65. type: Array
  66. }
  67. },
  68. setup(props) {
  69. let formattedMatchPercentage = (number) => number.toFixed(2)
  70. const dialog = ref([])
  71. props.topComparisons.forEach(() => dialog.value.push(false))
  72. const toggleDialog = (index) => {
  73. dialog.value[index] = true
  74. }
  75. const navigateToComparisonView = (firstId, secondId) => {
  76. if (!store.state.single) {
  77. router.push({
  78. name: "ComparisonView",
  79. query: {firstId: firstId, secondId: secondId},
  80. })
  81. }
  82. }
  83. const isInCluster = (id1, id2) => {
  84. return props.clusters.some(c => c.members.includes(id1) && c.members.includes(id2))
  85. }
  86. const isAnonymous = (id) => {
  87. return store.state.anonymous.has(id)
  88. }
  89. const getParticipatingMatchesForId = (id, others) => {
  90. let matches = []
  91. props.topComparisons.forEach(comparison => {
  92. if (comparison.firstSubmissionId.includes(id) && others.includes(comparison.secondSubmissionId)) {
  93. matches.push({matchedWith: comparison.secondSubmissionId, percentage: comparison.matchPercentage})
  94. } else if (comparison.secondSubmissionId.includes(id) && others.includes(comparison.firstSubmissionId)) {
  95. matches.push({matchedWith: comparison.firstSubmissionId, percentage: comparison.matchPercentage})
  96. }
  97. })
  98. return matches;
  99. }
  100. const clustersWithParticipatingMatches = props.clusters.map(cluster => {
  101. let membersArray = {}
  102. cluster.members.forEach(member => {
  103. let others = cluster.members.filter(m => !m.includes(member))
  104. membersArray[member] = getParticipatingMatchesForId(member, others)
  105. })
  106. return {
  107. averageSimilarity: cluster.averageSimilarity,
  108. strength: cluster.strength,
  109. members: membersArray
  110. }
  111. })
  112. const getClustersFor = (id1, id2) => {
  113. return clustersWithParticipatingMatches.filter(c => Object.keys(c.members).includes(id1)
  114. && Object.keys(c.members).includes(id2))
  115. }
  116. return {
  117. clustersWithParticipatingMatches,
  118. dialog,
  119. isAnonymous,
  120. getClustersFor,
  121. toggleDialog,
  122. formattedMatchPercentage,
  123. navigateToComparisonView,
  124. isInCluster
  125. }
  126. }
  127. })
  128. </script>
  129. <style scoped>
  130. table {
  131. border-collapse: collapse;
  132. font-size: larger;
  133. text-align: center;
  134. }
  135. tr:nth-child(odd) {
  136. background: var(--primary-color-light);
  137. }
  138. tr:nth-child(even) {
  139. background: var(--secondary-color);
  140. }
  141. th {
  142. margin: 0;
  143. padding-top: 2%;
  144. padding-bottom: 2%;
  145. color: var(--on-primary-color);
  146. }
  147. td {
  148. padding-top: 3%;
  149. padding-bottom: 3%;
  150. }
  151. .anonymous-style {
  152. color: #777777;
  153. filter: blur(1px);
  154. }
  155. .head-row {
  156. background: var(--primary-color-light);
  157. }
  158. .selectable:hover {
  159. background: var(--primary-color-dark);
  160. cursor: pointer;
  161. }
  162. </style>