Skip to content

Commit

Permalink
Fix #1339
Browse files Browse the repository at this point in the history
Add in missing -dt term so ETA counts down correctly :)
  • Loading branch information
sneakers-the-rat committed Oct 27, 2023
1 parent 04e7c20 commit 5bfd05d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dandi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def agg_done(self, done_sizes: Iterator[int]) -> List[str]:
and self.items_summary.size != 0
):
dt = time.time() - self.items_summary.t0
more_time = dt / r if r != 1 else 0
more_time = (dt / r) - dt if r != 1 else 0
more_time_str = humanize.naturaldelta(more_time)
if not self.it.finished:
more_time_str += "<"
Expand Down
43 changes: 42 additions & 1 deletion dandi/tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
from shutil import rmtree
from typing import Callable, List, Tuple
import time

import numpy as np
import pytest
Expand All @@ -17,7 +18,7 @@
from .test_helpers import assert_dirtrees_eq
from ..consts import DRAFT, dandiset_metadata_file
from ..dandiarchive import DandisetURL
from ..download import Downloader, ProgressCombiner, download
from ..download import Downloader, ProgressCombiner, download, PYOUTHelper
from ..exceptions import NotFoundError
from ..utils import list_paths

Expand Down Expand Up @@ -899,3 +900,43 @@ def test_download_empty_dandiset_and_nonexistent_multiasset(
tmp_path / empty_dandiset.dandiset_id,
tmp_path / empty_dandiset.dandiset_id / "dandiset.yaml",
]


def test_pyouthelper_time_remaining_1339():
"""
Ensure that time remaining goes down!
https://github.com/dandi/dandi-cli/issues/1339
Since time.now() is called inside the agg methods, we
simulate time elapsing by changing t0
Assume downloading files totaling 100 arbitrary units at rates to trigger
a few hours, then countdown to 0.
check that ETA goes down like we want it to
"""

helper = PYOUTHelper()
helper.items_summary.size = 100

# first check hours
# 5 hours remaining = 50% done in 60*60*5
helper.items_summary.t0 = time.time() - (60 * 60 * 5)
done = helper.agg_done(iter([50]))
assert done[-1] == "ETA: 5 hours<"

# 5 minutes remaining = 50% done in 60 * 5
helper.items_summary.t0 = time.time() - (5 * 60)
done = helper.agg_done(iter([50]))
assert done[-1] == "ETA: 5 minutes<"

# countdown the last 10 seconds!
for i in range(11):
helper.items_summary.t0 = time.time() - (100 - (10 - i))
done = helper.agg_done(iter([100 - (10 - i)]))
if i == 9:
assert done[-1] == f"ETA: a second<"
elif i == 10:
# once done, dont print ETA
assert len(done) == 2
else:
assert done[-1] == f"ETA: {10-i} seconds<"

0 comments on commit 5bfd05d

Please sign in to comment.