All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProgressTimer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/progress/ProgressTimer.cpp
22 
23  \brief The ProgressTimer is a utility class that can be used to calculate the estimated time to finish a task.
24 */
25 
26 // TerraLib
27 #include "../StringUtils.h"
28 #include "../Translator.h"
29 #include "ProgressTimer.h"
30 
32  : m_totalSteps(totalSteps),
33  m_count(0),
34  m_startTime(0),
35  m_remainingTime(0.0),
36  m_speedTime(0.0)
37 {
38 }
39 
41 {
42 }
43 
45 {
46 // start time
47  time(&m_startTime);
48 
49  m_count = 0;
50 }
51 
53 {
54  ++m_count;
55 
56  time_t curtime;
57 
58  // current time
59  time(&curtime);
60 
61  // difference in seconds
62  double diffInSec = difftime(curtime, m_startTime);
63 
64  m_speedTime = (static_cast<double>(m_count) / diffInSec);
65 
66  int remainingSteps = m_totalSteps - m_count;
67 
68  double remainingTimeInSec = (static_cast<double>(remainingSteps) / m_speedTime);
69 
70  m_remainingTime = remainingTimeInSec / 60.0;
71 }
72 
74 {
75  m_totalSteps = totalSteps;
76 }
77 
79 {
80  return m_remainingTime;
81 }
82 
84 {
85  return m_speedTime;
86 }
87 
89 {
90  std::string strTime = "";
91 
92  if(m_remainingTime < 1.0)
93  {
94  strTime = TR_COMMON("Remaining Time: Less than one minute");
95  }
96  else
97  {
98  strTime = TR_COMMON("Remaining Time: ") + te::common::Convert2String(m_remainingTime, 1);
99  strTime += TR_COMMON(" minute(s) - Speed: ") + te::common::Convert2String(m_speedTime, 2);
100  strTime += TR_COMMON(" Steps/Second");
101  }
102 
103  return strTime;
104 }
ProgressTimer(int totalSteps)
It initializes a ProgressTimer.
void tick()
Define a new step process evolution.
std::string getMessage()
Get the information about the evolution of the process.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:51
#define TR_COMMON(message)
It marks a string in order to get translated. This is the mark used in the Common module of TerraLib...
Definition: Config.h:173
void setTotalSteps(int totalSteps)
Set the total steps.
The ProgressTimer is a utility class that can be used to calculate the estimated time to finish a tas...
double getRemainingTimeInMin() const
Function used to get the remaining time to end the process.
void start()
Start the internal timer.
double getSpeedTimeInSec() const
Function used to get the speed time.