PercentQualityRandom.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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>
  9. <!-- ## Template to place in the header (example: Extract-configurator) ## -->
  10. </template>
  11. <template v-slot:content>
  12. <!-- ## Actual experiment template ## -->
  13. <!-- Image -->
  14. <v-flex xs6>
  15. <v-card dark color="primary">
  16. <v-card-text class="px-0">Image 1</v-card-text>
  17. <v-img v-if="image1 && image1.link" :src="image1.link">
  18. <template v-slot:placeholder>
  19. <v-layout fill-height align-center justify-center ma-0>
  20. <v-progress-circular indeterminate color="grey lighten-5" />
  21. </v-layout>
  22. </template>
  23. </v-img>
  24. </v-card>
  25. </v-flex>
  26. <!-- Quality Slider -->
  27. <v-flex xs12>
  28. <v-subheader class="pl-0">Mark from 0 to 100 how high you think the quality is</v-subheader>
  29. <v-slider
  30. v-model="selectedQuality"
  31. thumb-label
  32. />
  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 sm12 xs12>
  41. <v-btn @click="nextRandomImage()" color="primary" large>Validate quality</v-btn>
  42. </v-flex>
  43. </v-layout>
  44. </v-container>
  45. </div>
  46. </v-layout>
  47. <!--/ Experiment validation button -->
  48. </template>
  49. </ExperimentBlock>
  50. </template>
  51. <script>
  52. import ExperimentBlock from '@/components/ExperimentBlock.vue'
  53. import ExperimentBase from '@/mixins/ExperimentBase.vue'
  54. import { EXPERIMENT as experimentMsgId } from '@/../config.messagesId'
  55. import { rand } from '@/functions'
  56. export default {
  57. name: 'PercentQualityRandom', // experiment filename
  58. components: {
  59. ExperimentBlock
  60. },
  61. mixins: [ExperimentBase],
  62. data() {
  63. return {
  64. experimentName: 'PercentQualityRandom', // experiment filename
  65. image1: null,
  66. selectedQuality: 50,
  67. testCount: 1,
  68. maxTestCount: 10
  69. }
  70. },
  71. // When experiment is loaded, this function is ran
  72. async mounted() {
  73. // Load config and progress for this scene to local state
  74. this.loadConfig()
  75. this.loadProgress()
  76. // ## Do your experiment initialization stuff here ##
  77. this.loadingMessage = 'Loading experiment data...'
  78. this.loadingErrorMessage = null
  79. try {
  80. // Load scene qualities list
  81. await this.getQualitiesList()
  82. if (!this.image1) await this.getTest()
  83. }
  84. catch (err) {
  85. console.error(err)
  86. this.loadingErrorMessage = err.message
  87. return
  88. }
  89. finally {
  90. this.loadingMessage = null
  91. }
  92. // ##/ Do your experiment initialization stuff here ##
  93. // Save progress from local state into store
  94. this.saveProgress()
  95. },
  96. // List of experiment-specific methods
  97. methods: {
  98. // load image
  99. async getTest() {
  100. let randomQuality = this.qualities[rand(0, this.qualities.length - 1)]
  101. let image = await this.getImage(randomQuality)
  102. image.link = this.getHostURI + image.link
  103. this.image1 = image
  104. this.selectedQuality = 50
  105. },
  106. async nextRandomImage() {
  107. this.loadingMessage = 'Loading new test...'
  108. this.loadingErrorMessage = null
  109. try {
  110. this.testCount++
  111. const experimentalData = {
  112. image1: this.image1,
  113. selectedQuality: this.selectedQuality,
  114. experimentName: this.experimentName,
  115. sceneName: this.sceneName
  116. }
  117. this.sendMessage({ msgId: experimentMsgId.DATA, msg: experimentalData })
  118. await this.getTest()
  119. // Experiment end
  120. if (this.testCount > this.maxTestCount) return this.finishExperiment()
  121. }
  122. catch (err) {
  123. console.error('Failed to load new test', err)
  124. this.loadingErrorMessage = 'Failed to load new test. ' + err.message
  125. }
  126. finally {
  127. this.loadingMessage = null
  128. this.saveProgress()
  129. }
  130. }
  131. }
  132. }
  133. </script>
  134. <style scoped>
  135. /* Experiment-specific style (CSS) */
  136. </style>