LonelinessSuicideEvent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _has_friends_with_beans() 0 10 4
A _prepare() 0 4 2
1
from synergine.core.exceptions import NotConcernedEvent
2
from tests.src.event.TestEvent import TestEvent
3
from tests.src.cst import BEANS, COMPUTABLE
4
from tests.src.TestSimulation import TestSimulation
5
6
7
class LonelinessSuicideEvent(TestEvent):
8
9
    def _prepare(self, object_id, context, parameters={}):
10
        if self._has_friends_with_beans(context):
11
            raise NotConcernedEvent()
12
        return parameters
13
14
    @staticmethod
15
    def _has_friends_with_beans(context):
16
        friends_with_beans_count = 0
17
        for friend_id in context.metas.list.get(TestSimulation.STATE, COMPUTABLE):
18
            friend_beans = context.metas.value.get(BEANS, friend_id)
19
            if friend_beans > 1:
20
                friends_with_beans_count += 1
21
        if friends_with_beans_count == 0:
22
            return False
23
        return True
24