Browse Source

Added experiment default config file support and file linting

rigwild 1 year ago
parent
commit
10d88a52aa

+ 22 - 7
src/config.utils.js

@@ -1,14 +1,31 @@
 import deepmerge from 'deepmerge'
 import store from '@/store'
+import { experiments as experimentsDEFAULT } from '@/../experimentConfig.default'
 import { experiments } from '@/../experimentConfig'
 
 // Merge a default config with a specific scene config
 const buildConfig = ({ defaultConfig = {}, scenesConfig = {} }, sceneName) =>
   deepmerge(defaultConfig, scenesConfig[sceneName] || {})
 
+// Merge multiple configs (used for multiple mixins)
 const buildMultiConfig = (confArr, sceneName) =>
   deepmerge.all(confArr.map(aConfig => buildConfig(aConfig, sceneName)))
 
+
+/**
+ * Find the configuration.
+ * Will use the default configuration if not found in the real one.
+ * @param {String} experimentName The selected experiment
+ * @returns {Object} Configuration object
+ */
+const getConfigObject = experimentName => {
+  if (experiments[experimentName])
+    return experiments
+  else if (experimentsDEFAULT[experimentName])
+    return experimentsDEFAULT
+  throw new Error(`Could not find the experiment "${experimentName}" in the config file nor the default config file.`)
+}
+
 /**
 * Build a configuration file by merging the default config with the asked scene.
 * The asked scene config will overwrite the default config.
@@ -20,13 +37,12 @@ const buildMultiConfig = (confArr, sceneName) =>
 * @returns {Object} The config for the selected experiment with the selected scene
 */
 export const getExperimentConfig = (experimentName, sceneName) => {
-  if (!experiments[experimentName])
-    throw new Error(`Could not find the experiment "${experimentName}" in the config file.`)
+  const config = getConfigObject(experimentName)
 
   // Build parent mixin config
-  const mixinConfig = buildMultiConfig(experiments[experimentName].mixins, sceneName)
+  const mixinConfig = buildMultiConfig(config[experimentName].mixins, sceneName)
   // Build global config
-  const globalConfig = buildConfig(experiments[experimentName], sceneName)
+  const globalConfig = buildConfig(config[experimentName], sceneName)
   // Merge configs
   return deepmerge(mixinConfig, globalConfig)
 }
@@ -40,12 +56,11 @@ export const getExperimentConfig = (experimentName, sceneName) => {
  * @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.`)
+  const config = getConfigObject(experimentName)
 
   let configuredScenesList = []
 
-  const confObj = experiments[experimentName].availableScenes
+  const confObj = config[experimentName].availableScenes
   const scenesList = store.state.scenesList
 
   // Apply whitelist

+ 0 - 11
src/main.js

@@ -3,20 +3,9 @@ import './plugins/vuetify'
 import App from './App.vue'
 import router from './router'
 import store from './store'
-import VueNativeSock from 'vue-native-websocket'
 
 Vue.config.productionTip = false
 
-// Connect the WebSocket client to the store
-Vue.use(VueNativeSock, 'ws://example.com', {
-  store,
-  connectManually: true,
-  reconnection: true,
-  reconnectionAttempts: 2,
-  reconnectionDelay: 1000
-})
-store.$socket = Vue.prototype.$socket
-
 // A function loaded before each route change
 router.beforeEach((to, from, next) => {
   // Redirect from config pages if already configured

+ 3 - 3
src/views/Experiments/AreSameImagesRandom.vue

@@ -95,10 +95,10 @@ export default {
 
   methods: {
     // generate next action and save data
-    async nextAction(same){
+    async nextAction(same) {
       let additionalData = {
-          stepCounter: this.testCount,
-          maxStepCount: this.maxTestCount
+        stepCounter: this.testCount,
+        maxStepCount: this.maxTestCount
       }
 
       this.areTheSameAction(same, this.getReferenceTest, additionalData)

+ 3 - 3
src/views/Experiments/AreSameImagesReference.vue

@@ -96,10 +96,10 @@ export default {
 
   methods: {
     // generate next action and save data
-    async nextAction(same){
+    async nextAction(same) {
       let additionalData = {
-          stepCounter: this.testCount,
-          maxStepCount: this.maxTestCount
+        stepCounter: this.testCount,
+        maxStepCount: this.maxTestCount
       }
 
       this.areTheSameAction(same, this.getReferenceTest, additionalData)

+ 1 - 1
src/views/Experiments/AreSameImagesReferenceOneExtract.vue

@@ -151,7 +151,7 @@ export default {
         randomZone: this.randomZoneIndex + 1,
         randomZoneQuality: this.randomZoneQuality,
         stepCounter: this.testCount,
-        maxStepCount: this.maxTestCount,
+        maxStepCount: this.maxTestCount
       }
       this.areTheSameAction(areTheSame, this.getReferenceOneExtractTest, additionalData)
     }

+ 0 - 1
src/views/Experiments/IsImageCorrect.vue

@@ -168,7 +168,6 @@ export default {
 }
 </script>
 
-
 <style scoped>
 /* Experiment-specific style (CSS) */
 </style>

+ 0 - 1
src/views/Experiments/IsImageCorrectOneExtract.vue

@@ -168,7 +168,6 @@ export default {
 }
 </script>
 
-
 <style scoped>
 /* Experiment-specific style (CSS) */
 </style>