calibration_errors.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # main imports
  2. import argparse
  3. import numpy as np
  4. import sys
  5. # mongo import
  6. from pymongo import MongoClient
  7. # modules imports
  8. sys.path.insert(0, '') # trick to enable import of main folder module
  9. # config imports
  10. import custom_config as cfg
  11. def main():
  12. parser = argparse.ArgumentParser(description="Get error during calibration experiment for each user")
  13. parser.add_argument('--expeId', type=str, help='Experiment identifier')
  14. args = parser.parse_args()
  15. p_expe_id = args.expeId
  16. # connect to Mongo db and collect data
  17. client = MongoClient(cfg.default_host)
  18. db = client.sin3d
  19. query = {
  20. 'data.msg.experimentName': "CalibrationMeasurement",
  21. 'data.msgId': "EXPERIMENT_VALIDATED"
  22. }
  23. # add of expeid into query if exists
  24. if p_expe_id:
  25. print("Expe id used", p_expe_id)
  26. query['data.experimentId'] = p_expe_id
  27. print(query)
  28. res = db.datas.find(query)
  29. zone_index = np.arange(16)
  30. threshold_img = (zone_index / 15) * 100
  31. print(threshold_img)
  32. for cursor in res:
  33. user_data = cursor['data']
  34. user_id = user_data['userId']
  35. experiment_user_thresholds = []
  36. experiment_user_zone = []
  37. experiment_error_thresholds = []
  38. for val in user_data['msg']['extracts']:
  39. zone_id = int(val['zone']) - 1
  40. experiment_user_thresholds.append(val['quality'])
  41. error = (val['quality'] - threshold_img[zone_id])
  42. error_squared = error * error
  43. experiment_user_zone.append(zone_id)
  44. experiment_error_thresholds.append(error_squared)
  45. print('----------------------------------------------')
  46. print('User', user_id)
  47. print('zone id', experiment_user_zone)
  48. print('Estimated', experiment_user_thresholds)
  49. print('Squared error', list(map(lambda x: str('%.2f' % x), experiment_error_thresholds)))
  50. print('Mean squared error', np.mean(experiment_error_thresholds))
  51. if __name__== "__main__":
  52. main()