From 736a3065d4fad74a2ca61e04459e8ae63a7cf566 Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Sun, 30 Apr 2017 16:35:36 -0700 Subject: [PATCH] import import stats --- cli.js | 4 ++-- ui.js | 68 ++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/cli.js b/cli.js index cba0a8b..45f7628 100755 --- a/cli.js +++ b/cli.js @@ -140,12 +140,12 @@ function trackProgress (state, bus) { }) progress.on('put-end', function (src, dst) { - state.fileImport = null + // state.fileImport = null bus.emit('render') }) progress.on('end', function (src, dst) { - state.fileImport = null + // state.fileImport = null bus.emit('render') }) } diff --git a/ui.js b/ui.js index 93000fb..a26be7b 100644 --- a/ui.js +++ b/ui.js @@ -29,10 +29,12 @@ function progressView (state) { } function archiveUI (state) { - if (!state.archive) return `Starting...` + if (!state.archive) return '' var archive = state.archive - var size = archive.content ? archive.content.byteLength : 0 - var files = archive.metadata.length - 1 + + var stats = state.stats.get() + var size = stats.byteLength || 0 + var files = stats.files return output` ${state.downloading ? 'Downloading' : 'Syncing'} Archive: ${files} files (${pretty(size)}) ` @@ -42,13 +44,12 @@ function networkUI (state) { // state.exiting = last render before download exit if (!state.network || state.downloadExit) return '' if (!state.network.connected || !state.archive.content) { - if (state.writable) return ''// '\nWaiting for Connections...' + if (state.writable) return '\nNo Connections'// '\nWaiting for Connections...' return '\nConnecting...' } return output` - ${state.archive.content.peers.length} peers - ${speed()} + ${state.archive.content.peers.length} peers ${speed()} ` function speed () { @@ -56,6 +57,7 @@ function networkUI (state) { if (state.uploadSpeed) output += `Uploading ${pretty(state.uploadSpeed)}/s` // !state.nsync hack so speed doesn't display when done if (!state.nsync && state.downloadSpeed) output += `Downloading ${pretty(state.downloadSpeed)}/s` + if (output.length) output = '| ' + output return output } } @@ -93,51 +95,55 @@ function downloadUI (state) { function importUI (state) { if (state.count) {// Initial import done - if (state.importer.putDone >= state.count.files) { + if (state.importer.putDone.files >= state.count.files) { if (state.importer.pending.length) return 'Importing updated files.' if (!state.opts.watch) return 'All files imported.' return 'Watching for file changes.' } } else { if (!state.importer.count.files) return `Checking for file updates ...` + var indexSpeed = state.importer.indexSpeed ? `(${pretty(state.importer.indexSpeed)}/s)` : '' return output` - Importing ${state.importer.count.files} files (${pretty(state.importer.count.bytes)}) + Imported ${state.importer.putDone.files} of ${state.importer.count.files} files ${indexSpeed} + (Calculating total import count...) ` } - if (!state.totalBar) { - var total = state.count.files - state.totalBar = progress({ - total: total, - style: function (a, b) { - return `[${a}${b}] ${(100 * state.importer.putDone / total).toFixed(0)}%` - } - }) - } + var total = state.count.bytes + var totalBar = progress({ + total: total, + style: function (a, b) { + return `[${a}${b}] ${(100 * state.importer.putDone.bytes / total).toFixed(0)}%` + } + }) return output` - Importing ${state.count.files} files to Archive - ${state.totalBar(state.importer.putDone)} + Importing ${state.count.files} files to Archive (${pretty(state.importer.indexSpeed)}/s) + ${totalBar(state.importer.putDone.bytes)} ` } function fileImport (state) { if (!state.fileImport) return '' if (state.fileImport.type === 'del') return `\nDEL: ${state.fileImport.src.name}` - var total = state.fileImport.src.stat.size - var bar = progress({ - total: total, - width: 35, - style: function (a, b) { - return `[${a}${b}] ${pretty(state.fileImport.progress)} / ${pretty(total)}` - } - }) - var name = state.fileImport.dst.name + var total = state.fileImport.src.stat.size + // var bar = progress({ + // total: total, + // width: 35, + // style: function (a, b) { + // return `[${a}${b}] ${pretty(state.fileImport.progress)} / ${pretty(total)}` + // } + // }) + + var name = state.fileImport.dst.name.substr(1) // del / at start + var size + // >500 mb show progress to + if (total < 5e8) size = `(${pretty(total)})` + else size = `(${pretty(state.fileImport.progress)} / ${pretty(total)})` return output` - ${pretty(state.importer.indexSpeed)}/s - ADD: ${cliTruncate(name, process.stdout.columns - 5, {position: 'start'})} - ${bar(state.fileImport.progress)} + ADD: ${cliTruncate(name, process.stdout.columns - 7 - size.length, {position: 'start'})} ${size} ` + // ${bar(state.fileImport.progress)} }