extract_stats_freq_and_min_all.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # main imports
  2. import os, sys
  3. import argparse
  4. import json
  5. import numpy as np
  6. def main():
  7. """
  8. main function which is ran when launching script
  9. """
  10. parser = argparse.ArgumentParser(description="Extract scenes data and save thresholds into .csv")
  11. parser.add_argument('--file', type=str, help='image to convert', required=True)
  12. parser.add_argument('--output', type=str, help='output csv filename', required=True)
  13. args = parser.parse_args()
  14. p_file = args.file
  15. p_output = args.output
  16. f = open(p_file)
  17. json_data = json.load(f)
  18. dict_data = {}
  19. for element in json_data:
  20. scene = element['msg']['sceneName']
  21. if scene not in dict_data:
  22. dict_data[scene] = {}
  23. extracts = element['msg']['extracts']
  24. for extract in extracts:
  25. if extract['index'] not in dict_data[scene]:
  26. dict_data[scene][extract['index']] = [extract['quality']]
  27. else:
  28. dict_data[scene][extract['index']].append(extract['quality'])
  29. output_file = open(p_output, 'w')
  30. # output_file.write('scene;n_users;min_scene;\n')
  31. for scene in dict_data:
  32. output_file.write(scene + ';')
  33. all_thresholds = []
  34. n_users = 0
  35. for extract in dict_data[scene]:
  36. thresholds_data = dict_data[scene][extract]
  37. all_thresholds.append(int(np.min(thresholds_data)))
  38. n_users = len(thresholds_data)
  39. output_file.write(str(n_users) + ';' + str(np.min(all_thresholds)) + ';')
  40. output_file.write('\n')
  41. if __name__ == "__main__":
  42. main()