Passed
Pull Request — master (#110)
by
unknown
01:35
created

hyperactive.optimizers.pipelines.optimizer_attributes   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 65
Duplicated Lines 87.69 %

Importance

Changes 0
Metric Value
eloc 44
dl 57
loc 65
rs 10
c 0
b 0
f 0
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
C OptimizerAttributes._add_result_attributes() 47 47 11
A OptimizerAttributes.__init__() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import pandas as pd
6
7
8 View Code Duplication
class OptimizerAttributes:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
    def __init__(self):
10
        self.best_para = None
11
        self.best_score = None
12
        self.best_since_iter = None
13
        self.eval_times = None
14
        self.iter_times = None
15
        self.search_data = None
16
        self.random_seed = None
17
18
    def _add_result_attributes(
19
        self,
20
        best_para,
21
        best_score,
22
        best_since_iter,
23
        eval_times,
24
        iter_times,
25
        search_data,
26
        random_seed,
27
    ):
28
        if self.best_para is None:
29
            self.best_para = best_para
30
        else:
31
            if best_score > self.best_score:
32
                self.best_para = best_para
33
34
        if self.best_score is None:
35
            self.best_score = best_score
36
        else:
37
            if best_score > self.best_score:
38
                self.best_score = best_score
39
40
        if self.best_since_iter is None:
41
            self.best_since_iter = best_since_iter
42
        else:
43
            if best_score > self.best_score:
44
                self.best_since_iter = best_since_iter
45
46
        if self.eval_times is None:
47
            self.eval_times = eval_times
48
        else:
49
            self.eval_times = self.eval_times + eval_times
50
51
        if self.iter_times is None:
52
            self.iter_times = iter_times
53
        else:
54
            self.iter_times = self.iter_times + eval_times
55
56
        if self.search_data is None:
57
            self.search_data = search_data
58
        else:
59
            self.search_data = pd.concat(
60
                [self.search_data, search_data], ignore_index=True
61
            )
62
63
        if self.random_seed is None:
64
            self.random_seed = random_seed
65