4 ## Copyright (c) 2010-2017 Intel Corporation
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
10 ## http://www.apache.org/licenses/LICENSE-2.0
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
23 def __init__(self, limit, fieldNames = [], overallETA = True):
24 self._fieldNames = fieldNames;
27 self._prevProgress = 0;
29 self._progressSetCount = 0;
31 self._overallETA = overallETA;
33 def setProgress(self, progress, fieldValues = []):
34 self._fieldValues = fieldValues;
35 if (self._overallETA == True):
36 self._progress = progress
38 if (self._progressSetCount == 0):
39 self._prevProgress = self._progress;
40 self._prevTime = self._time;
42 self._prevProgress = self._progress;
43 self._prevTime = self._time;
44 self._progress = progress;
46 self._progressSetCount += 1
48 def incrProgress(self):
49 self.setProgress(self._progress + 1);
53 ret += str(self._getETA()) + " seconds left"
54 for f,v in zip(self._fieldNames, self._fieldValues):
55 ret += ", %s=%s" % (str(f),str(v))
59 if (self._progressSetCount < 2):
61 diff = self._progress - self._prevProgress;
62 t_diff = Decimal(self._time - self._prevTime);
63 if (t_diff < 0.001 or diff <= 0):
65 rate = Decimal(diff)/t_diff
66 remaining = Decimal(self._limit - self._progress);
67 return round(remaining/rate, 2);