Browse Source

[Feature] Add geolocation signal

First draft
ThiBuff 7 years ago
parent
commit
442a8acfc4

+ 11 - 0
kalliope/signals/geolocation/README.md

@@ -0,0 +1,11 @@
+# Geolocalisation
+
+TODO
+
+## Synopsis
+
+
+## Options
+
+
+## Synapses example

+ 1 - 0
kalliope/signals/geolocation/__init__.py

@@ -0,0 +1 @@
+from .geolocation import Geolocation

+ 48 - 0
kalliope/signals/geolocation/geolocation.py

@@ -0,0 +1,48 @@
+import logging
+from threading import Thread
+
+from kalliope.core import Utils
+from kalliope.core.ConfigurationManager import BrainLoader
+
+logging.basicConfig()
+logger = logging.getLogger("kalliope")
+
+
+class Geolocation(Thread):
+
+    def __init__(self):
+        super(Geolocation, self).__init__()
+        Utils.print_info('Init Geolocation')
+        self.brain = BrainLoader().get_brain()
+
+    def run(self):
+        logger.debug("[Geolocalisation] Loading ...")
+        self.list_synapses_with_geolocalion = self._get_list_synapse_with_geolocation(self.brain)
+
+    @classmethod
+    def _get_list_synapse_with_geolocation(cls, brain):
+        """
+        return the list of synapse that use geolocation as signal in the provided brain
+        :param brain: Brain object that contain all synapses loaded
+        :type brain: Brain
+        :return: list of synapse that use geolocation as signal
+        """
+        for synapse in brain.synapses:
+            for signal in synapse.signals:
+                # if the signal is an event we add it to the task list
+                if signal.name == "geolocation":
+                    if not cls._check_geolocation(signal.parameters):
+                        logger.debug("[Geolocation] The signal is missing mandatory parameters, check documentation")
+                    else:
+                        yield synapse
+
+    @staticmethod
+    def _check_geolocation(parameters):
+        """
+        receive a dict of parameter from a geolocation signal and them
+        :param parameters: dict of parameters
+        :return: True if parameters are valid
+        """
+        # check mandatory parameters
+        mandatory_parameters = ["latitude", "longitude", "radius"]
+        return all(key in parameters for key in mandatory_parameters)

+ 17 - 0
kalliope/signals/geolocation/model.py

@@ -0,0 +1,17 @@
+class Geolocation(object):
+
+    def __init__(self, latitude, longitude, radius):
+        self.latitude = latitude
+        self.longitude = longitude
+        self.radius = radius
+
+    def __str__(self):
+        return str(self.serialize())
+
+    def __eq__(self, other):
+        """
+        This is used to compare 2 objects
+        :param other:
+        :return:
+        """
+        return self.__dict__ == other.__dict__

+ 0 - 0
kalliope/signals/geolocation/tests/__init__.py


+ 9 - 0
kalliope/signals/geolocation/tests/test_geolocalisation.py

@@ -0,0 +1,9 @@
+import unittest
+
+
+class Test_Geolocation(unittest.TestCase):
+    pass
+
+
+if __name__ == '__main__':
+    unittest.main()