Passed
Push — master ( 44bd28...268666 )
by Simon
03:57
created

ResultsManager._obj_func_results()   A

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nop 2
dl 0
loc 13
rs 9.95
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
class ResultsManager:
7
    def __init__(self, objective_function, conv):
8
        super().__init__()
9
        self.objective_function = objective_function
10
        self.conv = conv
11
12
        self.results_list = []
13
14
    def _obj_func_results(self, para):
15
        results = self.objective_function(para)
16
17
        if isinstance(results, tuple):
18
            score = results[0]
19
            results_dict = results[1]
20
        else:
21
            score = results
22
            results_dict = {}
23
24
        results_dict["score"] = score
25
26
        return results_dict
27
28
    def score(self, pos):
29
        value = self.conv.position2value(pos)
30
        para = self.conv.value2para(value)
31
        results_dict = self._obj_func_results(para)
32
33
        self.results_list.append({**results_dict, **para})
34
35
        return results_dict["score"]
36
37