# Path: ndlib/models/compartments/Compartment.py
# class Compartiment(object):
#     """
#     """
# 
#     def __init__(self, *args, **kwargs):
#         self.composed = None
#         if 'composed' in args[0]:
#             if isinstance(args[0]['composed'], Compartiment):
#                 self.composed = args[0]['composed']
# 
#     def execute(self, *args, **kwargs):
#         pass
# 
#     def compose(self, *args, **kwargs):
#         if self.composed is not None:
#             return self.composed.execute(*args, **kwargs)
#         else:
#             return True
# 
# class ConfigurationException(Exception):
#     """Configuration Exception"""


from ndlib.models.compartments.Compartment import Compartiment, ConfigurationException
        self.threshold = threshold
        self.trigger = triggering_status

    def execute(self, node, graph, status, status_map, params, *args, **kwargs):
        neighbors = list(graph.neighbors(node))
        test = False

        try:
            directed = graph.directed
        except AttributeError:
            directed = graph.is_directed()

        if directed:
            neighbors = list(graph.predecessors(node))

        if self.trigger is None:
            triggered = 0
        else:
            triggered = len([v for v in neighbors if status[v] == status_map[self.trigger]])

        if len(list(neighbors)) > 0:
            infected_ratio = float(triggered) / len(neighbors)
            if 'threshold' in params['nodes']:
                test = infected_ratio >= params['nodes']['threshold'][node]
            else:
                if self.threshold is not None:
                    test = infected_ratio >= self.threshold
                else:
                    raise ConfigurationException("Threshold not specified")
        if test:

# Path: ndlib/models/compartments/Compartment.py
# class Compartiment(object):
#     """
#     """
# 
#     def __init__(self, *args, **kwargs):
#         self.composed = None
#         if 'composed' in args[0]:
#             if isinstance(args[0]['composed'], Compartiment):
#                 self.composed = args[0]['composed']
# 
#     def execute(self, *args, **kwargs):
#         pass
# 
#     def compose(self, *args, **kwargs):
#         if self.composed is not None:
#             return self.composed.execute(*args, **kwargs)
#         else:
#             return True
# 
# class ConfigurationException(Exception):
#     """Configuration Exception"""


# Path: ndlib/models/compartments/NodeThreshold.py
from ndlib.models.compartments.Compartment import Compartiment, ConfigurationException

        self.threshold = threshold
        self.trigger = triggering_status

    def execute(self, node, graph, status, status_map, params, *args, **kwargs):
        neighbors = list(graph.neighbors(node))
        test = False

        try:
            directed = graph.directed
        except AttributeError:
            directed = graph.is_directed()

        if directed:
            neighbors = list(graph.predecessors(node))

        if self.trigger is None:
            triggered = 0
        else:
            triggered = len([v for v in neighbors if status[v] == status_map[self.trigger]])

        if len(list(neighbors)) > 0:
            infected_ratio = float(triggered) / len(neighbors)
            if 'threshold' in params['nodes']:
                test = infected_ratio >= params['nodes']['threshold'][node]
            else:
                if self.threshold is not None:
                    test = infected_ratio >= self.threshold
                else:
                    raise ConfigurationException("Threshold not specified")
        if test:

            return self.compose(node, graph, status, status_map, params, kwargs)