Skip to content

Commit d2dda9c

Browse files
committed
Merge branch 'idc-test' of https://github.com/ImagingDataCommons/IDC-WebApp into idc-prod-sp
2 parents 25d444a + 01ef5b4 commit d2dda9c

File tree

5 files changed

+59
-31
lines changed

5 files changed

+59
-31
lines changed

static/css/jquery-ui.min.css

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/css/jquery-ui.structure.min.css

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/css/jquery-ui.theme.min.css

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/js/downloader.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ require([
4141
if(size <= 0) {
4242
return "0 MB";
4343
}
44-
let log_level = Math.floor(Math.log10(size));
45-
let byte_count = 12;
46-
while(log_level%byte_count >= log_level) {
47-
byte_count-=3;
48-
}
49-
let bytes = (Math.round((size/(Math.pow(10,byte_count)))*1000)/1000).toFixed(3);
50-
return `${bytes} ${byte_level[(byte_count/3)]}` ;
44+
let byte_count = 0;
45+
let converted_size = size;
46+
while(converted_size > 1024) {
47+
byte_count += 1;
48+
converted_size /= 1024;
49+
}
50+
let bytes = (Math.round(converted_size*1000)/1000).toFixed(3);
51+
return `${bytes} ${byte_level[byte_count]}` ;
5152
}
5253

5354
class DownloadProgressDisplay {
@@ -188,6 +189,7 @@ require([
188189
queue_byte_size = 0;
189190
bytes_downloaded = 0;
190191
series_count = 0;
192+
start_time = -1;
191193
collections = new Set([]);
192194
cases = new Set([]);
193195
studies = new Set([]);
@@ -212,6 +214,14 @@ require([
212214
return size_display_string(this.bytes_downloaded);
213215
}
214216

217+
get total_duration_estimate() {
218+
if(this.start_time < 0 || this.bytes_downloaded <=0)
219+
return "Calculating..."
220+
let rate = this.bytes_downloaded/((Date.now()-this.start_time)/1000);
221+
let sec_remaining = Math.round((this.queue_byte_size-this.bytes_downloaded)/rate).toFixed(0);
222+
return `~${((sec_remaining-(sec_remaining%60))/60)}m${(sec_remaining%60) > 9 ? ':' : ':0'}${sec_remaining%60}s remaining @ ${size_display_string(rate)}ps`;
223+
}
224+
215225
reset_queue_manager() {
216226
this.queue_byte_size = 0;
217227
this.bytes_downloaded = 0;
@@ -220,12 +230,17 @@ require([
220230
this.cases = new Set([]);
221231
this.studies = new Set([]);
222232
this.cancellation_underway = false;
233+
this.start_time = -1;
223234
}
224235

225236
get active_requests() {
226237
return (this.working_queue.length > 0);
227238
}
228239

240+
set_start_time() {
241+
if(this.start_time < 0) this.start_time = Date.now();
242+
}
243+
229244
cancel() {
230245
this.cancellation_underway = true;
231246
this._emptyQueues();
@@ -263,6 +278,7 @@ require([
263278
}
264279

265280
async get_download_item() {
281+
this.set_start_time();
266282
await this._update_queue();
267283
if(this.working_queue.length > 0 && !this.cancellation_underway) {
268284
return this.working_queue.pop();
@@ -279,6 +295,9 @@ require([
279295
function workerOnMessage(event) {
280296
if(event.data.message === 'update') {
281297
downloader_manager.add_to_done(parseFloat(event.data.size));
298+
let msg = `Download status: ${downloader_manager.in_progress} file(s) downloading${downloader_manager.pending_msg}...`;
299+
let progType = "download";
300+
downloader_manager.progressUpdate(msg, progType);
282301
return;
283302
}
284303
let thisWorker = event.target;
@@ -385,14 +404,16 @@ require([
385404
}
386405
return;
387406
}
388-
let counts = 0;
389407
let read = 0;
408+
let lastReportTime = -1;
409+
let thisChunkTime = -1;
390410
for await(const chunk of response.body) {
391-
if(abort_controller.signal.aborted) break;
411+
if(abort_controller.signal.aborted) break;
392412
outputStream.write(chunk);
393-
counts += 1;
413+
thisChunkTime = Date.now();
394414
read += chunk.length;
395-
if(counts%20 === 0) {
415+
if(lastReportTime < 0 || ((thisChunkTime-lastReportTime) > 300)) {
416+
lastReportTime = Date.now();
396417
self.postMessage({message: "update", size: read});
397418
read = 0;
398419
}
@@ -424,13 +445,15 @@ require([
424445
workerObjectURL = null;
425446
workerLimit = navigator.hardwareConcurrency;
426447

448+
lastProgressUpdate = -1;
449+
427450
constructor() {
428451
this.queues = new DownloadQueueManager();
429452
this.workerCodeBlob = new Blob([this.workerCode], {type: 'application/javascript'});
430453
}
431454

432455
get overall_progress() {
433-
return `${this.queues.total_bytes_downloaded} / ${this.queues.total_downloads_requested} downloaded `;
456+
return `${this.queues.total_bytes_downloaded} / ${this.queues.total_downloads_requested} downloaded (${this.queues.total_duration_estimate})`;
434457
}
435458

436459
get all_requested() {
@@ -469,7 +492,11 @@ require([
469492
}
470493

471494
// Updates the current floating message contents and display class
495+
// Will abort out of an update if there isn't a pending cancellation and the last update time was < 2 seconds
496+
// ago
472497
progressUpdate(message, progType) {
498+
if(this.lastProgressUpdate > 0 && Date.now()-this.lastProgressUpdate < 300 && !this.pending_cancellation)
499+
return;
473500
progType = progType || "download";
474501
let type = "info";
475502
let icon = progType || true;
@@ -496,6 +523,7 @@ require([
496523
if(!this.pending_cancellation && this.in_progress > 0) {
497524
messages['header'] = this.all_requested;
498525
}
526+
this.lastProgressUpdate = Date.now();
499527
this.progressDisplay.update(type, messages, icon);
500528
}
501529

static/js/libs/jquery-ui.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)