Passed
Push — master ( 4bb259...06915f )
by Simon
04:09
created

ProgressBar.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
from tqdm.auto import tqdm
6
7
8
class ProgressBar:
9
    def __init__(self):
10
        self.best_since_iter = 0
11
12
    def init_p_bar(self, nth_process, n_iter, obj_func):
13
        self._tqdm = tqdm(**self._tqdm_dict(nth_process, n_iter, obj_func))
14
15
    def update_p_bar(self, n, score_best):
16
        self._tqdm.update(n)
17
        self._tqdm.set_postfix(
18
            best_score=str(score_best), best_since_iter=self.best_since_iter
19
        )
20
21
    def close_p_bar(self):
22
        self._tqdm.close()
23
24
    def _tqdm_dict(self, nth_process, n_iter, obj_func):
25
        """Generates the parameter dict for tqdm in the iteration-loop of each optimizer"""
26
        return {
27
            "total": n_iter,
28
            "desc": "Process " + str(nth_process) + " -> " + obj_func.__name__,
29
            "position": nth_process,
30
            "leave": True,
31
        }
32
33