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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. self.infoText = ''
  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.infoText = 'start copyspelling -- '
  31. self.controller.setInfos(self.infoText)
  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.infoText = self.infoText + 'finished Copyspelling\n'
  47. self.controller.setInfos(self.infoText)
  48. self.controller.stop("filterXdawn")
  49. break
  50. elif(y != -1 ):
  51. print("Error occured")
  52. self.controller.changeScreen("StartPage")
  53. self.controller.setInfos(self.infoText + "Fehler beim Copyspelling aufgetaucht\n")
  54. process.terminate()
  55. self.controller.stop()
  56. break
  57. self.controller.stop()
  58. #self.killProzess()
  59. #self.controller.filterXdawn()
  60. def trainXDawn(self):
  61. print("start training Xdawn")
  62. self.infoText = self.infoText + 'start training XDawn -- '
  63. self.controller.setInfos(self.infoText)
  64. path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml'
  65. #path = 'Projekte/test.xml'
  66. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  67. stdout=PIPE,
  68. universal_newlines=True)
  69. self.openVibeAktiv = True
  70. while self.aktiv:
  71. output = process.stdout.readline()
  72. print(output.strip())
  73. x = output.find("Training finished and saved")
  74. y = output.find("Error")
  75. if(x != -1):
  76. print("Training finished")
  77. process.terminate()
  78. self.infoText = self.infoText + 'finished Training\n'
  79. self.controller.setInfos(self.infoText)
  80. self.controller.stop("filterClassic")
  81. break
  82. elif(y != -1 ):
  83. print("Error occured")
  84. self.controller.changeScreen("StartPage")
  85. self.controller.setInfos(self.infoText + "Fehler beim XDawn Training aufgetaucht\n")
  86. self.controller.stop()
  87. process.terminate()
  88. break
  89. self.controller.stop()
  90. #self.controller.filterClassic()
  91. def trainClassifier(self):
  92. print("start training Classifier")
  93. self.infoText = self.infoText + "start training with Classifier -- "
  94. self.controller.setInfos(self.infoText)
  95. path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml'
  96. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  97. stdout=PIPE,
  98. universal_newlines=True)
  99. self.openVibeAktiv = True
  100. counter = 0
  101. while True:
  102. output = process.stdout.readline()
  103. print(output.strip())
  104. x = output.find("aka Classifier trainer")
  105. accuracy = output.find("Training set accuracy is")
  106. y = output.find("Error")
  107. if(x != -1):
  108. counter = counter +1
  109. #counter = 18
  110. if(counter >= 17):
  111. print("Training finished")
  112. self.infoText = self.infoText + 'finished Training\n'
  113. self.controller.setInfos(self.infoText)
  114. process.terminate()
  115. break
  116. elif(y != -1 ):
  117. print("Error occured")
  118. self.controller.changeScreen("StartPage")
  119. self.controller.setInfos(self.infoText + "Fehler beim Classifier Training aufgetaucht\n")
  120. process.terminate()
  121. break
  122. elif(accuracy != -1):
  123. print("ACCURACY" + output)
  124. self.controller.changeScreen("StartPage")
  125. self.controller.stop()
  126. def freeSpelling(self):
  127. #bei error auch abrechen?
  128. print("start freeSpelling")
  129. self.infoText = 'start free spelling -- '
  130. self.controller.setInfos(self.infoText)
  131. path = self.PATH_FILES + 'p300-visual-4-online.xml'
  132. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  133. stdout=PIPE,
  134. universal_newlines=True)
  135. self.openVibeAktiv = True
  136. while True:
  137. output = process.stdout.readline()
  138. print(output.strip())
  139. y = output.find("Error")
  140. x = output.find("Schlagwort")
  141. if(x != -1):
  142. print("End Spelling")
  143. process.terminate()
  144. self.infoText = self.infoText + 'finished freespelling\n'
  145. self.controller.setInfos(self.infoText)
  146. self.controller.changeScreen("StartPage")
  147. self.controller.stop()
  148. break
  149. elif(y != -1 ):
  150. print("Error occured")
  151. self.controller.changeScreen("StartPage")
  152. self.controller.setInfos(self.infoText + "Fehler beim Freespelling aufgetaucht\n")
  153. process.terminate()
  154. self.controller.stop()
  155. break
  156. self.controller.changeScreen("StartPage")
  157. self.controller.stop()
  158. def killProzess(self):
  159. if(self.openVibeAktiv):
  160. self.openVibeAktiv = False
  161. print('start killing')
  162. pidOV = 0
  163. items = []
  164. prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip()
  165. zeilen = prozesse.split('\n')
  166. for z in zeilen:
  167. if(z.find("openvibe-design") != -1):
  168. z = z.strip()
  169. items = z.split(' ')
  170. pidOV = items[0]
  171. #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen)
  172. Popen(["kill", "-TERM", str(pidOV)], stdout=PIPE).communicate()
  173. print("killed openvibe-designer")