Jelajahi Sumber

order analyser get the loaded brain instead of the file path

nico 8 tahun lalu
induk
melakukan
dd679d4440
2 mengubah file dengan 11 tambahan dan 9 penghapusan
  1. 8 1
      core/MainController.py
  2. 3 8
      core/OrderAnalyser.py

+ 8 - 1
core/MainController.py

@@ -5,6 +5,7 @@ import random
 from core import AudioPlayer
 from core import Utils
 from core.ConfigurationManager import SettingLoader
+from core.ConfigurationManager.BrainLoader import BrainLoader
 from core.OrderAnalyser import OrderAnalyser
 from core.OrderListener import OrderListener
 from core.TriggerLauncher import TriggerLauncher
@@ -22,6 +23,12 @@ class MainController:
         # get global configuration
         self.settings = SettingLoader.get_settings()
 
+        # load the brain
+        if brain_file is None:
+            self.brain = BrainLoader.get_brain()
+        else:
+            self.brain = BrainLoader.get_brain(file_path=brain_file)
+
         # run the api if the user want it
         if self.settings.rest_api.active:
             Utils.print_info("Starting REST API Listening port: %s" % self.settings.rest_api.port)
@@ -60,7 +67,7 @@ class MainController:
         Receive an order, try to retreive it in the brain.yml to launch to attached plugins
         :return:
         """
-        order_analyser = OrderAnalyser(order, main_controller=self, brain_file=self.brain_file)
+        order_analyser = OrderAnalyser(order, main_controller=self, brain=self.brain)
         order_analyser.start()
         # restart the trigger when the order analyser has finish his job
         Utils.print_info("Waiting for trigger detection")

+ 3 - 8
core/OrderAnalyser.py

@@ -3,7 +3,6 @@ import re
 from collections import Counter
 
 from core.Utils import Utils
-from core.ConfigurationManager.BrainLoader import BrainLoader
 from core.Models import Order
 from core.NeuroneLauncher import NeuroneLauncher
 
@@ -14,21 +13,18 @@ logger = logging.getLogger("kalliope")
 
 
 class OrderAnalyser:
-    def __init__(self, order, main_controller=None, brain_file=None):
+    def __init__(self, order, main_controller=None, brain=None):
         """
         Class used to load brain and run neuron attached to the received order
         :param order: spelt order
         :param main_controller
-        :param brain_file: To override the default brain.yml file
+        :param brain: loaded brain
         """
         self.main_controller = main_controller
         self.order = order
         if isinstance(self.order, str):
             self.order = order.decode('utf-8')
-        if brain_file is None:
-            self.brain = BrainLoader.get_brain()
-        else:
-            self.brain = BrainLoader.get_brain(file_path=brain_file)
+        self.brain = brain
         logger.debug("OrderAnalyser, Received order: %s" % self.order)
 
     def start(self):
@@ -78,7 +74,6 @@ class OrderAnalyser:
                             else:
                                 Utils.print_danger("A problem has been found in the Synapse.")
 
-
         if not synapses_found:
             Utils.print_info("No synapse match the captured order: %s" % self.order)