generate_experiment_link.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # main imports
  2. import base64
  3. import json
  4. import re
  5. import argparse
  6. import sys, os
  7. import requests
  8. # modules imports
  9. sys.path.insert(0, '') # trick to enable import of main folder module
  10. import config as cfg
  11. def encode_data(data):
  12. json_data = json.dumps(data)
  13. link_data = base64.b64encode(str(json_data).encode('utf-8'))
  14. return link_data
  15. def main():
  16. # getting all scenes available name
  17. scenes_list_url = cfg.default_host + '/api/listScenes'
  18. res = requests.get(scenes_list_url)
  19. data = json.loads(res.content)
  20. scenes_name = data['data']
  21. # getting all params
  22. parser = argparse.ArgumentParser(description="Compute specific dataset for model using of metric")
  23. parser.add_argument('--host', type=str, help='hostname choosen', default=cfg.default_host)
  24. parser.add_argument('--experiment', type=str, help="experiment name to use", choices=cfg.experiment_list, required=True)
  25. parser.add_argument('--experimentId', type=str, help="experiment id to use")
  26. parser.add_argument('--scenes', type=str, help="scene name list from %s" % scenes_name)
  27. parser.add_argument('--output', type=str, help="output filename", required=True)
  28. args = parser.parse_args()
  29. p_host = args.host
  30. p_experiment = args.experiment
  31. p_experiment_id = args.experimentId
  32. p_scenes = args.scenes.split(',')
  33. p_output = args.output
  34. # generate link for each scene
  35. links = []
  36. for scene in p_scenes:
  37. data = {
  38. 'hostConfig': p_host,
  39. 'experimentId': p_experiment_id,
  40. 'experimentName': p_experiment,
  41. 'sceneName': scene
  42. }
  43. generated_link_info = encode_data(data)
  44. generated_link = p_host + '/#/?q=' + bytes(generated_link_info).decode("utf-8")
  45. links.append(generated_link)
  46. filename_path = os.path.join(cfg.links_data_folder, p_output)
  47. if not os.path.exists(cfg.links_data_folder):
  48. os.makedirs(cfg.links_data_folder)
  49. with open(filename_path, 'w') as f:
  50. for link in links:
  51. f.write(link + '\n')
  52. print("Links are saved into.. %s" % filename_path)
  53. if __name__== "__main__":
  54. main()