Publishing 2019 R2 content (#223)
[platform/upstream/dldt.git] / inference-engine / ie_bridges / python / sample / benchmark_app / benchmark / utils / progress_bar.py
1 """
2  Copyright (C) 2018-2019 Intel Corporation
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 implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 """
16
17 from progress.bar import Bar
18
19 class ProgressBar:
20     def __init__(self, total_num, stream_output=False, progress_enabled=False):
21         self.stream_output = stream_output
22         self.is_finished = True
23         self.progress_enabled = progress_enabled
24         self.reset(total_num)
25
26     def add_progress(self, num):
27         self.is_finished = False
28         if self.progress_enabled:
29            for i in range(num):
30               self.bar.next()
31               if self.stream_output:
32                   print()
33
34     def finish(self, num = 0):
35         if (num > 0):
36             self.add_progress(num)
37
38         self.is_finished = True
39         if self.progress_enabled:
40             self.bar.finish()
41             print()
42
43     def reset(self, total_num):
44         if self.progress_enabled:
45             self.bar = Bar('Progress:', max = total_num, fill = '.', suffix='%(percent).2f%%')
46
47     def new_bar(self, total_num):
48         if self.is_finished:
49             self.reset(total_num)
50         else:
51            raise Exception("Cannot create a new bar. Current bar is still in progress")