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.

UIModellTaktil.py 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. from subprocess import *
  2. from threading import Thread
  3. import time
  4. from UIModell import *
  5. class ModellTaktil(Modell):
  6. def __init__(self,c, path_ov, path_files):
  7. Thread.__init__(self)
  8. Modell.__init__(self, c)
  9. self.PATH_FILES = path_files
  10. self.PATH_OV = path_ov
  11. self.aktiv= True
  12. self.openVibeAktiv = False
  13. def stop(self):
  14. print("stop thread")
  15. self.aktiv = False
  16. def setFunktion(self, func, args=None, kwargs=None):
  17. self.func = func
  18. self.args = args or []
  19. self.kwargs = kwargs or {}
  20. def run(self):
  21. print("start thread")
  22. #self.aktiv = True
  23. t = Thread(target=self.func, args=self.args, kwargs=self.kwargs)
  24. t.setDaemon(True)
  25. t.start()
  26. while self.aktiv:
  27. time.sleep(0.1)
  28. def startCopySpelling(self):
  29. print("start copySpelling")
  30. self.controller.resetInfo()
  31. self.controller.addInfoText('start copyspelling -- ')
  32. self.controller.setTitle("Copy Spelling")
  33. path = self.PATH_FILES + 'p300-visual-1-acquisition.xml'
  34. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  35. stdout=PIPE,
  36. universal_newlines=True)
  37. self.openVibeAktiv = True
  38. while True:
  39. output = process.stdout.readline()
  40. print(output.strip())
  41. x = output.find("schlagwort?")
  42. y = output.find("Error")
  43. if(x != -1):
  44. print("Training finished")
  45. process.terminate()
  46. self.controller.addInfoText('finished Copyspelling\n')
  47. self.controller.stop("filterXdawn")
  48. break
  49. elif(y != -1 ):
  50. print("Error occured")
  51. self.controller.changeScreen("StartPage")
  52. self.controller.addInfoText("Fehler beim Copyspelling aufgetaucht\n")
  53. process.terminate()
  54. self.controller.stop()
  55. break
  56. self.controller.stop()
  57. #self.killProzess()
  58. #self.controller.filterXdawn()
  59. def trainXDawn(self):
  60. print("start training Xdawn")
  61. self.controller.addInfoText('start training XDawn -- ')
  62. path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml'
  63. #path = 'Projekte/test.xml'
  64. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  65. stdout=PIPE,
  66. universal_newlines=True)
  67. self.openVibeAktiv = True
  68. while self.aktiv:
  69. output = process.stdout.readline()
  70. print(output.strip())
  71. x = output.find("Training finished and saved")
  72. y = output.find("Error")
  73. if(x != -1):
  74. print("Training finished")
  75. process.terminate()
  76. self.controller.addInfoText('finished Training\n')
  77. self.controller.stop("filterClassic")
  78. break
  79. elif(y != -1 ):
  80. print("Error occured")
  81. self.controller.changeScreen("StartPage")
  82. self.controller.addInfoText("Fehler beim XDawn Training aufgetaucht\n")
  83. self.controller.stop()
  84. process.terminate()
  85. break
  86. self.controller.stop()
  87. #self.controller.filterClassic()
  88. def trainClassifier(self):
  89. print("start training Classifier")
  90. self.controller.addInfoText("start training with Classifier -- ")
  91. path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml'
  92. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  93. stdout=PIPE,
  94. universal_newlines=True)
  95. self.openVibeAktiv = True
  96. counter = 0
  97. while True:
  98. output = process.stdout.readline()
  99. print(output.strip())
  100. x = output.find("aka Classifier trainer")
  101. accuracy = output.find("Training set accuracy is")
  102. y = output.find("Error")
  103. if(x != -1):
  104. counter = counter +1
  105. #counter = 18
  106. if(counter >= 17):
  107. print("Training finished")
  108. self.controller.addInfoText('finished Training\n')
  109. process.terminate()
  110. self.controller.stop("save")
  111. break
  112. elif(y != -1 ):
  113. print("Error occured")
  114. self.controller.changeScreen("StartPage")
  115. self.controller.addInfoText("Fehler beim Classifier Training aufgetaucht\n")
  116. process.terminate()
  117. break
  118. elif(accuracy != -1):
  119. print("ACCURACY" + output)
  120. self.controller.changeScreen("StartPage")
  121. self.controller.stop()
  122. def freeSpelling(self):
  123. #bei error auch abrechen?
  124. print("start freeSpelling")
  125. self.controller.resetInfo()
  126. self.controller.addInfoText('start free spelling -- ')
  127. path = self.PATH_FILES + 'p300-visual-4-online.xml'
  128. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  129. stdout=PIPE,
  130. universal_newlines=True)
  131. self.openVibeAktiv = True
  132. while True:
  133. output = process.stdout.readline()
  134. print(output.strip())
  135. y = output.find("Error")
  136. x = output.find("Schlagwort")
  137. if(x != -1):
  138. print("End Spelling")
  139. process.terminate()
  140. self.controller.addInfoText('finished freespelling\n')
  141. self.controller.changeScreen("StartPage")
  142. self.controller.stop()
  143. break
  144. elif(y != -1 ):
  145. print("Error occured")
  146. self.controller.changeScreen("StartPage")
  147. self.controller.addInfoText("Fehler beim Freespelling aufgetaucht\n")
  148. process.terminate()
  149. self.controller.stop()
  150. break
  151. self.controller.changeScreen("StartPage")
  152. self.controller.stop()
  153. def killProzess(self):
  154. if(self.openVibeAktiv):
  155. self.openVibeAktiv = False
  156. self.killProzessParent()