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

Display consistent format for job runtime #10504

Merged
merged 13 commits into from
Oct 23, 2020

Conversation

kxk302
Copy link
Contributor

@kxk302 kxk302 commented Oct 21, 2020

This fixes the formatting reported in #10473

@kxk302
Copy link
Contributor Author

kxk302 commented Oct 21, 2020

@jmchilton or @dannon
Could you please take a look at this PR? Seems the issue can be fixed in backend only.
Thanks

@galaxybot galaxybot added this to the 21.01 milestone Oct 21, 2020
@jdavcs
Copy link
Member

jdavcs commented Oct 21, 2020

Can we also have a unit test for seconds_to_str()? Also, maybe handle singular/plural; and also days? For example:

assert '1 second' == seconds_to_str(1)
assert '2 seconds' == seconds_to_str(2)
assert '1 minute' == seconds_to_str(60)
assert '1 minute 1 second' == seconds_to_str(61)
assert '1 minute 2 seconds' == seconds_to_str(62)
assert '2 minutes 1 second' == seconds_to_str(121)
etc...

If this is too annoying to handle, I think there might be a library for this.

@dannon
Copy link
Member

dannon commented Oct 21, 2020

@kxk302 This looks great to me -- that was definitely a bug before, good catch. Do you want to rebase this branch to drop the other commits related to the vscode config?

@kxk302
Copy link
Contributor Author

kxk302 commented Oct 21, 2020

Can we also have a unit test for seconds_to_str()? Also, maybe handle singular/plural; and also days? For example:

assert '1 second' == seconds_to_str(1)
assert '2 seconds' == seconds_to_str(2)
assert '1 minute' == seconds_to_str(60)
assert '1 minute 1 second' == seconds_to_str(61)
assert '1 minute 2 seconds' == seconds_to_str(62)
assert '2 minutes 1 second' == seconds_to_str(121)
etc...

If this is too annoying to handle, I think there might be a library for this.

I can add unit tests for sure, probably tomorrow though.

@kxk302
Copy link
Contributor Author

kxk302 commented Oct 21, 2020

@kxk302 This looks great to me -- that was definitely a bug before, good catch. Do you want to rebase this branch to drop the other commits related to the vscode config?

I can cherry-pick this change into my other branch, so we'd have 1 PR. Would that work?

@dannon
Copy link
Member

dannon commented Oct 21, 2020

@kxk302 I think it's fine to leave this as a separate PR since it's totally unrelated. I'd just do a simple git rebase -i upstream/dev, drop the preceding 4 commits from the rebase plan, and it should be good to go. Then you force-push over this branch if it looks good, and the PR will auto-update.

@kxk302
Copy link
Contributor Author

kxk302 commented Oct 21, 2020

@kxk302 I think it's fine to leave this as a separate PR since it's totally unrelated. I'd just do a simple git rebase -i upstream/dev, drop the preceding 4 commits from the rebase plan, and it should be good to go. Then you force-push over this branch if it looks good, and the PR will auto-update.

Got it. Sorry I become slower near the end of the day :)

lib/galaxy/job_metrics/formatting.py Outdated Show resolved Hide resolved
lib/galaxy/job_metrics/formatting.py Outdated Show resolved Hide resolved
lib/galaxy/job_metrics/formatting.py Outdated Show resolved Hide resolved
@kxk302
Copy link
Contributor Author

kxk302 commented Oct 22, 2020

@dannon Updated string formatting

@dannon
Copy link
Member

dannon commented Oct 22, 2020

@kxk302 Thanks. Next time you can just 'accept suggestions' (in batch if there are multiple), too, and it'll make a commit for you, also crediting the suggester.

@mvdbeek mvdbeek changed the title Papercut 10473 Display consistent format for job runtime Oct 22, 2020
@kxk302
Copy link
Contributor Author

kxk302 commented Oct 22, 2020

Added unit tests.

@kxk302
Copy link
Contributor Author

kxk302 commented Oct 22, 2020

The only check failing seems to client test (ToolsView.test.js). I don't think this is related to my code change. Could someone please verify and if so merge this? Thanks.

Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
@jdavcs
Copy link
Member

jdavcs commented Oct 22, 2020

@kxk302 thank you for adding the test! See my inline comment. Plural vs. singular - up to you. I'm OK either way.

@kxk302
Copy link
Contributor Author

kxk302 commented Oct 22, 2020

@kxk302 thank you for adding the test! See my inline comment. Plural vs. singular - up to you. I'm OK either way.

@ic4f I updated the method and the test to handle singular/plural seconds/minutes. Made the method a bit convoluted, but I guess nobody can pick on the grammar :)

@@ -12,9 +12,25 @@ def seconds_to_str(value):
"""Convert seconds to a simple simple string describing the amount of time."""
mins, secs = divmod(value, 60)
hours, mins = divmod(mins, 60)
if value < 60:

if value == 0:
Copy link
Member

Choose a reason for hiding this comment

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

Great! As a suggestion, you could simplify this, if you like. It's just 3 cases: value < 60; if not then value < 3600; and the rest - i.e., if/elif/else. As for the s suffix - you could pre-calculate it: it's '' or 's' for secs/mins/hours depending on whether they == 1.

lib/galaxy/job_metrics/formatting.py Outdated Show resolved Hide resolved
lib/galaxy/job_metrics/formatting.py Outdated Show resolved Hide resolved
lib/galaxy/job_metrics/formatting.py Outdated Show resolved Hide resolved
kxk302 and others added 4 commits October 22, 2020 18:56
Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
Copy link
Member

@jdavcs jdavcs left a comment

Choose a reason for hiding this comment

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

Thank you for making all the changes, looks great!

@nsoranzo nsoranzo merged commit a6bd4e4 into galaxyproject:dev Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants