extract_stats.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. for scene in dict_data:
  31. output_file.write(scene + ';')
  32. for extract in dict_data[scene]:
  33. thresholds_data = dict_data[scene][extract]
  34. output_file.write(str(int(np.mean(thresholds_data))) + ';')
  35. output_file.write('\n')
  36. if __name__ == "__main__":
  37. main()