You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

csv-analyser.py 2.1KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #######################################################################
  2. # Software License Agreement (AGPL-3 License)
  3. #
  4. # OpenViBE SDK Test Software
  5. # Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
  6. # Copyright (C) Inria, 2015-2017,V1.0
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License version 3,
  10. # as published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program.
  19. # If not, see <http://www.gnu.org/licenses/>.
  20. #######################################################################
  21. import csv
  22. import sys
  23. import re
  24. import numpy as np
  25. # test script parameter arg1: reference file csv
  26. # test script parameter arg2: test file csv
  27. if len(sys.argv) < 3 :
  28. print('incorrect args')
  29. sys.exit(101)
  30. # assign arguments to variable
  31. ref_filename=sys.argv[1]
  32. test_filename=sys.argv[2]
  33. #open files associated with the variables
  34. with open(ref_filename, 'r') as fileReferenceData :
  35. ref_header = next(fileReferenceData)
  36. ref_data = np.loadtxt(fileReferenceData, delimiter=",", usecols=[0, 1, 2, 3, 4])
  37. min_epoch = np.amax(ref_data[ref_data[:,0] <= 1], 0)[1] + 1
  38. start_index = np.where(ref_data[:,1] == min_epoch)[0][0]
  39. max_epoch = np.amax(ref_data[ref_data[:,0] <= 2], 0)[1]
  40. end_index = np.where(ref_data[:,1] == max_epoch)[0][-1] + 1
  41. with open(test_filename, 'r') as fileTestData :
  42. test_header = next(fileTestData)
  43. test_data = np.loadtxt(fileTestData, delimiter=",", usecols=[0, 1, 2, 3, 4])
  44. if test_header != ref_header or test_data.shape[0] != (end_index - start_index):
  45. print("Header or shape does not correspond")
  46. sys.exit(101)
  47. if not np.allclose(test_data[:,[0, 2, 3, 4]], ref_data[start_index:end_index,[0, 2, 3, 4]]) :
  48. print("Data is different")
  49. sys.exit(100)
  50. sys.exit()