Parcourir la source

Merge branch 'release/v0.0.1'

Jérôme BUISINE il y a 4 ans
Parent
commit
460b6337a1
5 fichiers modifiés avec 193 ajouts et 0 suppressions
  1. 4 0
      .gitignore
  2. 30 0
      README.md
  3. 14 0
      config.py
  4. 70 0
      generate/generate_experiment.py
  5. 75 0
      generate/generate_experiment_link.py

+ 4 - 0
.gitignore

@@ -102,3 +102,7 @@ venv.bak/
 
 # mypy
 .mypy_cache/
+
+# data folder
+data
+expe

+ 30 - 0
README.md

@@ -0,0 +1,30 @@
+# SIN3D-launcher
+
+## Description
+
+Project for generating users links in order to launch SIN3D application quickly during experiment.
+
+## How to use ?
+
+
+Generate user links (file saved into `data` folder):
+```sh
+python generate/generate_experiment_link.py --experiment AreSameImagesRandom --experimentId expe1 --scenes Appart1opt02,Bureau1,Cendrier --output expe1.csv
+```
+
+Generate experiment links for each user (file saved into `expe` folder):
+```sh
+python generate/generate_experiment.py --data data/expe1.csv --scenes 2 --users 150 --output expe1_user_links.csv
+```
+
+The final file is generated and contains data just as follow:
+
+```
+link1;link2;...;linkN
+...
+link2;link3;...;linkN
+```
+
+## Licence
+
+[The MIT license](LICENSE)

+ 14 - 0
config.py

@@ -0,0 +1,14 @@
+experiment_list = [
+    'MatchExtractsWithReference',
+    'AreSameImagesRandom',
+    'AreSameImagesReference',
+    'AreSameImagesReferenceOneExtract',
+    'PercentQualityRandom',
+    'IsImageCorrect',
+    'IsImageCorrectOneExtract'
+]
+
+default_host = 'https://diran.univ-littoral.fr'
+
+links_data_folder = 'data'
+expe_data_folder  = 'expe'

+ 70 - 0
generate/generate_experiment.py

@@ -0,0 +1,70 @@
+# main imports
+import base64
+import json
+import re
+import argparse
+import sys, os
+import requests
+import random
+
+# modules imports
+sys.path.insert(0, '') # trick to enable import of main folder module
+
+import config  as cfg
+
+
+def main():
+
+    parser = argparse.ArgumentParser(description="Compute specific dataset for model using of metric")
+
+    parser.add_argument('--data', type=str, help='data links to use', required=True)
+    parser.add_argument('--scenes', type=int, help="number of scenes", required=True)
+    parser.add_argument('--users', type=int, help="number of users of experiment", required=True)
+    parser.add_argument('--output', type=str, help="output filename of user links", required=True)
+
+    args = parser.parse_args()
+
+    p_data          = args.data
+    p_scenes        = args.scenes
+    p_users         = args.users
+    p_output        = args.output
+
+    # generate link for each scene
+    with open(p_data, 'r') as f:
+        lines = f.readlines()
+        lines = [l.replace('\n', '') for l in lines]
+        
+        nb_elements = len(lines)
+
+        # check if number of scenes is higher than number of elements in data links
+        if p_scenes > nb_elements:
+            p_scenes = nb_elements
+
+        # open output filename
+        filename_path = os.path.join(cfg.expe_data_folder, p_output)
+
+        if not os.path.exists(cfg.expe_data_folder):
+            os.makedirs(cfg.expe_data_folder)
+
+        output_f = open(filename_path, 'w')
+
+        for _ in range(p_users):
+
+            user_links = random.choices(lines, k=p_scenes)
+
+            # generate output line
+            output_line = ""
+            for link in user_links:
+                output_line += link + ';'
+            output_line += '\n'
+
+            output_f.write(output_line)
+            output_f.flush()
+        
+        output_f.close()
+
+        print("Experiment generated output file is saved into.. %s" % filename_path)
+
+
+if __name__== "__main__":
+    main()

+ 75 - 0
generate/generate_experiment_link.py

@@ -0,0 +1,75 @@
+# main imports
+import base64
+import json
+import re
+import argparse
+import sys, os
+import requests
+
+# modules imports
+sys.path.insert(0, '') # trick to enable import of main folder module
+
+import config  as cfg
+
+
+def encode_data(data):
+    json_data = json.dumps(data)
+    link_data = base64.b64encode(str(json_data).encode('utf-8'))
+    
+    return link_data
+
+
+def main():
+    # getting all scenes available name
+    scenes_list_url = cfg.default_host + '/api/listScenes'
+    res = requests.get(scenes_list_url)
+    data = json.loads(res.content)
+    scenes_name = data['data']
+
+    # getting all params
+    parser = argparse.ArgumentParser(description="Compute links for scenes of experiment")
+
+    parser.add_argument('--host', type=str, help='hostname choosen', default=cfg.default_host)
+    parser.add_argument('--experiment', type=str, help="experiment name to use", choices=cfg.experiment_list, required=True)
+    parser.add_argument('--experimentId', type=str, help="experiment id to use")
+    parser.add_argument('--scenes', type=str, help="scene name list from %s" % scenes_name)
+    parser.add_argument('--output', type=str, help="output filename", required=True)
+
+    args = parser.parse_args()
+
+    p_host          = args.host
+    p_experiment    = args.experiment
+    p_experiment_id = args.experimentId
+    p_scenes        = args.scenes.split(',')
+    p_output        = args.output
+
+    # generate link for each scene
+
+    links = []
+    for scene in p_scenes:
+
+        data = {
+            'hostConfig': p_host,
+            'experimentId': p_experiment_id,
+            'experimentName': p_experiment,
+            'sceneName': scene
+        }
+
+        generated_link_info = encode_data(data)
+        generated_link = p_host + '/#/?q=' + bytes(generated_link_info).decode("utf-8")
+        links.append(generated_link)
+
+    filename_path = os.path.join(cfg.links_data_folder, p_output)
+
+    if not os.path.exists(cfg.links_data_folder):
+        os.makedirs(cfg.links_data_folder)
+
+    with open(filename_path, 'w') as f:
+
+        for link in links:
+            f.write(link + '\n')
+
+    print("Links are saved into.. %s" % filename_path)
+
+if __name__== "__main__":
+    main()