AreSameImagesReferenceOneExtract.vue 5.3 KB

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