2 * svrt is the ``Synthetic Visual Reasoning Test'', an image
3 * generator for evaluating classification performance of machine
4 * learning systems, humans and primates.
6 * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of svrt.
11 * svrt is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 3 as
13 * published by the Free Software Foundation.
15 * svrt is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with selector. If not, see <http://www.gnu.org/licenses/>.
26 #include "progress_bar.h"
28 ProgressBar::ProgressBar() : _visible(false), _value_max(-1) { }
30 void ProgressBar::set_visible(bool visible) {
34 void ProgressBar::init(ostream *out, scalar_t value_max) {
35 _value_max = value_max;
41 void ProgressBar::refresh(ostream *out, scalar_t value) {
42 if(_visible && _value_max > 0) {
43 int step = int((value * 40) / _value_max);
45 if(step > _last_step) {
46 char buffer[width + 1], date_buffer[buffer_size];
48 j = sprintf(buffer, "Timer: ");
50 for(i = 0; i < step; i++) buffer[j + i] = 'X';
51 for(; i < 40; i++) buffer[j + i] = (i%4 == 0) ? '+' : '-';
54 time_t current_time; time(¤t_time);
55 int rt = int(((current_time - _initial_time)/scalar_t(value)) * scalar_t(_value_max - value));
62 strftime(date_buffer, buffer_size, "%a %b %e %H:%M", localtime(¤t));
63 j += snprintf(buffer + j, width - j - 1, " (end ~ %s)", date_buffer);
65 int hours = rt/3600, min = (rt%3600)/60, sec = rt%60;
67 j += snprintf(buffer + j, width - j - 1, " (~%dh%dmin left)", hours, min);
69 j += snprintf(buffer + j, width - j - 1, " (~%dmin%ds left)", min, sec);
71 j += snprintf(buffer + j, width - j - 1, " (~%ds left)", sec);
75 for(; j < width; j++) buffer[j] = ' ';
77 (*out) << buffer << "\r";
84 void ProgressBar::finish(ostream *out) {
86 char buffer[width + 1];
88 time_t current_time; time(¤t_time);
89 int rt = int(current_time - _initial_time);
90 int min = rt/60, sec = rt%60;
91 j = sprintf(buffer, "Timer: Total %dmin%ds", min, sec);
92 for(; j < width; j++) buffer[j] = ' ';
94 (*out) << buffer << endl;