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 7.0KB

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