AreSameImagesReferenceOneExtract.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. components: {
  68. ExperimentBlock,
  69. ExtractsToImage
  70. },
  71. mixins: [
  72. ExperimentBaseExtracts,
  73. ExperimentBaseAreSameImages
  74. ],
  75. data() {
  76. return {
  77. imageOneExtractPosition: null,
  78. randomZoneIndex: null,
  79. randomZoneQuality: null
  80. }
  81. },
  82. async mounted() {
  83. // Load config for this scene to local state
  84. this.loadConfig()
  85. // Load progress from store into local state
  86. this.loadProgress()
  87. // Load scene data from the API
  88. await this.getQualitiesList()
  89. // Load a test if not already one loaded
  90. if (!this.image1 || !this.image2) {
  91. const { image1, image2 } = await this.getReferenceOneExtractTest()
  92. this.image1 = image1
  93. this.image2 = image2
  94. }
  95. this.saveProgress()
  96. },
  97. methods: {
  98. // Get a test with one random quality and a reference
  99. async getReferenceOneExtractTest() {
  100. // Randomly choose a quality for the extract
  101. const randomQuality = this.qualities[rand(0, this.qualities.length - 1)]
  102. const maxQuality = this.qualities[this.qualities.length - 1]
  103. // Get the reference image, extracts of reference image and random quality extracts
  104. const [maxExtracts, randomExtracts, maxImage] = await Promise.all([
  105. this.getExtracts('max'),
  106. this.getExtracts(randomQuality),
  107. this.getImage(maxQuality)
  108. ])
  109. // Select which zone is the random extract (-1 to get array index)
  110. const randomZoneIndex = rand(0, maxExtracts.extracts.length - 1)
  111. // Apply the random quality extract
  112. maxExtracts.extracts[randomZoneIndex] = randomExtracts.extracts[randomZoneIndex]
  113. // Backup test data
  114. this.randomZoneIndex = randomZoneIndex
  115. this.randomZoneQuality = randomQuality
  116. this.imageOneExtractPosition = rand(0, 1) === 0 ? 'left' : 'right'
  117. return {
  118. image1: maxExtracts.extracts,
  119. image2: maxImage
  120. }
  121. },
  122. areTheSameActionLocal(areTheSame) {
  123. const additionalData = {
  124. imageOneExtractPosition: this.imageOneExtractPosition,
  125. randomZoneIndex: this.randomZoneIndex,
  126. randomZone: this.randomZoneIndex + 1,
  127. randomZoneQuality: this.randomZoneQuality,
  128. stepCounter: this.testCount,
  129. maxStepCount: this.maxTestCount
  130. }
  131. this.areTheSameAction(areTheSame, this.getReferenceOneExtractTest, additionalData)
  132. }
  133. }
  134. }
  135. </script>