implementing terminal progressbar with data

This is the place for queries that don't fit in any of the other categories.

implementing terminal progressbar with data

Postby metulburr » Wed Mar 27, 2013 2:08 am

I have seen examples of progressbars. I might be retared now, but i cant seem to figure out how to implement the progress bar with the data that is pbar is suppose to represent. One of those "dah" moments!

The original code uses a timestamp as the start of the progress bar, and different points of time as the end of numerous progress bars. (8 hours, 24 hours, 48 hours, one month, etc.). My idea was to have a separate progress bar for each point in time of

This is the code i whipped up for a small example.
Code: Select all
import time
import sys

start = time.time()
end = start + 60

def progressbar_disp_full():
    display_char = '#'
    for num in range(101):
        spacer = int(33-int(num/3)) * ' '
        filler = int(num/3)         * display_char
        sys.stdout.write("\r[{0}{1}] {2}%".format(filler, spacer, num))

So because i havent yet used a progress bar, and i feel like my brain is not working 100% lately: The range(101) gets the bar with from 0-100%, but how would you implement the start and end into the pbar. I have yet to see an example to view that hasnt just used time.sleep(1) to increment the pbar, so that might also be a part of my problem.
we will be moving to on October 1 2016
more details here
User avatar
Posts: 2242
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: implementing terminal progressbar with data

Postby setrofim » Wed Mar 27, 2013 6:32 am

You can adapt the following to your needs:
Code: Select all
import sys
import time

class SimpleProgressBar(object):

    def __init__(self, max_value, size=80):
        self.max_value = max_value
        self.size = size
        self.value = 0

    def draw(self):
        fill_size = self.size * self.value // self.max_value
        if fill_size > self.size - 2:
            fill_size = self.size - 2
        blank_size = self.size - fill_size -2
        bar = ''.join(['[', '=' * fill_size,
                            ' ' * blank_size, ']'])

        sys.stdout.write('\b' * len(bar))

    def step(self, step_size=1):
        self.value += step_size

    def end(self):

if __name__ == '__main__':
    pbar = SimpleProgressBar(10)
    for i in xrange(10):
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 5 guests