diff --git a/torrent/assets/js/general.js b/torrent/assets/js/general.js index 03c14f9..7b60130 100644 --- a/torrent/assets/js/general.js +++ b/torrent/assets/js/general.js @@ -22,10 +22,10 @@ function fetchData() { cacheChart.update(stats.cacheFilled, stats.cacheCapacity - stats.cacheFilled); document.getElementById("down-speed-text").innerText = - Humanize.bytes(download, 1024) + "/s"; + Humanize.ibytes(download, 1024) + "/s"; document.getElementById("up-speed-text").innerText = - Humanize.bytes(upload, 1024) + " /s"; + Humanize.ibytes(upload, 1024) + " /s"; }) .catch(function (error) { console.log('Error getting status info: ' + error.message); diff --git a/torrent/assets/js/general_chart.js b/torrent/assets/js/general_chart.js index a034c99..ce9b303 100644 --- a/torrent/assets/js/general_chart.js +++ b/torrent/assets/js/general_chart.js @@ -27,16 +27,18 @@ var GeneralChart = { { label: 'Download Speed', fill: false, - backgroundColor: 'rgb(255, 99, 132)', - borderColor: 'rgb(255, 99, 132)', - borderWidth: 1, + backgroundColor: '#859900', + borderColor: '#859900', + borderWidth: 2, data: this._downloadData, }, { label: 'Upload Speed', fill: false, - borderWidth: 1, + backgroundColor: '#839496', + borderColor: '#839496', + borderWidth: 2, data: this._uploadData, }, @@ -66,7 +68,7 @@ var GeneralChart = { type: 'linear', ticks: { userCallback: function (tick) { - return Humanize.bytes(tick, 1024) + "/s"; + return Humanize.ibytes(tick, 1024) + "/s"; }, beginAtZero: true }, diff --git a/torrent/assets/js/humanize.js b/torrent/assets/js/humanize.js index fbd7f9c..c861e18 100644 --- a/torrent/assets/js/humanize.js +++ b/torrent/assets/js/humanize.js @@ -1,4 +1,5 @@ -var sizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"]; +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); @@ -19,6 +20,22 @@ var Humanize = { 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; } }; diff --git a/torrent/assets/js/routes.js b/torrent/assets/js/routes.js index 5b17f06..af3b3aa 100644 --- a/torrent/assets/js/routes.js +++ b/torrent/assets/js/routes.js @@ -20,12 +20,15 @@ function fetchData() { var download = torrentStat.downloadedBytes / torrentStat.timePassed; var upload = torrentStat.uploadedBytes / torrentStat.timePassed; - var seeders = torrentStat.seeders - var peers = torrentStat.peers + var seeders = torrentStat.seeders; + var peers = torrentStat.peers; + var pieceSize = torrentStat.pieceSice; + document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText = - Humanize.bytes(download, 1024) + "/s down, " + Humanize.bytes(upload, 1024) + "/s up"; - document.getElementById("peers-seeders-" + 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) }); }); diff --git a/torrent/assets/js/single_bar_chart.js b/torrent/assets/js/single_bar_chart.js index 1324aa9..b50ba28 100644 --- a/torrent/assets/js/single_bar_chart.js +++ b/torrent/assets/js/single_bar_chart.js @@ -7,12 +7,12 @@ function SingleBarChart(id, name) { data: { labels:[name], datasets: [{ - backgroundColor: "gray", + backgroundColor: "#839496", label: "used", data: this._used, }, { - backgroundColor: "green", + backgroundColor: "#859900", label: "free", data: this._free, }], diff --git a/torrent/stats/torrent.go b/torrent/stats/torrent.go index 46d4754..17ec8de 100644 --- a/torrent/stats/torrent.go +++ b/torrent/stats/torrent.go @@ -35,6 +35,7 @@ type TorrentStats struct { TimePassed float64 `json:"timePassed"` PieceChunks []*PieceChunk `json:"pieceChunks"` TotalPieces int `json:"totalPieces"` + PieceSize int64 `json:"pieceSice"` } type GlobalTorrentStats struct { @@ -196,6 +197,11 @@ func (s *Torrent) stats(now time.Time, t *torrent.Torrent, chunks bool) *Torrent ts.Hash = t.InfoHash().String() ts.Name = t.Name() ts.TotalPieces = totalPieces + + if t.Info() != nil { + ts.PieceSize = t.Info().PieceLength + } + return ts } diff --git a/torrent/templates/routes.html b/torrent/templates/routes.html index 130b128..f932738 100644 --- a/torrent/templates/routes.html +++ b/torrent/templates/routes.html @@ -29,7 +29,7 @@

...

...

- +

...