Browse Source

synapse lancher do its job instead of the main controller

nico 8 years ago
parent
commit
32adafeb6c

+ 1 - 23
kalliope/core/MainController.py

@@ -196,29 +196,7 @@ class MainController:
         Start the order analyser with the caught order to process
         Start the order analyser with the caught order to process
         """
         """
         logger.debug("order in analysing_order_thread %s" % self.order_to_process)
         logger.debug("order in analysing_order_thread %s" % self.order_to_process)
-        no_synapse_match = False
-        if self.order_to_process is not None:   # maybe we have received a null audio from STT engine
-            oa2 = OrderAnalyser2.get_matching_synapse(order=self.order_to_process, brain=self.brain)
-
-            # oa2 contains the list Named tuple of synapse to run with the associated order that has matched
-            # for each synapse, get neurons, et for each neuron, get parameters
-            if not oa2:
-                no_synapse_match = True
-            else:
-                # the order match one or more synapses
-                for tuple_el in oa2:
-                    logger.debug("Get parameter for %s " % tuple_el.synapse.name)
-                    parameters = NeuronParameterLoader.get_parameters(synapse_order=tuple_el.order,
-                                                                      user_order=self.order_to_process).next()
-                    # start the neuron list
-                    NeuronLauncher.start_neuron_list(neuron_list=tuple_el.synapse.neurons,
-                                                     parameters_dict=parameters)
-        else:
-            no_synapse_match = True
-
-        if no_synapse_match:  # then run the default synapse
-            if self.settings.default_synapse is not None:
-                SynapseLauncher.start_synapse(name=self.settings.default_synapse, brain=self.brain)
+        SynapseLauncher.run_matching_synapse_or_default(self.order_to_process, self.brain, self.settings)
 
 
         # return to the state "unpausing_trigger"
         # return to the state "unpausing_trigger"
         self.unpause_trigger()
         self.unpause_trigger()

+ 1 - 19
kalliope/core/RestAPI/FlaskAPI.py

@@ -258,25 +258,7 @@ class FlaskAPI(threading.Thread):
         :return:
         :return:
         """
         """
         logger.debug("order to process %s" % order)
         logger.debug("order to process %s" % order)
-        if order is not None:  # maybe we have received a null audio from STT engine
-            synapses_launched = list()
-
-            oa2 = OrderAnalyser2.get_matching_synapse(order=order, brain=self.brain)
-
-            # oa2 contains the list Named tuple of synapse to run with the associated order that has matched
-            # for each synapse, get neurons, et for each neuron, get parameters
-            for tuple_el in oa2:
-                logger.debug("Get parameter for %s " % tuple_el.synapse.name)
-                parameters = NeuronParameterLoader.get_parameters(synapse_order=tuple_el.order,
-                                                                  user_order=order).next()
-                # start the neuron list
-                synapses_launched = NeuronLauncher.start_neuron_list(neuron_list=tuple_el.synapse.neurons,
-                                                                     parameters_dict=parameters)
-            self.launched_synapses = synapses_launched
-        else:
-            if self.settings.default_synapse is not None:
-                SynapseLauncher.start_synapse(name=self.settings.default_synapse, brain=self.brain)
-                self.launched_synapses = self.brain.get_synapse_by_name(synapse_name=self.settings.default_synapse)
+        SynapseLauncher.run_matching_synapse_or_default(order, self.brain, self.settings)
 
 
         # this boolean will notify the main process that the order have been processed
         # this boolean will notify the main process that the order have been processed
         self.order_analyser_return = True
         self.order_analyser_return = True

+ 34 - 0
kalliope/core/SynapseLauncher.py

@@ -1,4 +1,12 @@
+import logging
+
 from kalliope.core.NeuronLauncher import NeuronLauncher
 from kalliope.core.NeuronLauncher import NeuronLauncher
+from kalliope.core.NeuronParameterLoader import NeuronParameterLoader
+from kalliope.core.OrderAnalyser2 import OrderAnalyser2
+
+
+logging.basicConfig()
+logger = logging.getLogger("kalliope")
 
 
 
 
 class SynapseNameNotFound(Exception):
 class SynapseNameNotFound(Exception):
@@ -41,3 +49,29 @@ class SynapseLauncher(object):
         for neuron in synapse.neurons:
         for neuron in synapse.neurons:
             NeuronLauncher.start_neuron(neuron)
             NeuronLauncher.start_neuron(neuron)
         return True
         return True
+
+    @classmethod
+    def run_matching_synapse_or_default(cls, order_to_process, brain, settings):
+        no_synapse_match = False
+        if order_to_process is not None:  # maybe we have received a null audio from STT engine
+            oa2 = OrderAnalyser2.get_matching_synapse(order=order_to_process, brain=brain)
+
+            # oa2 contains the list Named tuple of synapse to run with the associated order that has matched
+            # for each synapse, get neurons, et for each neuron, get parameters
+            if not oa2:
+                no_synapse_match = True
+            else:
+                # the order match one or more synapses
+                for tuple_el in oa2:
+                    logger.debug("Get parameter for %s " % tuple_el.synapse.name)
+                    parameters = NeuronParameterLoader.get_parameters(synapse_order=tuple_el.order,
+                                                                      user_order=order_to_process).next()
+                    # start the neuron list
+                    NeuronLauncher.start_neuron_list(neuron_list=tuple_el.synapse.neurons,
+                                                     parameters_dict=parameters)
+        else:
+            no_synapse_match = True
+
+        if no_synapse_match:  # then run the default synapse
+            if settings.default_synapse is not None:
+                SynapseLauncher.start_synapse(name=settings.default_synapse, brain=brain)