compare downloads instead of bandwidth
This commit is contained in:
@@ -6,7 +6,7 @@ function Toolbar(viewer) {
|
|||||||
this.editWindow = null
|
this.editWindow = null
|
||||||
|
|
||||||
this.views = 0
|
this.views = 0
|
||||||
this.bandwidth = 0
|
this.downloads = 0
|
||||||
this.statsInterval = 1000
|
this.statsInterval = 1000
|
||||||
this.statsTimeout = null
|
this.statsTimeout = null
|
||||||
|
|
||||||
@@ -48,16 +48,23 @@ Toolbar.prototype.setStats = function() {
|
|||||||
fetch(this.currentFile.stats_href).then(resp => {
|
fetch(this.currentFile.stats_href).then(resp => {
|
||||||
return resp.json()
|
return resp.json()
|
||||||
}).then(resp => {
|
}).then(resp => {
|
||||||
if (resp.views != this.views || resp.bandwidth != this.bandwidth) {
|
let downloads = Math.round(resp.bandwidth/size)
|
||||||
|
|
||||||
|
// If the new values are different we reset the timer
|
||||||
|
if (resp.views != this.views || downloads != this.downloads) {
|
||||||
this.statsInterval = 1000
|
this.statsInterval = 1000
|
||||||
} else {
|
} else {
|
||||||
this.statsInterval = this.statsInterval + 1000
|
this.statsInterval = this.statsInterval + 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save the new values
|
||||||
this.views = resp.views
|
this.views = resp.views
|
||||||
|
this.downloads = downloads
|
||||||
|
|
||||||
this.spanViews.innerText = formatThousands(this.views)
|
this.spanViews.innerText = formatThousands(this.views)
|
||||||
this.bandwidth = resp.bandwidth
|
this.spanDownloads.innerText = formatThousands(downloads)
|
||||||
this.spanDownloads.innerText = formatThousands(Math.round(this.bandwidth/size))
|
|
||||||
|
console.debug("updating stats in ", this.statsInterval)
|
||||||
|
|
||||||
this.statsTimeout = setTimeout(() => { this.setStats() }, this.statsInterval)
|
this.statsTimeout = setTimeout(() => { this.setStats() }, this.statsInterval)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
Reference in New Issue
Block a user