AreSameImagesReferenceOneExtract.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div>
  3. <v-container grid-list-md text-xs-center fluid>
  4. <v-layout row wrap>
  5. <v-flex xs12>
  6. <v-layout justify-start>
  7. <v-btn flat exact :to="`/experiments/${experimentName}`">
  8. <v-icon left>arrow_back</v-icon>
  9. Back to scene selection
  10. </v-btn>
  11. </v-layout>
  12. <h2>Experiment "{{ $route.meta.fullName }}"</h2>
  13. <h3>{{ sceneName }}</h3>
  14. </v-flex>
  15. <!-- Loading screen -->
  16. <loader v-if="loadingMessage" :message="loadingMessage" />
  17. <!--/ Loading screen -->
  18. <!-- Experiment -->
  19. <template v-else-if="!loadingErrorMessage && image1 && image2">
  20. <v-flex xs12 sm6>
  21. <v-card dark color="primary">
  22. <v-card-text class="px-0">Image 1</v-card-text>
  23. <v-container v-if="imageOneExtractPosition === 'left'" class="pa-1">
  24. <ExtractsToImage :extracts="image1" :extract-config="extractConfig" />
  25. </v-container>
  26. <v-img v-else :src="image2.link" @load="scrollToChoiceButtons">
  27. <template v-slot:placeholder>
  28. <v-layout fill-height align-center justify-center ma-0>
  29. <v-progress-circular indeterminate color="grey lighten-5" />
  30. </v-layout>
  31. </template>
  32. </v-img>
  33. </v-card>
  34. </v-flex>
  35. <v-flex xs12 sm6>
  36. <v-card dark color="primary">
  37. <v-card-text>Image 2</v-card-text>
  38. <v-container v-if="imageOneExtractPosition === 'right'" class="pa-1">
  39. <ExtractsToImage :extracts="image1" :extract-config="extractConfig" />
  40. </v-container>
  41. <v-img v-else :src="image2.link" @load="scrollToChoiceButtons">
  42. <template v-slot:placeholder>
  43. <v-layout fill-height align-center justify-center ma-0>
  44. <v-progress-circular indeterminate color="grey lighten-5" />
  45. </v-layout>
  46. </template>
  47. </v-img>
  48. </v-card>
  49. </v-flex>
  50. <!-- Experiment validation button -->
  51. <v-layout justify-center align-content-center>
  52. <div id="choice">
  53. <v-container grid-list-md text-xs-center fluid>
  54. <h2>Test {{ testCount }} / {{ maxTestCount }}</h2>
  55. <v-layout row wrap>
  56. <v-flex sm6 xs12>
  57. <v-btn @click="areTheSameActionLocal(false)" color="error" large>Images are NOT the same</v-btn>
  58. </v-flex>
  59. <v-flex sm6 xs12>
  60. <v-btn @click="areTheSameActionLocal(true)" color="success" large>Images are the same</v-btn>
  61. </v-flex>
  62. </v-layout>
  63. </v-container>
  64. </div>
  65. </v-layout>
  66. <!--/ Experiment validation button -->
  67. </template>
  68. <!--/ Experiment -->
  69. </v-layout>
  70. </v-container>
  71. </div>
  72. </template>
  73. <script>
  74. import ExperimentBaseExtracts from '@/mixins/ExperimentBaseExtracts'
  75. import ExperimentBaseAreSameImages from '@/mixins/ExperimentBaseAreSameImages'
  76. import Loader from '@/components/Loader'
  77. import ExtractsToImage from '@/components/ExperimentsComponents/ExtractsToImage'
  78. import { rand } from '@/functions'
  79. export default {
  80. name: 'AreSameImagesReferenceOneExtract',
  81. components: {
  82. Loader,
  83. ExtractsToImage
  84. },
  85. mixins: [
  86. ExperimentBaseExtracts,
  87. ExperimentBaseAreSameImages
  88. ],
  89. data() {
  90. return {
  91. experimentName: 'AreSameImagesReferenceOneExtract',
  92. imageOneExtractPosition: null,
  93. randomZoneIndex: null,
  94. randomZoneQuality: null
  95. }
  96. },
  97. async mounted() {
  98. // Load config for this scene to local state
  99. this.loadConfig()
  100. // Load progress from store into local state
  101. this.loadProgress()
  102. // Load scene data from the API
  103. await this.getQualitiesList()
  104. // Load a test if not already one loaded
  105. if (!this.image1 || !this.image2) {
  106. const { image1, image2 } = await this.getReferenceOneExtractTest()
  107. this.image1 = image1
  108. this.image2 = image2
  109. }
  110. this.saveProgress()
  111. },
  112. methods: {
  113. // Get a test with one random quality and a reference
  114. async getReferenceOneExtractTest() {
  115. // Randomly choose a quality for the extract
  116. const randomQuality = this.qualities[rand(0, this.qualities.length - 1)]
  117. const maxQuality = this.qualities[this.qualities.length - 1]
  118. // Get the reference image, extracts of reference image and random quality extracts
  119. const [maxExtracts, randomExtracts, maxImage] = await Promise.all([
  120. this.getExtracts('max'),
  121. this.getExtracts(randomQuality),
  122. this.getImage(maxQuality)
  123. ])
  124. // Select which zone is the random extract (-1 to get array index)
  125. const randomZoneIndex = rand(0, maxExtracts.extracts.length - 1)
  126. // Apply the random quality extract
  127. maxExtracts.extracts[randomZoneIndex] = randomExtracts.extracts[randomZoneIndex]
  128. // Fix uris
  129. const referenceWithOneExtract = maxExtracts.extracts.map(url => this.getHostURI + url)
  130. maxImage.link = this.getHostURI + maxImage.link
  131. // Backup test data
  132. this.randomZoneIndex = randomZoneIndex
  133. this.randomZoneQuality = randomQuality
  134. this.imageOneExtractPosition = rand(0, 1) === 0 ? 'left' : 'right'
  135. return {
  136. image1: referenceWithOneExtract,
  137. image2: maxImage
  138. }
  139. },
  140. areTheSameActionLocal(areTheSame) {
  141. const additionalData = {
  142. imageOneExtractPosition: this.imageOneExtractPosition,
  143. randomZoneIndex: this.randomZoneIndex,
  144. randomZone: this.randomZoneIndex + 1,
  145. randomZoneQuality: this.randomZoneQuality
  146. }
  147. this.areTheSameAction(areTheSame, this.getReferenceOneExtractTest, additionalData)
  148. }
  149. }
  150. }
  151. </script>