4 ms·
In a JavaScript comment we can read: "This just takes the amount of time you have been on this site and multiplies it by the 24 hour moving average. Average vi
by gulbrandr 14y ago
In a JavaScript comment we can read:
"This just takes the amount of time you have been on this site and multiplies it by the 24 hour moving average. Average views per seconds is calculated server-side based on the closest 24 hour mark. Click on view sample data for how average views per second is calculated. Server takes the latest count and time and adds to that count to the difference between the current time and the latest time when youtube updated their views that new number (mycurviews) is passed to the browser along with the Average views/sec (avgpersec) to make a live counter inside the browser, so that all users will have the same number. So lets say 60 seconds ago youtube updated the viewcount to 999,000,000 and the average views per second calculation is 100 and you have been on the site for 10 seconds. The server (10 seconds ago) would have given you a mycurviews of 999,006,000 and the browser would show it as 999,007,000 (because it would add the 10 seconds by 100, compensating for how long you were on this site)"
The "interesting" part of the JavaScript code:
var start = new Date().getTime();
var avgpersec = 105.4627;
var mycurviews = 999866433;
function updateClock( ) {
var elapsed = new Date().getTime() - start;
var totviews = Math.floor(mycurviews+((elapsed/1000)*avgpersec));
var totsecs = Math.floor((1000000000-totviews)/avgpersec);
var mdays = Math.floor(totsecs/86400);
totsecs = totsecs-(mdays*86400);
var mhours = Math.floor(totsecs/3600);
totsecs = totsecs-(mhours*3600);
var mmins = Math.floor(totsecs/60);
totsecs = totsecs-(mmins *60);
document.getElementById("clock").firstChild.nodeValue = addCommas(totviews);
document.getElementById("clock2").firstChild.nodeValue = mhours + " hours " + mmins + " minutes " + totsecs + " seconds";
}
updateClock() is called every 50ms.