Coverage for watcher/api/controllers/v1/efficacy_indicator.py: 100%
22 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2016 b<>com
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
17"""
18An efficacy indicator is a single value that gives an indication on how the
19:ref:`solution <solution_definition>` produced by a given :ref:`strategy
20<strategy_definition>` performed. These efficacy indicators are specific to a
21given :ref:`goal <goal_definition>` and are usually used to compute the
22:ref:`global efficacy <efficacy_definition>` of the resulting :ref:`action plan
23<action_plan_definition>`.
25In Watcher, these efficacy indicators are specified alongside the goal they
26relate to. When a strategy (which always relates to a goal) is executed, it
27produces a solution containing the efficacy indicators specified by the goal.
28This solution, which has been translated by the :ref:`Watcher Planner
29<watcher_planner_definition>` into an action plan, will see its indicators and
30global efficacy stored and would now be accessible through the :ref:`Watcher
31API <archi_watcher_api_definition>`.
32"""
34import numbers
36from wsme import types as wtypes
38from watcher.api.controllers import base
39from watcher import objects
42class EfficacyIndicator(base.APIBase):
43 """API representation of a efficacy indicator.
45 This class enforces type checking and value constraints, and converts
46 between the internal object model and the API representation of an
47 efficacy indicator.
48 """
50 name = wtypes.wsattr(wtypes.text, mandatory=True)
51 """Name of this efficacy indicator"""
53 description = wtypes.wsattr(wtypes.text, mandatory=False)
54 """Description of this efficacy indicator"""
56 unit = wtypes.wsattr(wtypes.text, mandatory=False)
57 """Unit of this efficacy indicator"""
59 value = wtypes.wsattr(numbers.Number, mandatory=True)
60 """Value of this efficacy indicator"""
62 def __init__(self, **kwargs):
63 super(EfficacyIndicator, self).__init__()
65 self.fields = []
66 fields = list(objects.EfficacyIndicator.fields)
67 for field in fields:
68 # Skip fields we do not expose.
69 if not hasattr(self, field):
70 continue
71 self.fields.append(field)
72 setattr(self, field, kwargs.get(field, wtypes.Unset))