PercentQualityRandom.vue 4.1 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>
  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 xs12 sm6 offset-sm3>
  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. <!--/ Image -->
  27. <!-- Quality Slider -->
  28. <v-flex xs12>
  29. <v-subheader class="pl-0">Donner votre score entre 0 et 100</v-subheader>
  30. <v-slider
  31. v-model="selectedQuality"
  32. thumb-label
  33. />
  34. </v-flex>
  35. <!--/ Quality Slider -->
  36. <!-- Experiment validation button -->
  37. <v-layout justify-center align-content-center>
  38. <div id="choice">
  39. <v-container grid-list-md text-xs-center fluid>
  40. <h2>Test {{ testCount }} / {{ maxTestCount }}</h2>
  41. <v-layout row wrap>
  42. <v-flex sm12 xs12>
  43. <v-btn @click="nextRandomImage" color="primary" large>Validate quality</v-btn>
  44. </v-flex>
  45. </v-layout>
  46. </v-container>
  47. </div>
  48. </v-layout>
  49. <!--/ Experiment validation button -->
  50. </template>
  51. </ExperimentBlock>
  52. </template>
  53. <script>
  54. import ExperimentBlock from '@/components/ExperimentBlock.vue'
  55. import ExperimentBase from '@/mixins/ExperimentBase.vue'
  56. import { EXPERIMENT as experimentMsgId } from '@/../config.messagesId'
  57. import { rand } from '@/functions'
  58. export default {
  59. components: {
  60. ExperimentBlock
  61. },
  62. mixins: [ExperimentBase],
  63. data() {
  64. return {
  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. this.image1 = await this.getImage(randomQuality)
  102. this.selectedQuality = 50
  103. },
  104. async nextRandomImage() {
  105. this.loadingMessage = 'Loading new test...'
  106. this.loadingErrorMessage = null
  107. try {
  108. this.testCount++
  109. const experimentalData = {
  110. image1: this.image1,
  111. selectedQuality: this.selectedQuality,
  112. experimentName: this.experimentName,
  113. sceneName: this.sceneName
  114. }
  115. this.sendMessage({ msgId: experimentMsgId.DATA, msg: experimentalData })
  116. // Experiment end
  117. if (this.testCount > this.maxTestCount) return this.finishExperiment()
  118. await this.getTest()
  119. }
  120. catch (err) {
  121. console.error('Failed to load new test', err)
  122. this.loadingErrorMessage = 'Failed to load new test. ' + err.message
  123. }
  124. finally {
  125. this.loadingMessage = null
  126. this.saveProgress()
  127. }
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. /* Experiment-specific style (CSS) */
  134. </style>