Loading src/main/resources/web/js/rs/helpers.js +39 −0 Original line number Diff line number Diff line Loading @@ -263,6 +263,45 @@ function hrBandwidth(bw) { return bw + " B/s"; } function bytesPrettyPrint(bytes_bigint){ //convert a number of bytes(javascript bigint) into a pretty "245 GB" or similar, to 1 decimal place const units = ["B", "kB", "MB", "GB", "TB", "PB"] const thresh_bigint = 1000n;// SI units - 1000 between units, not 1024 let unitIndex = 0; let tenPower = 0;//bytes_bigint / (10**tenPower) < 1000 unless I run out of SI units while (bytes_bigint/BigInt(10**tenPower) >= thresh_bigint && unitIndex < units.length - 1) {//while answer still too big and I have a bigger unit to use //go to next power by dividing by 1000 and increasing the unit tenPower += 3; unitIndex++; } //make the integer times 100 then divide by 100, so that I can get a decimal prettyNumber = Number(bytes_bigint / BigInt(10**(tenPower-2)))/100 return prettyNumber.toFixed(1) + " " + units[unitIndex]; } function integralToBigInt(blockHeights, blockWidth){ function toBigInt(value) { if(typeof value === "bigint"){ return value; } if(!Number.isFinite(value)) return 0n; return BigInt(Math.round(value)); } ans = 0n;//set up bigint for(var i=0;i<blockHeights.length;i++){ heightBigint = toBigInt(blockHeights[i]); ans += heightBigint;//add to total } ans *= toBigInt(blockWidth); return ans; } function checkIfDataIsUpToDate(lastModifiedHeader) { // check if onionoo document is up to date: var lastModified = new Date(Date.parse(lastModifiedHeader)); Loading src/main/resources/web/js/rs/views/details/main.js +19 −4 Original line number Diff line number Diff line Loading @@ -181,15 +181,30 @@ define([ this.graph.lookup_bw(this.model.fingerprint, { success: function() { graph.parse_bw_data(graph.data); graphs = ['bw_month', 'bw_months', 'bw_year', 'bw_years']; _.each(graphs, function(g) { let biggestDataPart = []; let dataWidth = 0; graphs = ['bw_month', 'bw_months', 'bw_year', 'bw_years']; for(let i=0;i < graphs.length; i++){ let g = graphs[i]; var data = [graph.get(g).write, graph.get(g).read]; var labels = ["written bytes per second", "read bytes per second"]; var legendPos = [[140, 0], [310, 0]]; var colors = ["#edc240", "#afd8f8"]; plot(g, data, labels, legendPos, colors, "s", ".4s"); }); if (data[0].length==0) continue; dataWidth = (data[0][1][0] - data[0][0][0]) / 1000; biggestDataPart = data[0].map(item => item[1]); } totalElement = document.getElementById("total_data_info"); if(totalElement){ let bytesBigInt = integralToBigInt(biggestDataPart, dataWidth); totalElement.innerHTML = bytesPrettyPrint(bytesBigInt);//convert the total to a pretty format, then set the DOM } } }); Loading src/main/resources/web/templates/rs/details/router.html +3 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,9 @@ should update it as soon as possible.</div> <dd><%= relay.get('last_seen') %></dd> <% } %> <dt><span class="tip" title="the total amount of data donated by this relay in the past 5 years">Total Data</span></dt> <dd id="total_data_info">unknown</dd> <dt><span class="tip" title="Flags that the directory authorities assigned to this relay.">Flags</span></dt> <dd><% _.each(relay.get('flags'), function(flag) { %> <span class="tip flags" title="<%= flag[2] %>"> Loading Loading
src/main/resources/web/js/rs/helpers.js +39 −0 Original line number Diff line number Diff line Loading @@ -263,6 +263,45 @@ function hrBandwidth(bw) { return bw + " B/s"; } function bytesPrettyPrint(bytes_bigint){ //convert a number of bytes(javascript bigint) into a pretty "245 GB" or similar, to 1 decimal place const units = ["B", "kB", "MB", "GB", "TB", "PB"] const thresh_bigint = 1000n;// SI units - 1000 between units, not 1024 let unitIndex = 0; let tenPower = 0;//bytes_bigint / (10**tenPower) < 1000 unless I run out of SI units while (bytes_bigint/BigInt(10**tenPower) >= thresh_bigint && unitIndex < units.length - 1) {//while answer still too big and I have a bigger unit to use //go to next power by dividing by 1000 and increasing the unit tenPower += 3; unitIndex++; } //make the integer times 100 then divide by 100, so that I can get a decimal prettyNumber = Number(bytes_bigint / BigInt(10**(tenPower-2)))/100 return prettyNumber.toFixed(1) + " " + units[unitIndex]; } function integralToBigInt(blockHeights, blockWidth){ function toBigInt(value) { if(typeof value === "bigint"){ return value; } if(!Number.isFinite(value)) return 0n; return BigInt(Math.round(value)); } ans = 0n;//set up bigint for(var i=0;i<blockHeights.length;i++){ heightBigint = toBigInt(blockHeights[i]); ans += heightBigint;//add to total } ans *= toBigInt(blockWidth); return ans; } function checkIfDataIsUpToDate(lastModifiedHeader) { // check if onionoo document is up to date: var lastModified = new Date(Date.parse(lastModifiedHeader)); Loading
src/main/resources/web/js/rs/views/details/main.js +19 −4 Original line number Diff line number Diff line Loading @@ -181,15 +181,30 @@ define([ this.graph.lookup_bw(this.model.fingerprint, { success: function() { graph.parse_bw_data(graph.data); graphs = ['bw_month', 'bw_months', 'bw_year', 'bw_years']; _.each(graphs, function(g) { let biggestDataPart = []; let dataWidth = 0; graphs = ['bw_month', 'bw_months', 'bw_year', 'bw_years']; for(let i=0;i < graphs.length; i++){ let g = graphs[i]; var data = [graph.get(g).write, graph.get(g).read]; var labels = ["written bytes per second", "read bytes per second"]; var legendPos = [[140, 0], [310, 0]]; var colors = ["#edc240", "#afd8f8"]; plot(g, data, labels, legendPos, colors, "s", ".4s"); }); if (data[0].length==0) continue; dataWidth = (data[0][1][0] - data[0][0][0]) / 1000; biggestDataPart = data[0].map(item => item[1]); } totalElement = document.getElementById("total_data_info"); if(totalElement){ let bytesBigInt = integralToBigInt(biggestDataPart, dataWidth); totalElement.innerHTML = bytesPrettyPrint(bytesBigInt);//convert the total to a pretty format, then set the DOM } } }); Loading
src/main/resources/web/templates/rs/details/router.html +3 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,9 @@ should update it as soon as possible.</div> <dd><%= relay.get('last_seen') %></dd> <% } %> <dt><span class="tip" title="the total amount of data donated by this relay in the past 5 years">Total Data</span></dt> <dd id="total_data_info">unknown</dd> <dt><span class="tip" title="Flags that the directory authorities assigned to this relay.">Flags</span></dt> <dd><% _.each(relay.get('flags'), function(flag) { %> <span class="tip flags" title="<%= flag[2] %>"> Loading