Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use status bar for retriever update #442

Merged
merged 1 commit into from
Mar 9, 2016

Conversation

ghoshbishakh
Copy link
Contributor

Fixes #397
Use a progress bar while scripts are being downloaded for retriever update

progress = 1
status = "Done...\r\n"
block = int(round(barWidth*progress))
text = "\r[{0}] {1:.2f}%".format("#"*block + "-"*(barWidth-block),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghoshbishakh great work. just a few things to change.
I think we can add Downlaod progress text = "\rDownload Progress: [{0}]

def update_progressbar(progress):
"""Shows progressbar given progress in float
Example: 0.5 for 50%
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the doc string we can remove this Example: 0.5 for 50%
or we wan instead explain how this comes up

"""Shows progressbar given progress in float

accepts a a number between 0 and 1 and it's converted to a float.
a number under 0 represents a 'halt'.
a number at 1 or greater represents 100%
"""

@ghoshbishakh
Copy link
Contributor Author

@henrykironde thank you for taking a look. 😄 I am updating my PR.

@ghoshbishakh ghoshbishakh force-pushed the progressBar branch 2 times, most recently from e048508 to 5cdf0be Compare March 8, 2016 20:45
@ghoshbishakh
Copy link
Contributor Author

@henrykironde I hope that is better

pass
status = ""
if isinstance(progress, int):
progress = float(progress)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about we change the logic and assume that given a number just convert to float, and this case we may not need to check if its int.
so before line 102, we can just say progress = float(progress)

@ghoshbishakh
Copy link
Contributor Author

good call 😄 will update.

@henrykironde
Copy link
Contributor

Modify this to change the length of the progress bar
barWidth = 20

if we go with bar_length or barLenth , people reading the code later may understand easily since the comment is talking about length

@ghoshbishakh
Copy link
Contributor Author

ok sure but actually I am dynamically setting the length of the progressbar later according to the console width. So I think its better to comment that as default bar width?

@henrykironde
Copy link
Contributor

ok that works


def update_progressbar(progress):
"""Shows progressbar given progress in float
accepts a a number between 0 and 1 and it's converted to a float.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after the first line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I did not get that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah in the docstring ok!

@ghoshbishakh ghoshbishakh force-pushed the progressBar branch 2 times, most recently from 1e32126 to c140fef Compare March 8, 2016 21:06
@ghoshbishakh
Copy link
Contributor Author

Did I miss anything?

bar_length = 20
except:
pass
status = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are creating status, then I guess we may include it in line text = "\rDownload Progress:....
or we can remove the creation of status

@ghoshbishakh
Copy link
Contributor Author

@henrykironde cat you take a look at it now?

@henrykironde
Copy link
Contributor

henrykironde commented Mar 9, 2016 via email

@ethanwhite
Copy link
Member

Thanks for this @ghoshbishakh. Overall it looks great.

I have a couple of thoughts/recommendations/questions:

  1. I think we can remove the reporthook function entirely and then get rid of the associated optional argument in the call to urllib.urlretriever.

  2. The docstring for update_progressbar could cleaned up a little (for part an explanation of
    part of the cleanup see number 4 below). E.g.,

    """Show progressbar
    
    Takes a number between 0 and 1 to indicate progress from 0 to 100%.
    
    """
    
  3. Is the initial declaration of bar_length there for cases when determining the
    size of the terminal doesn't work properly? If so then it would be clearer to
    include this in the except. If not, then could you explain a little more about
    what it's accomplishing.

  4. Since update_progressbar shouldn't be getting values < 0 or > 1 I think we can
    probably get rid of lines 105-112, and 116-117 unless I'm
    missing something. If you were thinking about checking for bad values we could use
    an assert statement and throw an exception if the value isn't between 0 and 1.

  5. I don't understand why it's necessary to call update_progressbar at both the
    beginning and end of the main for loop. Could you explain a little be more about
    why we need both of them.

@ghoshbishakh
Copy link
Contributor Author

@ethanwhite thanks for the suggestions 😄

  1. I am removing the reporthook
  2. Updated docstring
  3. Yes it was there for cases where determination of console size fails. I have put it in the except.
  4. I was thinking that later may be we could use statuses like halt for any exception or like that. But yes its better to keep it simple
  5. Actually the 0% is not displayed if we don't call it first once. So I will call it outside the for loop first then so that it isn't repeated uselessly?

Fixes weecology#397
Use a progress bar while scripts are being downloaded for retriever update

Change progress bar text

Change update_progressbar description
@ghoshbishakh
Copy link
Contributor Author

@ethanwhite I have pushed with the required changes

@henrykironde
Copy link
Contributor

great work @ghoshbishakh

henrykironde added a commit that referenced this pull request Mar 9, 2016
Use status bar for retriever update
@henrykironde henrykironde merged commit f1dfbbd into weecology:master Mar 9, 2016
@ghoshbishakh ghoshbishakh deleted the progressBar branch March 9, 2016 16:12
@ghoshbishakh
Copy link
Contributor Author

@henrykironde thanks! 😄
Can you guide me a bit here:
numfocus/gsoc#105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants