MCPcopy
hub / github.com/apache/caldera / Objective

Class Objective

app/objects/c_objective.py:31–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30
31class Objective(FirstClassObjectInterface, BaseObject):
32
33 schema = ObjectiveSchema()
34
35 @property
36 def unique(self):
37 return self.hash('%s' % self.id)
38
39 @property
40 def percentage(self):
41 if len(self.goals) > 0:
42 return 100 * (len([g for g in self.goals if g.satisfied() is True])/len(self.goals))
43 return 0
44
45 def completed(self, facts=None):
46 return not any(x.satisfied(facts) is False for x in self.goals)
47
48 def __init__(self, id='', name='', description='', goals=None):
49 super().__init__()
50 self.id = id if id else str(uuid.uuid4())
51 self.name = name
52 self.description = description
53 self.goals = goals if goals else []
54
55 def store(self, ram):
56 existing = self.retrieve(ram['objectives'], self.unique)
57 if not existing:
58 ram['objectives'].append(self)
59 return self.retrieve(ram['objectives'], self.unique)
60 existing.update('name', self.name)
61 existing.update('description', self.description)
62 existing.update('goals', self.goals)
63 return existing

Callers 9

setup_empty_operationFunction · 0.90
test_goals_satisfiedMethod · 0.90
test_goals_percentMethod · 0.90
setup_rest_svc_testFunction · 0.90
test_objectiveFunction · 0.90
build_objectiveMethod · 0.85

Calls 1

ObjectiveSchemaClass · 0.85

Tested by 7

setup_empty_operationFunction · 0.72
test_goals_satisfiedMethod · 0.72
test_goals_percentMethod · 0.72
setup_rest_svc_testFunction · 0.72
test_objectiveFunction · 0.72