Remove previous POCs

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
Antonio Navarro Perez 2020-06-13 12:15:46 +02:00
parent 401a79379f
commit b8392c4c50
50 changed files with 0 additions and 1958 deletions

7
assets/js/Chart.bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

7
assets/js/bootstrap.bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

39
assets/js/file_chunks.js Normal file
View file

@ -0,0 +1,39 @@
function FileChunks() {
this.update = function (chunks, totalPieces, hash) {
var dom = document.getElementById("file-chunks-" + hash);
dom.innerHTML = "";
chunks.forEach(chunk => {
dom.appendChild(getPrintedChunk(chunk.status, chunk.numPieces, totalPieces));
});
};
var pieceStatus = {
"H": { class: "bg-warning", tooltip: "checking pieces" },
"P": { class: "bg-info", tooltip: "" },
"C": { class: "bg-success", tooltip: "downloaded pieces" },
"W": { class: "bg-transparent" },
"?": { class: "bg-danger", tooltip: "erroed pieces" },
};
var getPrintedChunk = function (status, pieces, totalPieces) {
var percentage = totalPieces * pieces / 100;
var pcMeta = pieceStatus[status]
var pieceStatusClass = pcMeta.class;
var pieceStatusTip = pcMeta.tooltip;
var div = document.createElement("div");
div.className = "progress-bar " + pieceStatusClass;
div.setAttribute("role", "progressbar");
if (pieceStatusTip) {
div.setAttribute("data-toggle", "tooltip");
div.setAttribute("data-placement", "top");
div.setAttribute("title", pieceStatusTip);
}
div.style.cssText = "width: " + percentage + "%";
return div;
};
};

33
assets/js/general.js Normal file
View file

@ -0,0 +1,33 @@
GeneralChart.init();
var cacheChart = new SingleBarChart("chart-cache", "Cache disk");
fetchData();
setInterval(function () {
fetchData();
}, 2000)
function fetchData() {
fetch('/api/status')
.then(function (response) {
if (response.ok) {
return response.json();
} else {
console.log('Error getting data from server. Response: ' + response.status);
}
}).then(function (stats) {
var download = stats.torrentStats.downloadedBytes / stats.torrentStats.timePassed;
var upload = stats.torrentStats.uploadedBytes / stats.torrentStats.timePassed;
GeneralChart.update(download, upload);
cacheChart.update(stats.cacheFilled, stats.cacheCapacity - stats.cacheFilled);
document.getElementById("down-speed-text").innerText =
Humanize.ibytes(download, 1024) + "/s";
document.getElementById("up-speed-text").innerText =
Humanize.ibytes(upload, 1024) + " /s";
})
.catch(function (error) {
console.log('Error getting status info: ' + error.message);
});
}

View file

@ -0,0 +1,80 @@
var GeneralChart = {
_downloadData: [],
_uploadData: [],
_chart: null,
update: function (download, upload) {
if (this._downloadData.length > 20) {
this._uploadData.shift();
this._downloadData.shift();
}
var date = new Date();
this._downloadData.push({
x: date,
y: download,
});
this._uploadData.push({
x: date,
y: upload,
});
this._chart.update();
},
init: function () {
var ctx = document.getElementById('chart-general-network').getContext('2d');
this._chart = new Chart(ctx, {
type: 'line',
data: {
datasets: [
{
label: 'Download Speed',
fill: false,
backgroundColor: '#859900',
borderColor: '#859900',
borderWidth: 2,
data: this._downloadData,
},
{
label: 'Upload Speed',
fill: false,
backgroundColor: '#839496',
borderColor: '#839496',
borderWidth: 2,
data: this._uploadData,
},
]
},
options: {
title: {
text: 'Download and Upload speed'
},
scales: {
xAxes: [{
scaleLabel: {
display: false,
},
gridLines: {
display: false,
},
ticks: {
display: false,
},
type: 'time',
}],
yAxes: [{
scaleLabel: {
display: false,
},
type: 'linear',
ticks: {
userCallback: function (tick) {
return Humanize.ibytes(tick, 1024) + "/s";
},
beginAtZero: true
},
}]
},
}
});
}
}

41
assets/js/humanize.js Normal file
View file

@ -0,0 +1,41 @@
var isizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
var sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB"];
function logn(n, b) {
return Math.log(n) / Math.log(b);
}
var Humanize = {
bytes: function (s, base) {
if (s < 10) {
return s.toFixed(0) + " B";
}
var e = Math.floor(logn(s, base));
var suffix = sizes[e];
var val = Math.floor(s / Math.pow(base, e) * 10 + 0.5) / 10;
var f = val.toFixed(0);
if (val < 10) {
f = val.toFixed(1);
}
return f + suffix;
},
ibytes: function (s, base) {
if (s < 10) {
return s.toFixed(0) + " B";
}
var e = Math.floor(logn(s, base));
var suffix = isizes[e];
var val = Math.floor(s / Math.pow(base, e) * 10 + 0.5) / 10;
var f = val.toFixed(0);
if (val < 10) {
f = val.toFixed(1);
}
return f + suffix;
}
};

39
assets/js/routes.js Normal file
View file

@ -0,0 +1,39 @@
var fileChunks = new FileChunks();
fetchData();
setInterval(function () {
fetchData();
}, 2000)
function fetchData() {
fetch('/api/routes')
.then(function (response) {
if (response.ok) {
return response.json();
} else {
console.log('Error getting data from server. Response: ' + response.status);
}
}).then(function (routes) {
routes.forEach(route => {
route.torrentStats.forEach(torrentStat => {
fileChunks.update(torrentStat.pieceChunks, torrentStat.totalPieces, torrentStat.hash);
var download = torrentStat.downloadedBytes / torrentStat.timePassed;
var upload = torrentStat.uploadedBytes / torrentStat.timePassed;
var seeders = torrentStat.seeders;
var peers = torrentStat.peers;
var pieceSize = torrentStat.pieceSice;
document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText =
Humanize.ibytes(download, 1024) + "/s down, " + Humanize.ibytes(upload, 1024) + "/s up";
document.getElementById("peers-seeders-" + torrentStat.hash).innerText =
peers + " peers, " + seeders + " seeders."
document.getElementById("piece-size-" + torrentStat.hash).innerText = "Piece size: " + Humanize.bytes(pieceSize, 1024)
});
});
})
.catch(function (error) {
console.log('Error getting status info: ' + error.message);
});
}

View file

@ -0,0 +1,48 @@
function SingleBarChart(id, name) {
var ctx = document.getElementById(id).getContext('2d');
this._used = [];
this._free = [];
this._chart = new Chart(ctx, {
type: 'horizontalBar',
data: {
labels:[name],
datasets: [{
backgroundColor: "#839496",
label: "used",
data: this._used,
},
{
backgroundColor: "#859900",
label: "free",
data: this._free,
}],
},
options: {
legend: {
display: false,
},
animation: false,
scales: {
xAxes: [{
stacked: true
}],
yAxes: [{
stacked: true,
display: true,
ticks: {
beginAtZero: true,
}
}]
}
},
});
this.update = function (used, free) {
this._used.shift();
this._free.shift();
this._used.push(used);
this._free.push(free);
this._chart.update();
};
}