Update progress bar to be more accurate when downloading large files (#888)

* Change from round to floor, so % bar increases when downloaded data is at X% not potentially under, thus leading to under reporting
* Add debug output when each % increase when downloading a file to assist with validating progress
* Start displaying ETA starting at 5% rather than 10%
This commit is contained in:
abraunegg 2020-04-26 06:52:29 +10:00 committed by GitHub
parent a0f4f9ddab
commit c05243444f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 11 deletions

View file

@ -100,7 +100,7 @@ void vdebug(T...)(T args)
} }
} }
void vdebugUpload(T...)(T args) void vdebugNewLine(T...)(T args)
{ {
if (verbose >= 2) { if (verbose >= 2) {
writeln("\n[DEBUG] ", args); writeln("\n[DEBUG] ", args);

View file

@ -567,18 +567,34 @@ final class OneDriveApi
Progress p = new Progress(iteration); Progress p = new Progress(iteration);
p.title = "Downloading"; p.title = "Downloading";
writeln(); writeln();
bool barInit = false;
real previousDLPercent = -1.0; real previousDLPercent = -1.0;
real percentCheck = 5.0; real percentCheck = 5.0;
// Setup progress bar to display // Setup progress bar to display
http.onProgress = delegate int(size_t dltotal, size_t dlnow, size_t ultotal, size_t ulnow) http.onProgress = delegate int(size_t dltotal, size_t dlnow, size_t ultotal, size_t ulnow)
{ {
// For each onProgress, what is the % of dlnow to dltotal // For each onProgress, what is the % of dlnow to dltotal
real currentDLPercent = round(double(dlnow)/dltotal*100); // floor - rounds down to nearest whole number
// If matching 5% of download, increment progress bar real currentDLPercent = floor(double(dlnow)/dltotal*100);
if ((isIdentical(fmod(currentDLPercent, percentCheck), 0.0)) && (previousDLPercent != currentDLPercent)) { if (currentDLPercent > 0){
p.next(); // We have started downloading
previousDLPercent = currentDLPercent; // If matching 5% of download, increment progress bar
if ((isIdentical(fmod(currentDLPercent, percentCheck), 0.0)) && (previousDLPercent != currentDLPercent)) {
// What have we downloaded thus far
log.vdebugNewLine("Data Received = ", dlnow);
log.vdebug("Expected Total = ", dltotal);
log.vdebug("Percent Complete = ", currentDLPercent);
// Increment counter & show bar update
p.next();
previousDLPercent = currentDLPercent;
}
} else {
if ((currentDLPercent == 0) && (!barInit)) {
// Initialise the download bar at 0%
// Downloading 0% | | ETA --:--:--:^C
p.next();
barInit = true;
}
} }
return 0; return 0;
}; };

View file

@ -82,7 +82,7 @@ class Progress
header.formattedWrite("%s %3d%% |", caption, cast(int)(ratio * 100)); header.formattedWrite("%s %3d%% |", caption, cast(int)(ratio * 100));
if(counter <= 1 || ratio == 0.0) { if(counter <= 0 || ratio == 0.0) {
footer.formattedWrite("| ETA --:--:--:"); footer.formattedWrite("| ETA --:--:--:");
} else { } else {
int h, m, s; int h, m, s;
@ -114,7 +114,7 @@ class Progress
this(size_t iterations) { this(size_t iterations) {
if(iterations <= 0) iterations = 1; if(iterations <= 0) iterations = 1;
counter = 0; counter = -1;
this.iterations = iterations; this.iterations = iterations;
start_time = Clock.currTime.toUnixTime; start_time = Clock.currTime.toUnixTime;
} }
@ -140,7 +140,7 @@ class Progress
} }
void reset() { void reset() {
counter = 0; counter = -1;
start_time = Clock.currTime.toUnixTime; start_time = Clock.currTime.toUnixTime;
} }

View file

@ -176,7 +176,7 @@ struct UploadSession
while (true) { while (true) {
fragmentCount++; fragmentCount++;
log.vdebugUpload("Fragment: ", fragmentCount, " of ", iteration); log.vdebugNewLine("Fragment: ", fragmentCount, " of ", iteration);
p.next(); p.next();
long fragSize = fragmentSize < fileSize - offset ? fragmentSize : fileSize - offset; long fragSize = fragmentSize < fileSize - offset ? fragmentSize : fileSize - offset;
// If the resume upload fails, we need to check for a return code here // If the resume upload fails, we need to check for a return code here