Browse Source

Configure availabie scenes

rigwild 1 year ago
parent
commit
a3ed193ac0

+ 20 - 3
experimentConfig.default.js

@@ -46,16 +46,33 @@ export const experiments = {
   MatchExtractsWithReference: {
     mixin: mixins.ExperimentBaseExtracts,
     defaultConfig: {},
-    scenesConfig: {}
+    scenesConfig: {},
+    availableScenes: {
+      whitelist: null,
+      blacklist: null
+      // No whitelist = Select all scenes
+      // Whitelist = Only select some scenes
+      // Blacklist = remove scenes
+      // whitelist: ['Appart1opt02', 'contemporary', 'bathroom', 'SdbDroite'],
+      // blacklist: ['Appart1opt02']
+    }
   },
   AreSameImagesRandom: {
     mixin: mixins.ExperimentBaseAreSameImages,
     defaultConfig: {},
-    scenesConfig: {}
+    scenesConfig: {},
+    availableScenes: {
+      whitelist: null,
+      blacklist: null
+    }
   },
   AreSameImagesReference: {
     mixin: mixins.ExperimentBaseAreSameImages,
     defaultConfig: {},
-    scenesConfig: {}
+    scenesConfig: {},
+    availableScenes: {
+      whitelist: null,
+      blacklist: null
+    }
   }
 }

+ 27 - 11
src/config.utils.js

@@ -1,4 +1,5 @@
 import deepmerge from 'deepmerge'
+import store from '@/store'
 import { experiments } from '@/../experimentConfig'
 
 // Merge a default config with a specific scene config
@@ -27,14 +28,29 @@ export const getExperimentConfig = (experimentName, sceneName) => {
   return deepmerge(mixinConfig, globalConfig)
 }
 
-// /**
-//  * Read config to get the list of available scenes for a given experiment
-//  *
-//  * @param {Object} experimentName The selected experiment
-//  * @param {String[]} scenesList List of scenes
-//  * @returns {String[]} The list of available scenes for this experiment
-//  */
-// export const getExperimentSceneList = (experimentName, scenesList) => {
-//   // TODO: scene blacklist, scene array, all
-//   return []
-// }
+/**
+ * Read config to get the list of available scenes for a given experiment.
+ * If no whitelist is supplied, it will take all the available scenes.
+ * If a blacklist is supplied, it will remove its scenes from the list of scenes.
+ *
+ * @param {Object} experimentName The selected experiment
+ * @returns {String[]} The list of available scenes for this experiment
+ */
+export const getExperimentSceneList = experimentName => {
+  if (!experiments[experimentName])
+    throw new Error(`Could not find the experiment "${experimentName}" in the config file.`)
+
+  let configuredScenesList = []
+
+  const confObj = experiments[experimentName].availableScenes
+  const scenesList = store.state.scenesList
+
+  // Apply whitelist
+  if (confObj.whitelist) configuredScenesList = scenesList.filter(x => confObj.whitelist.includes(x))
+  else configuredScenesList = scenesList
+
+  // Apply blacklist
+  if (confObj.blacklist) configuredScenesList = configuredScenesList.filter(x => !confObj.blacklist.includes(x))
+
+  return configuredScenesList
+}

+ 5 - 3
src/views/ExperimentsList.vue

@@ -39,6 +39,7 @@
 <script>
 import { mapState } from 'vuex'
 import Experiments from '@/router/experiments'
+import { getExperimentSceneList } from '@/config.utils'
 
 export default {
   name: 'ExperimentsList',
@@ -55,19 +56,20 @@ export default {
     }
   },
   computed: {
-    ...mapState(['scenesList', 'progression'])
+    ...mapState(['progression'])
   },
   mounted() {
     this.items = Experiments.map(expe => {
+      const scenesList = getExperimentSceneList(expe.name)
       const res = {
         name: expe.meta.fullName,
         link: `/experiments/${expe.name}`
       }
       // Check cache has an entry for each scenes in this experiment
-      if (this.progression[expe.name] && Object.keys(this.progression[expe.name]).every(y => this.scenesList.includes(y))) {
+      if (this.progression[expe.name]) {
         // Set experiment completion percentage
         const numberOfDoneScenes = Object.keys(this.progression[expe.name]).filter(y => this.progression[expe.name][y].done).length
-        const percentage = Math.round(numberOfDoneScenes / this.scenesList.length * 100)
+        const percentage = Math.round(numberOfDoneScenes / scenesList.length * 100)
         res.completion = `${percentage}%`
       }
       else res.completion = '0%'

+ 9 - 0
src/views/HostConfig.vue

@@ -79,6 +79,15 @@ export default {
     }
   },
 
+  mounted() {
+    if (process.env.NODE_ENV === 'rigwild')
+      this.config = {
+        ssl: false,
+        host: 'localhost',
+        port: '5000'
+      }
+  },
+
   methods: {
     ...mapActions(['setHostConfig']),
     reset() {

+ 5 - 2
src/views/SelectExperimentScene.vue

@@ -65,6 +65,7 @@
 import { mapState, mapGetters } from 'vuex'
 import Experiments from '@/router/experiments'
 import { API_ROUTES, shuffleArray } from '@/functions'
+import { getExperimentSceneList } from '@/config.utils'
 
 export default {
   name: 'SelectExperimentScene',
@@ -81,10 +82,12 @@ export default {
     }
   },
   computed: {
-    ...mapState(['scenesList', 'progression']),
+    ...mapState(['progression']),
     ...mapGetters(['getHostURI'])
   },
   async mounted() {
+    const scenesList = getExperimentSceneList(this.experimentName)
+
     // Find the selected experiment full name
     this.experimentFullName = Experiments.find(x => x.name === this.experimentName).meta.fullName
 
@@ -93,7 +96,7 @@ export default {
     let working = []
     let done = []
 
-    for (const aScene of this.scenesList) {
+    for (const aScene of scenesList) {
       const { data: thumb } = await fetch(`${this.getHostURI}${API_ROUTES.getImage(aScene, 'max')}`)
         .then(res => res.json())