Neuron.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. class Neuron(object):
  2. """
  3. This Class is representing a Neuron which is corresponding to an action to perform.
  4. .. note:: Neurons are defined in the brain file
  5. """
  6. def __init__(self, name=None, parameters=None):
  7. self.name = name
  8. self.parameters = parameters
  9. def serialize(self):
  10. """
  11. This method allows to serialize in a proper way this object
  12. :return: A dict of name and parameters
  13. :rtype: Dict
  14. """
  15. return {
  16. 'name': self.name,
  17. 'parameters': self.parameters
  18. }
  19. def __str__(self):
  20. """
  21. Return a string that describe the neuron. If a parameter contains the word "password",
  22. the output of this parameter will be masked in order to not appears in clean in the console
  23. :return: string description of the neuron
  24. """
  25. returned_dict = {
  26. 'name': self.name,
  27. 'parameters': self.parameters
  28. }
  29. cleaned_parameters = dict()
  30. for key, value in self.parameters.items():
  31. if "password" in key:
  32. cleaned_parameters[key] = "*****"
  33. else:
  34. cleaned_parameters[key] = value
  35. returned_dict["parameters"] = cleaned_parameters
  36. return str(returned_dict)
  37. def __eq__(self, other):
  38. """
  39. This is used to compare 2 objects
  40. :param other:
  41. :return:
  42. """
  43. return self.__dict__ == other.__dict__