Passed
Push — master ( 7ebd63...8bd9a3 )
by Simon
06:11
created

ResultsManager.search_data()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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