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.

accuracy.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 sys, os, re
  22. #arg 1 repository of the openvibe logs
  23. #arg 2 keyword to search in the log file to get the line where the measure was
  24. #arg 3 Threshold, the measure should be lower
  25. if len(sys.argv) < 4 :
  26. print('incorrect args')
  27. sys.exit(101)
  28. openvibeLogs=sys.argv[1]
  29. keyWord=sys.argv[2]
  30. threshold=float(sys.argv[3])
  31. def selectLineContainingWord (filename, searchingWord):
  32. """ Function to select the line containing the keyword
  33. the exception 103 is raised if file is missing
  34. """
  35. try:
  36. spaced_word = ' %s ' % searchingWord
  37. with open(filename) as file :
  38. for line in file:
  39. if spaced_word in line :
  40. return line
  41. #Exception raised if the log file wasn't created
  42. except FileNotFoundError:
  43. print('missing %s'%file)
  44. sys.exit(103)
  45. try:
  46. #Call the selectLineContainingWord function with the input parameter
  47. workingLine=selectLineContainingWord(openvibeLogs,keyWord)
  48. getPercentageValue = float(re.search('accuracy\s+is\s+(\d+(?:\.\d+))\%', workingLine).group(1))
  49. #check if the measure is under the threshold excpected
  50. if getPercentageValue >= threshold:
  51. print ('%s higher or equal to threshold %s'%(getPercentageValue,threshold))
  52. else:
  53. print ('%s lower to threshold %s'%(getPercentageValue,threshold))
  54. print ('reference line in the log %s' %workingLine)
  55. sys.exit(102)
  56. #exception raised if the keyword wasn't in the log file
  57. except AttributeError:
  58. print ('Missing searching word: %s in the file'%keyWord)
  59. sys.exit(104)
  60. #exception raised if the word: is, wasn't in the log file
  61. except ValueError:
  62. print ('error missing word: is in the selected line')
  63. sys.exit(105)
  64. except:
  65. raise
  66. sys.exit()