AreSameImagesReference.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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-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-img v-if="image1 && image1.link" :src="image1.link">
  14. <template v-slot:placeholder>
  15. <v-layout fill-height align-center justify-center ma-0>
  16. <v-progress-circular indeterminate color="grey lighten-5" />
  17. </v-layout>
  18. </template>
  19. </v-img>
  20. </v-card>
  21. </v-flex>
  22. <v-flex sm6 xs12>
  23. <v-card dark color="primary">
  24. <v-card-text>Image 2</v-card-text>
  25. <v-img v-if="image2 && image2.link" :src="image2.link" @load="scrollToChoiceButtons">
  26. <template v-slot:placeholder>
  27. <v-layout fill-height align-center justify-center ma-0>
  28. <v-progress-circular indeterminate color="grey lighten-5" />
  29. </v-layout>
  30. </template>
  31. </v-img>
  32. </v-card>
  33. </v-flex>
  34. <!-- Experiment validation button -->
  35. <v-layout justify-center align-content-center>
  36. <div id="choice">
  37. <v-container grid-list-md text-xs-center fluid>
  38. <h2>Test {{ testCount }} / {{ maxTestCount }}</h2>
  39. <v-layout row wrap>
  40. <v-flex sm6 xs12>
  41. <v-btn @click="nextAction(false)" color="error" large>Images are NOT the same</v-btn>
  42. </v-flex>
  43. <v-flex sm6 xs12>
  44. <v-btn @click="nextAction(true)" color="success" large>Images are the same</v-btn>
  45. </v-flex>
  46. </v-layout>
  47. </v-container>
  48. </div>
  49. </v-layout>
  50. <!--/ Experiment validation button -->
  51. </template>
  52. </ExperimentBlock>
  53. </template>
  54. <script>
  55. import ExperimentBlock from '@/components/ExperimentBlock.vue'
  56. import ExperimentBaseAreSameImages from '@/mixins/ExperimentBaseAreSameImages'
  57. import { rand } from '@/functions'
  58. export default {
  59. components: {
  60. ExperimentBlock
  61. },
  62. mixins: [ExperimentBaseAreSameImages],
  63. data() {
  64. return {
  65. referenceImagePosition: null
  66. }
  67. },
  68. async mounted() {
  69. // Load config for this scene to local state
  70. this.loadConfig()
  71. // Load progress from store into local state
  72. this.loadProgress()
  73. // Load scene data from the API
  74. await this.getQualitiesList()
  75. // Load a test if not already one loaded
  76. if (!this.image1 || !this.image1.link || !this.image2 || !this.image2.link) {
  77. const { image1, image2 } = await this.getReferenceTest()
  78. this.image1 = image1
  79. this.image2 = image2
  80. }
  81. this.saveProgress()
  82. },
  83. methods: {
  84. // Get a test with random qualities
  85. getReferenceTest() {
  86. // Randomly choose which is the reference image (0 = left, 1 = right)
  87. const isReferenceLeft = rand(0, 1) === 0
  88. // Randomly choose a quality for the other image
  89. const randomQuality = this.qualities[rand(0, this.qualities.length - 1)]
  90. const res = [this.qualities[this.qualities.length - 1], randomQuality]
  91. this.referenceImagePosition = isReferenceLeft ? 'left' : 'right'
  92. const table = isReferenceLeft ? res : res.reverse()
  93. return this.getTest(table[0], table[1])
  94. },
  95. // generate next action and save data
  96. async nextAction(same) {
  97. let additionalData = {
  98. stepCounter: this.testCount,
  99. maxStepCount: this.maxTestCount
  100. }
  101. this.areTheSameAction(same, this.getReferenceTest, additionalData)
  102. }
  103. }
  104. }
  105. </script>